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

ありがとうございました。どうやら、私が従っていたチュートリアルは、明らかにコールバックを取ったので、時代遅れだった可能性があります。 –

関連する問題