UNPKG

sn-vue-cli

Version:

* npm install sn-vue-cli -g

29 lines (28 loc) 956 B
const fs = require('fs') const handlerbars = require('handlebars') const chalk = require('chalk') module.exports = async () => { const list = fs .readdirSync('./src/views') .filter( v => v !== 'Home.vue') .map( v => ({ name: v.replace('.vue', '').toLowerCase(), file: v })) compile({list},'./src/router.js','./template/router.js.hbs') compile({list},'./src/App.vue','./template/app.vue.hbs') /** * 编译模板函数 * @param {*} meta 数据 * @param {*} filePath 目标 * @param {*} templatePath 模板 */ function compile(meta,filePath,templatePath){ if(fs.existsSync(templatePath)){ const content = fs.readFileSync(templatePath).toString() const result = handlerbars.compile(content)(meta) fs.writeFileSync(filePath,result); console.log(`🚀创建${filePath}文件成功...`); } } }