2016-11-23 17 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

謝謝親切的先生!顯然,我所遵循的教程很可能已經過時,因爲它顯然需要回調,現在都按預期工作。 –

相關問題