1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| const Generator = require("yeoman-generator");
module.exports = class extends Generator { prompting() { return this.prompt([ { type: "input", name: "name", message: "Your project name", default: this.appname, }, { type: "list", name: "tool", choices: ["yarn", "npm"], message: "请选择版本管理工具", default: "yarn", }, ]).then((answers) => { this.answers = answers; }); } writing() {
const templates = [ ".browserslistrc", ".editorconfig", ".env.development", ".env.production", ".eslintrc.js", ".gitignore", "babel.config.js", "package.json", "postcss.config.js", "README.md", "public/favicon.ico", "public/index.html", "src/App.vue", "src/main.js", "src/router.js", "src/assets/logo.png", "src/components/HelloWorld.vue", "src/store/actions.js", "src/store/getters.js", "src/store/index.js", "src/store/mutations.js", "src/store/state.js", "src/utils/request.js", "src/views/About.vue", "src/views/Home.vue", ]; templates.forEach((item) => { const temp = this.templatePath(item); const outPut = this.destinationPath(this.answers.name + "/" + item); this.fs.copyTpl(temp, outPut, this.answers); }); }
install() { const { name, tool } = this.answers; const npmDir = process.cwd() + "/" + name; process.chdir(npmDir); tool === "yarn" ? this.yarnInstall() : this.npmInstall(); } };
|