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

标签 javascript yeoman

我正在摆弄 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/

相关文章:

javascript - 在 FireFox 和 IE 中使用 Selenium WebdriverJS 时出现问题

javascript - 如何在html中添加侧边栏菜单?

javascript - 如何使用 Yeoman 和 Angular Fullstack 更改/设置主视图

javascript - AngularJS 错误 : Module ngAnimate is not available

angularjs - Yeoman 和 Bower 未添加 Bootstrap CSS(AngularJS 生成器)

ubuntu - 在 ubuntu 上安装 Yeoman 时出错

javascript - 在 IE7 中,两个函数在 window.onload 中不起作用

javascript - 获取错误 : Promise rejected with no or falsy reason in mocha selenium node js

javascript - 如何在 Django 中使用 jQuery 或 javascript 以 5 秒的间隔自动保存

javascript - 自耕农 : angular-fullstack-generator cannot find module 'babel-runtime/helpers/interop-require-default'