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
 plop 方便的micro-generator framework

 

 

plop 方便的micro-generator framework

 

 

参考资料

https://www.npmjs.com/package/plop
https://github.com/plopjs/plop
https://plopjs.com/
https://github.com/handlebars-lang/handlebars.js

上一篇:最大熵模型


下一篇:0224 如何面对高并发?缓存?中台为什么会火?