# nodjs-nutzcli **Repository Path**: icode2017/nodjs-nutzcli ## Basic Information - **Project Name**: nodjs-nutzcli - **Description**: 使用 Nodejs 制作的脚手.架. - **Primary Language**: JavaScript - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-03-21 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # nodjs-nutzcli 使用 Nodejs 制作的脚手.架. ## 下载安装 `yo` 和 `generator-generator` 在已经有装好node和npm的前提下,需要全局安装yo和generator-generator ``` npm install -g yo npm install -g generator-generator ``` 之后运行generator-generator来创建我们自己需要的generator的基础框架 ``` yo generator ``` 我们得到了generator的目录: ``` . ├── generators/ │ └── app/ │ ├── index.js │ └── templates/ │ └── dummyfile.txt ├── .editorconfig ├── .gitattributes ├── .gitignore ├── .eslintrc ├── .travis.yml ├── .yo-rc.json ├── package.json ├── gulpfile.js ├── README.md ├── LICENSE └── test/ └── app.js ``` ## 准备模版 ## 将用户输出内容作为变量写入到文件 ``` prompting() { // 定义用户交互的内容 const prompts =[{ type: 'input', name: 'groupId', message: 'maven groupId,eg: cn.dav', default: 'cn.dav' }] // 返回对象 return this.prompt(prompts).then(props => { // 将用户输入的内容赋值给 this.args this.args = props; }) } writing() { // console.log(this.args); // 指定要处理的文件 const cpyt = ["pom.xml", "README.md"]; // 迭代要处理的文件 for (var i in cpyt) { // 复制文件并替换文件中的变量 this.fs.copyTpl( // 复制文件 this.templatePath(cpyt[i]), // 替换文件中的变量 this.destinationPath(cpyt[i]), { groupId: this.args.groupId, }); } } } ``` `pom.xml` 使用变量 `groupId` ``` <%= groupId %> ``` - []() - []() - []() - [创建 Yeoman Generator 简单教程](https://www.jianshu.com/p/9f3e6bcdb274) - []() - []() - []()