[TOC]
- yeoman如何开始创建自己的generatorindex.js结构解析
yeoman
Yeoman helps you to kickstart new projects, prescribing best practices and tools to help you stay productive.
如何开始
学习一个新东西,最直接的方式就是去官方网站找向导,比如Getting Start.
创建自己的generator
官方指导,主要是对模板文件创建的过程进行了解。详细的使用查看: API
index.js结构解析
'use strict';// 引入使用的模块,yosay是命令行里显示文字的插件,chalk是增强命令行下颜色显示。var yeoman = require('yeoman-generator');var yosay = require('yosay');var chalk = require('chalk');// 导出模块,使得yo xxx能够运行module.exports = yeoman.generators.Base.extend({ // 默认会添加的构造函数 constructor: function () { yeoman.generators.Base.apply(this, arguments); }, // 初始化执行的内容,一般读取配置文件 initializing: function () { this.pkg = require('../package.json'); }, // 提示信息相关内容,比如询问用户是否使用某些模块 prompting: function () { }, // 拷贝文件,创建真正的项目, 这里面提三个需要注意的函数 // template: 拷贝文件,同时会替换里面的配置信息 // copy: 只负责拷贝,但是好像也能替换里面的配置信息 // write: 修改文件内容 writing: { }})
原文: https://leohxj.gitbooks.io/front-end-database/content/frontend-workflow/yeoman.html
