UNPKG

wypcli

Version:

```npm install wypcli```

40 lines (37 loc) 928 B
const ejs = require('ejs') const fs = require('fs') const { promisify } = require('util') const renderFIlePromise = promisify(ejs.renderFile) const path = require('path') const compile = async (templateName, data) => { const thepath = `../templates/${templateName}` const abpath = path.resolve(__dirname, thepath) try { return await renderFIlePromise(abpath, data) } catch (err) { console.log(err); } } /** * 递归创建文件夹 * */ // const createDirSync = (pathName) => { // if (fs.existsSync(pathName)) { // return true // } else { // if (createDirSync(path.dirname(pathName))) { // fs.mkdirSync(pathName) // return true // } // } // } const writeToFile = (path, context) => { return fs.promises.writeFile(path, context) } module.exports = { compile, writeToFile }