UNPKG

generator-zeus

Version:

组件脚手架

113 lines (111 loc) 3.84 kB
/** * Created by liaoyf on 2016/5/31 0031. */ var generators = require("yeoman-generator"); var mkdirp = require("mkdirp"); var _ = require("lodash"); module.exports = generators.Base.extend({ constructor: function () { generators.Base.apply(this, arguments); }, prompting: function () { var done = this.async(); return this.prompt([ { message: "what type of project do you want?", type: "list", name: "projectType", choices: [ { name: "React Component", value: "react" }, { name: "Jquery Plugin", value: "jquery" } ] } ], (function (answers) { this.projectType = answers.projectType; done(); }).bind(this)); }, writing: function(){ //创建文件夹 mkdirp("dist"); mkdirp("src"); mkdirp("example"); mkdirp("docs"); mkdirp("test"); this.fs.copyTpl( this.templatePath("_.gitignore"), this.destinationPath(".gitignore") ); this.fs.copyTpl( this.templatePath("_package.json"), this.destinationPath("package.json"), { name: this.appname.replace(/\s+/g, '-'), filename: this.appname.replace(/\s+/g, '-') } ); this.fs.copyTpl( this.templatePath("_component.json"), this.destinationPath("component.json"), { name: this.appname.replace(/\s+/g, '-'), filename: this.appname.replace(/\s+/g, '-') } ); this.fs.copyTpl( this.templatePath("_README.md"), this.destinationPath("README.md") ); switch (this.projectType){ case "react": this.fs.copyTpl( this.templatePath("_webpack.config.js"), this.destinationPath("webpack.config.js"), { filename: this.appname.replace(/\s+/g, '-'), library: _.camelCase(this.appname)[0].toUpperCase() + _.camelCase(this.appname).substring(1) } ); this.fs.copyTpl( this.templatePath("_webpack.prod.config.js"), this.destinationPath("webpack.prod.config.js"), { filename: this.appname.replace(/\s+/g, '-'), library: _.camelCase(this.appname)[0].toUpperCase() + _.camelCase(this.appname).substring(1) } ); this.fs.copyTpl( this.templatePath("_index.html"), this.destinationPath("example", "index.html"), { title: "React组件开发规范", filename: this.appname.replace(/\s+/g, '-') } ); this.fs.copyTpl( this.templatePath("_index.js"), this.destinationPath("example", "index.js") ); break; case "jquery": break; } }, install : function(){ /*this.installDependencies({ npm: true, callback: function () { console.log('Everything is ready!'); } });*/ }, end: function () { console.info("end~~~~~~"); } });