@Deimytsの注釈のように、元のコードは機能しなくなりました。これはAPIの変更によるものですInquirer.JSdocumented here
- ベースのAPIインタフェースは今
inquirer.prompt(questions).then()
です。コールバック機能はもうありません。
- すべての非同期質問関数は、
this.async()
ではなく、戻り値として約束しています。一言で言えば
、代わりにちょうどprompting
機能(see docs)からの約束を返す古いvar done = this.async()
APIを使用してdone()
とコールバックの内側にプロンプトを解決します。詳細については
prompt1: function() {
this.log("HTML")
return this.prompt([
// configure prompts as before
]).then(function (answers) {
// callback body as before, but no more calling done()
}.bind(this));
},
@Deimytsは下記お答え参照してください。
ヨーマンはあなたにあなたの行動を置くために使用することができ、特定の事前定義された優先順位に実行ループを使用しています。 ☞ docsで説明したように、複数のメソッドを1つの優先度でグループ化できます。例えば、あなたがさらにあなたのコードをモジュール化できヨーマンのこの機能を使用する
'use strict';
var generators = require('yeoman-generator');
module.exports = generators.Base.extend({
constructor: function() {
generators.Base.apply(this, arguments);
},
prompting: {
prompt1: function() {
this.log("HTML")
var done = this.async();
this.prompt([{
type : 'input',
name : 'foo',
message : 'Foo',
}, {
type : 'input',
name : 'bar',
message : 'Bar'
}], function (answers) {
this.foo = answers.foo;
this.bar = answers.bar;
done();
}.bind(this));
},
prompt2: function() {
this.log("CSS")
var done = this.async();
this.prompt([{
type : 'input',
name : 'bam',
message : 'Bam',
}], function (answers) {
this.bam = answers.bam;
done();
}.bind(this));
}
},
configuring: function() {
console.log(this.foo, this.bar, this.bam);
}
});
:プロンプトは二つのグループHTML
とCSS
に分割してここで発電機を説明するためのスニペットですさまざまなプロンプトを別々のコードファイルに入れ、require
/import
をジェネレータファイルに入れます。しかし、基本的に上記のスニペットはトリックを行う必要があります。
それが役立つかどうか教えてください。
はい、これは動作しているようです。ありがとう! – michaeldeboeve
すばらしい、聞いてうれしい。 – sthzg
この解決法は私のためには機能しません。私はyeoman-generator v0.23.4を使用しています。ジェネレータは 'prompt1'だけを要求し、終了します。 'var done = this.async();'と 'done();'を削除すると、両方の質問をすることができますが、答えを待つことはありません。 – Deimyts