Commit eabe3e95 authored by lipengcheng 's avatar lipengcheng

consolidate

parent 22369114
......@@ -83,7 +83,7 @@ semver:版本号控制 -- vuelci
slash: 将window反斜杠路径转换为斜杠路径 foo\\bar ➔ foo/bar -- vuecli
minimist:解析参数选项 -- vuecli
validate-npm-package-name:判断作为pkgname的某个字符串是否已经存在
ncpjs:异步文件目录递归复制
ncp:异步文件目录递归复制
模板引擎:consolidatejs、handlebars、ejs、jade、swig
......
......@@ -14,10 +14,15 @@
"axios": "^0.21.1",
"chalk": "^4.1.0",
"commander": "^7.1.0",
"consolidate": "^0.16.0",
"download-git-repo": "^3.0.2",
"ejs": "^3.1.6",
"fs-extra": "^9.1.0",
"handlebars": "^4.7.7",
"inquirer": "^8.0.0",
"leven": "^3.1.0",
"metalsmith": "^2.3.0",
"ncp": "^2.0.0",
"ora": "^5.4.0",
"semver": "^7.3.5",
"shelljs": "^0.8.4",
......
module.exports = [
{
name: 'ok',
type: 'confirm',
message: `xxxxxx`
}
]
\ No newline at end of file
console.log(`11:`,11);
`mikeee`
\ No newline at end of file
const Metalsmith = require('metalsmith')
const Handlebars = require('handlebars')
const { promisify } = require('util');
const render = require('consolidate').ejs.render; // 统一所有的模板引擎
const path = require('path');
const ncp = require('ncp');
const ncpPro = promisify(ncp);
const renderPro = promisify(render);
console.log(`__dirname:`,__dirname);
console.log(`__filename:`,__filename);
console.log(`process.cwd():`,process.cwd());
async function ttt() {
let res = await new Promise( (resolve, reject) => {
let m = Metalsmith(path.resolve(__dirname, 'tpl'))
m.metadata({age: 34})
m.source(path.resolve(__dirname, 'tpl'))
.destination(path.resolve(__dirname, 'build'))
.use(async (files, metal, done) => {
console.log(`files:`, files);
const m = metal.metadata();
Object.assign(m, { author: 'mikeee' });
done()
})
.use((files, metal, done) => {
const meta = metal.metadata();
console.log(`meta:`, meta);
Object.keys(files).forEach(async (file) => {
let c = files[file].contents.toString();
// 只有js和json文件才去做处理
if (file.includes('js') || file.includes('json')) {
// 判断是否是模板 可用正则匹配
if (c.includes('<%')) {
c = await renderPro(c, meta);
files[file].contents = Buffer.from(c);
}
}
})
done()
})
.build((err) => {
err ? reject(1) : resolve(2)
})
})
console.log(`res:`, res);
}
ttt()
console.log(`11:`,11);
`<%= author %>`
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment