2016-11-23 82 views
0

我开始学习Yeoman生成器,并决定在遵循一些教程的情况下尝试自己做一个。这是非常基本的,但它做了什么要求。我的问题是,在我要求用户输入一个名字后,它只是退出/结束而没有写入任何文件,没有错误就退出了。我已经隔离了可能的罪魁祸首,它归结为async()方法,因为如果我将它注释掉,生成器运行良好。我安装了其他的生成器,他们也使用相同类型的提示+异步结构,我没有问题,所以我想知道我能做什么错。以下是index.js文件:发生器在async()调用后退出

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

module.exports = yeoman.Base.extend({ 

    constructor: function() { 
    // Calling the super constructor is important so our generator is correctly set up 
    yeoman.Base.apply(this, arguments); 
    }, 

    prompting: function() { 

    var done = this.async(); 
    this.prompt({ 
     type: 'input', 
     name: 'name', 
     message: 'Whats the project name?', 
     default: this.appname 
    }, function(answers) { 
     done(); 
    }.bind(this)); 

    this.props = { 
    name: "yosass" 
    }; 
    }, 

    writing: { 
    //Copy the configuration files 
    config: function() { 
     this.log("CONFIG COPYING"); 
     this.props.name = "yosass"; 
     this.fs.copyTpl(
     this.templatePath('_package.json'), 
     this.destinationPath('package.json'), { 
      name: this.props.name 
     } 
    ); 

     this.fs.copy(
     this.templatePath('_gulpfile.js'), 
     this.destinationPath('gulpfile.js') 
    ) 
    }, 

    //Copy application files 
    app: function() { 
     this.log("APP COPYING"); 
     this.fs.copy(
     this.templatePath('_css/_main.scss'), 
     this.destinationPath("css/main.scss") 
    ); 

     this.fs.copy(
     this.templatePath("_css/_globals/_variables.scss"), 
     this.destinationPath("css/globals/_variables.scss") 
    ); 

     this.fs.copy(
     this.templatePath("_css/_globals/_mixins.scss"), 
     this.destinationPath("css/globals/_mixins.scss") 
    ); 

     this.fs.copy(
     this.templatePath("_css/_globals/_colors.scss"), 
     this.destinationPath("css/globals/_colors.scss") 
    ); 
    } 
    }, 

    _copy: function(from, to) { 
    this.fs.copy(this.templatePath(from), this.destinationPath(to)); 
    }, 

    _copyTpl: function(from, to) { 
    this.fs.copy(this.templatePath(from), this.destinationPath(to)); 
    }, 

    //Install Dependencies 
    install: function() { 
    this.installDependencies(); 
    } 

}); 

回答

1

this.prompt不需要回调。它返回一个承诺。

+0

谢谢亲切的先生!显然,我所遵循的教程很可能已经过时,因为它显然需要回调,现在都按预期工作。 –