wypcli
Version:
```npm install wypcli```
64 lines (52 loc) • 1.49 kB
JavaScript
;
var ejs = require('ejs');
var fs = require('fs');
var _require = require('util'),
promisify = _require.promisify;
var renderFIlePromise = promisify(ejs.renderFile);
var path = require('path');
var compile = function compile(templateName, data) {
var thepath, abpath;
return regeneratorRuntime.async(function compile$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
thepath = "../templates/".concat(templateName);
abpath = path.resolve(__dirname, thepath);
_context.prev = 2;
_context.next = 5;
return regeneratorRuntime.awrap(renderFIlePromise(abpath, data));
case 5:
return _context.abrupt("return", _context.sent);
case 8:
_context.prev = 8;
_context.t0 = _context["catch"](2);
console.log(_context.t0);
case 11:
case "end":
return _context.stop();
}
}
}, null, null, [[2, 8]]);
};
/**
* 递归创建文件夹
*
*/
// const createDirSync = (pathName) => {
// if (fs.existsSync(pathName)) {
// return true
// } else {
// if (createDirSync(path.dirname(pathName))) {
// fs.mkdirSync(pathName)
// return true
// }
// }
// }
var writeToFile = function writeToFile(path, context) {
return fs.promises.writeFile(path, context);
};
module.exports = {
compile: compile,
writeToFile: writeToFile
};