建立檔案指令碼(.sh檔案)
阿新 • • 發佈:2020-12-29
echo "create project folder - input name"
read name
cd "./src/views"
if [ ! -d "$name" ];then
sed -i "" '/Vue.use(VueRouter);/i\
import '$name'Routes from \"@\/views\/'$name'\/routes\";
' ../router/index.ts
sed -i "" '/Vue.use(Vuex);/i\
import '$name ' from \"@\/views\/'$name'\/modules\";
' ../store/index.ts
mkdir $name
cd "./$name"
mkdir "containers"
mkdir "models"
mkdir "modules"
mkdir "routes"
touch "index.vue"
echo "<template>
<div>
<Title />
<router-view></router-view>
</div>
</template>
<script lang=" ts">
import Vue from 'vue'
import Title from '@/components/Title'
export default Vue.extend({
components: {
Title
}
})
</script>" >> ./index.vue
touch "./containers/$name.vue"
echo "<template>
<div>
</div>
</template>
<style lang='less' scoped>
</style>
<script lang='ts'>
import { Component, Vue, Watch, Prop } from 'vue-property-decorator';
@Component
export default class $name extends Vue {
}
</script>" >> ./containers/$name.vue
touch "./modules/index.ts"
touch "./modules/$name.ts"
echo "import request from '@/utils/request';
import { message } from 'ant-design-vue';
export default {
namespaced: true,
state: {},
mutations: {},
actions: {}
};" >> ./modules/$name.ts
echo "import $name from './$name'
export default {
namespaced: true,
modules: { $name:$name }
};" >> ./modules/index.ts
touch "./routes/index.ts"
echo "import { RouteConfig } from 'vue-router';
export default [
{
path: '/',
component: () => import('../index.vue'),
children:[{
path:'$name',
component: () => import('../containers/$name.vue')
}]
}
] as Array<RouteConfig>;" >> ./routes/index.ts
echo "generate finished"
cd "../../"
npm run lint
else
echo "資料夾已經存在"
fi
// package.json檔案 scripts
"create": "sh ./src/utils/create.sh"
npm run create 檔名