【发布时间】:2018-02-12 04:54:31
【问题描述】:
我正在尝试编写一个非常基本的生成器,它将创建 4 个与组件相关的文件。此时生成器需要做的就是从命令行获取组件名称,然后创建 4 个具有该名称的文件。生成器运行良好,但完成后不执行任何操作。
我的index.js 里面/app
'use strict';
//Require dependencies
var chalk = require('chalk');
var yosay = require('yosay');
var Generator = require('yeoman-generator');
module.exports = class extends Generator {
prompting() {
var done = this.async();
this.prompt({
type: 'input',
name: 'componentName',
message: 'Your component name',
default: this.appname
}, (answers) => {
this.props = answers
});
}
writing() {
const componentName = this.props.componentName;
this.fs.copyTpl(
`${this.templatePath()}/**/!(_)*`,
this.destinationPath(),
this.props
);
this.fs.copyTpl(
this.templatePath('src/_component.js'),
this.destinationPath(`${componentName}.js`),
this.props
);
this.fs.copyTpl(
this.templatePath('src/_component.spec.js'),
this.destinationPath(`${componentName}.spec.js`),
this.props
);
this.fs.copyTpl(
this.templatePath('src/_component.scss'),
this.destinationPath(`${componentName}.scss`),
this.props
);
this.fs.copyTpl(
this.templatePath('src/_component.pug'),
this.destinationPath(`${componentName}.pug`),
this.props
);
}
install() {
this.installDependencies();
}
};
【问题讨论】:
标签: command-line-interface yeoman yeoman-generator