plop 方便的micro-generator framework
作者:互联网
plop是一个micro-generator framework,可以用来方便的生成代码
参考使用
- 安装
pacakge.json
{
"name": "appdemo",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"plop": "^2.7.4"
},
"scripts": {
"app":"plop"
}
}
plopfile.js
module.exports = function (plop) {
// controller generator
plop.setGenerator('controller', {
description: 'application controller logic',
prompts: [{
type: 'input',
name: 'name',
message: 'controller name please'
}],
actions: [{
type: 'add',
path: 'src/{{name}}.js',
templateFile: 'plop-templates/controller.hbs'
}]
});
};
- 模板
plop-templates/controller.hbs
module.exports = class {{name}} {
constrcut(){
this.name={{name}};
}
get name(){
return this.name;
}
}
- 运行效果
yarn app
参考资料
https://www.npmjs.com/package/plop
https://github.com/plopjs/plop
https://plopjs.com/
https://github.com/handlebars-lang/handlebars.js
标签:plop,generator,js,micro,controller,https,com,name 来源: https://www.cnblogs.com/rongfengliang/p/14415534.html