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

时间:2016-07-06 19:54:05

标签: javascript yeoman

我正在为自耕农做准备,并希望为一个简单的html5样板编写我的第一台发电机。我的问题是,我的发电机中的两个功能本身运行良好,但不是在一起,我不知道为什么。我从自耕农页面检查了一些发电机,但我看不出我做错了什么。我希望你能帮助我。这是我的代码:

'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" }
    );
  },
});

提前致谢!

1 个答案:

答案 0 :(得分:1)

Try using the Promises version of the prompting function, as shown on yeoman.io.

Example:

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));
  },

Changes:

  1. add return before this.prompt().

  2. change this.prompt(prompts, callback); to this.prompt(prompts).then(callback);