我在yeoman中有一个模板目录,我想将其添加到问题的所有内容都复制到目标路径,我已将其添加到问题中,是否有更好的方法来完成此任务?
index.js
'use strict';
const Generator = require('yeoman-generator');
const chalk = require('chalk');
const yosay = require('yosay');
module.exports = class extends Generator {
prompting() {
// Have Yeoman greet the user.
this.log(
yosay(
`Welcome to the epic ${chalk.red(
"generator-cvsdigital-sdk-nodeapp-generator"
)} generator!`
)
);
const prompts = [
{
type: "input",
name: "name",
message: "Your project name",
// Defaults to the project's folder name if the input is skipped
default: this.appname
}
];
return this.prompt(prompts).then(props => {
// To access props later use this.props.someAnswer;
this.props = props;
});
}
// writing() {
// this.fs.copyTpl(
// this.templatePath("package.json"),
// this.destinationPath("package.json")
// );
// this.fs.copyTpl(
// this.templatePath("app"),
// this.destinationPath("src")
// );
// }
writing: function () {
this.fs.copy(
this.templatePath('app/templates'),
this.destinationPath('app/templates')
);
}
install() {
this.installDependencies();
}
};
错误
AssertionError [ERR_ASSERTION]: Trying to copy from a source that does not exist:
源目录路径
generators/app/templates all the files are in templates that i want to copy to destination
如果您的模板位于generators/app/templates
中,我认为您需要将模板路径更改为templatePath('templates/NAME-OF-TEMPLATE.JS')
我发现的方法是在__dirname
调用之前记录copyTpl
。将__dirname
与错误中正在寻找的源进行比较,您应该可以找出来。