2016-11-23 8 views
0

Ich fing an, über Yeoman Generatoren zu lernen und entschied mich zu versuchen, eine selbst zu machen, die einigen Tutorien folgt. Es ist sehr einfach, aber tut, was es gefragt wird. Mein Problem damit ist, nachdem ich nach Benutzereingabe für einen Namen frage, der einfach beendet wird, ohne in das Schreiben irgendwelcher der Akten zu gehen, keine Fehler beendet einfach. Ich habe den möglichen Schuldigen isoliert und es kam auf die async() Methode, denn wenn ich es kommentieren, läuft der Generator gut. Ich habe andere Generatoren installiert und sie verwenden auch die gleiche Art von prompt + async Struktur und ich habe keine Probleme damit, also frage ich mich, was ich falsch machen kann. Im Anschluss an die index.js Datei:Generator quittiert nach async() Anruf

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

}); 

Antwort

1

this.prompt nimmt keinen Rückruf. Es gibt ein Versprechen zurück.

+0

Vielen Dank, mein Herr! Offensichtlich war das Tutorial, dem ich folgte, wahrscheinlich veraltet, weil es eindeutig einen Rückruf angenommen hatte und alles wie erwartet funktionierte. –