gpt4 book ai didi

javascript - 提示后 Yeoman 复制功能不起作用

转载 作者:行者123 更新时间:2023-11-27 22:48:43 24 4
gpt4 key购买 nike

我正在摆弄 yeoman,想为一个简单的 html5 样板编写我的第一个生成器。我的问题是,我的生成器中的两个函数单独工作得很好,但不能一起工作,我不知道为什么。我从 yeoman 页面检查了一些生成器,但我不明白我做错了什么。我希望你可以帮助我。这是我的代码:

'use strict';
var generators = require('yeoman-generator');
var yosay = require('yosay');

module.exports = generators.Base.extend({

initializing: function(){
this.log(yosay("\'Allo \'allo I will create your HTML5 Boilerplate..."));
},

prompting: function() {
var done = this.async();
this.prompt({
type: 'input',
name: 'name',
message: 'Your project name',
//Defaults to the project's folder name if the input is skipped
default: this.appname
}, function(answers) {

this.props = answers
this.log(answers.name);
done();
}.bind(this));
},

writing: function(){
this.fs.copyTpl(
this.templatePath('_page/_index.html'),
this.destinationPath('index.html'),
{ title: "answers.name" }
);
},
});

提前致谢!

最佳答案

尝试使用Promises版本的提示函数,如yeoman.io所示.

示例:

prompting: function() {
return this.prompt({
type: 'input',
name: 'name',
message: 'Your project name',
//Defaults to the project's folder name if the input is skipped
default: this.appname
}).then(function(answers) {
this.props = answers
this.log(answers.name);
}.bind(this));
},

变化:

  1. this.prompt() 之前添加 return

  2. this.prompt(prompts, callback); 更改为 this.prompt(prompts).then(callback);

关于javascript - 提示后 Yeoman 复制功能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38232654/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com