2016-07-06 8 views
1

나는 yeoman과 함께 놀고있어 간단한 html5 상용구에 대한 첫 번째 생성기를 작성하려고한다. 내 문제는 제 발전기의 두 기능이 서로 잘 작동하지만 함께 작동하지 않는다는 것입니다. 이유는 모르겠습니다. 나는 yeoman 페이지에서 일부 발전기를 확인했지만, 내가 뭘 잘못하고 있는지 보지 못했다. 네가 나를 도울 수 있기를 바랍니다. 내 코드 :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" } 
    ); 
    }, 
}); 

미리 감사드립니다.

답변

1

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);

+0

덕분에, 그러나 이것은 :-(작동하지 않습니다 ... 콘솔에 오류가 있습니다 ... "개체 [개체 개체] '다음'에는 방법이 없습니다"내가 조만간 발전기를 업데이트하려고 시도했지만 오류가 남아 있습니다. 약속하기에 그다지 익숙하지 않지만 다른 발전기가 작동하지 않는 이유는 무엇입니까? – sonnenpriester

+0

약속이없는 오래된 구문은 여전히 ​​작동합니다. 더 새로운 방법보다 신뢰성이 떨어질 수 있습니다. 무슨 일이 일어나고 있는지 더 잘 알기 위해서는 콘솔에 'this'를 로깅 해보십시오 .-이 '생성자'는 전체 생성기 객체를 참조해야합니다.문제의 – Deimyts