templatePath : 源路径,相对于根源路径
destinationPath : 目的路径,相对于根目的路径
destinationRoot : 根目的路径,可以通过destinationRoot('XX')来设置根目的路径
sourceRoot : 根源路径,可以通过sourceRoot(‘XX’)来设置根源路径
resolved : 当前index.js
appname :当前generator 名字
props : 当前prompt 存储变量
copy :复制方法
function copy(source, destination, process) {
var file = this._prepCopy(source, destination, process);
try {
file.body = this.engine(file.body, this);
} catch (err) {
// this happens in some cases when trying to copy a JS file like lodash/underscore
// (conflicting the templating engine)
}
this.fs.copy(file.source, file.destination, {
process: function () {
return file.body;
}
});
return this;
}
this.copy 执行prepCopy之后调用this.fs.copy方法处理.
_prepCopy : 预复制方法,主要处理一些路径等方面的初始化
function _prepCopy(source, destination, process) {
destination = destination || source;
if (typeof destination === 'function') {
process = destination;
destination = source;
}
source = isPathAbsolute(source) ? source : path.join(this.sourceRoot(), source);
destination = isPathAbsolute(destination) ? destination : path.join(this.destinationRoot(), destination);
var encoding = null;
var body = fs.readFileSync(source);
var isText = istextorbinary.isTextSync(undefined, body);
if (isText) {
body = body.toString();
if (typeof process === 'function') {
body = process(body, source, destination, {
encoding: encoding
});
}
}
return {
body: body,
encoding: encoding,
destination: destination,
source: source
};
}
template : 复制方法,先使用engine进行模板parser
function template(source, destination, data, options) {
if (!destination || !isPathAbsolute(destination)) {
destination = path.join(
this.destinationRoot(),
this.engine(destination || source, data || this, options)
);
}
if (!isPathAbsolute(source)) {
source = path.join(
this.sourceRoot(),
this.engine(source, data || this, options)
);
}
var body = this.engine(this.fs.read(source), data || this, options);
// Using copy to keep the file mode of the previous file
this.fs.copy(source, destination, {
process: function () {
return body;
}
});
return this;
}
directory : 复制目录方法
function directory(source, destination, process, bulk) {
// Only add sourceRoot if the path is not absolute
var root = isPathAbsolute(source) ? source : path.join(this.sourceRoot(), source);
var files = glob.sync('**', { dot: true, nodir: true, cwd: root });
destination = destination || source;
if (typeof destination === 'function') {
process = destination;
destination = source;
}
var cp = this.copy;
if (bulk) {
cp = this.bulkCopy;
}
// get the path relative to the template root, and copy to the relative destination
for (var i in files) {
var dest = path.join(destination, files[i]);
cp.call(this, path.join(root, files[i]), dest, process);
}
return this;
}
runInstall : install 所安装依赖
installDependencies : install 所安装依赖
bowerInstall : install using bower
npmInstall : install using npm
spawnCommand : 执行其他命令
prompt :
invoke :
composeWith : 调用sub-generator 或者其他generator