Nodejs学习笔记:开发脚手架工具
创建项目
安装 commander
- npm install commander
- 官方文档:https://github.com/tj/commander.js/blob/master/Readme_zh-CN.md
- 比如查看版本号:
- 示例:
- 输出:
- help
- 可以将上面抽离到一个文件中 lib\core\help.js
const program = require('commander');
const helpOptions = () => {
// 增加自己的options
program.option('-w --why', 'a why cli');
program.option('-d --dest <dest>', 'a destination folder, 例如: -d /src/components')
program.option('-f --framework <framework>', 'your frameword')
program.on('--help', function () {
console.log("");
console.log("Other:")
console.log(" other options~");
})
}
module.exports = helpOptions;
- 调用:
#!/usr/bin/env node
const program = require("commander");
const helpOptions = require("./lib/core/help");
// 查看版本号
program.version(require("./package.json").version);
// 帮助和可选信息
helpOptions();
program.parse(process.argv);
创建项目指令
- 安装依赖库 npm install download-git-repo
使用模板 ejs
- 参考文档:EJS -- 嵌入式 JavaScript 模板引擎 | EJS 中文文档
- 安装:npm install ejs