UNPKG

cjlfastvuecli

Version:
42 lines (39 loc) 1.17 kB
const fs = require('fs') const ejs = require('ejs'); const path = require('path'); //templateName是要编译的模板,data是传入的类名,信息之类的 const compile = (templateName, data) => { const templatePosition = `../templates/${templateName}`; //拿到D:\ViteVue\fastvuecli\lib\templates\vue-component.ejs let templatePath = path.resolve(__dirname, templatePosition) // console.log(templatePath); return new Promise((resolve, reject) => { ejs.renderFile(templatePath, { data }, {}, (err, res) => { if (err) { console.log(err); reject(err); return } resolve(res) }) }) } //递归创建文件夹 const createDirSync = pathName => { if (fs.existsSync(pathName)) { return true } else { if (createDirSync(path.dirname(pathName))) { fs.mkdirSync(pathName) return true } } } const writeToFile = (path, content) => { return fs.promises.writeFile(path, content) } module.exports = { compile, writeToFile, createDirSync }