2017-01-18 12 views
0

私はYeomanジェネレータを作成して、私のプロセスをスピードアップしようとしていますが、 に問題があります。Yeomanジェネレータが意図したとおりに動作しない

  • の入力ではなく、提供された値で、値trueある
  • すべての値が、私は確認を得るが、その何が他の(起こりませんした後、すべての引数が提供されている場合にのみ提供されていない場合には)
  • scaffoldFoldersはフォルダ (EDIT作成されていません:作業)

がないことです誰もが私の問題の解決策を知っていますか?

'use strict'; 
var Generator = require('yeoman-generator'); 
var util = require('util') 
var OptionOrPrompt = require('yeoman-option-or-prompt'); 
var mkdirp = require('mkdirp'); 
var _ = require('underscore.string'); 

var GlatGenerator = class extends Generator { 

    constructor(args, opts) { 
    // Calling the super constructor is important so our generator is correctly set up 
    super(args, opts); 
    this._optionOrPrompt = OptionOrPrompt; 
    this.props = {}; 
    } 

    prompting() { 
    var done = this.async(); 
    // Instead of calling prompt, call _optionOrPrompt to allow parameters to be passed as command line or composeWith options. 
    this._optionOrPrompt([{ 
     type: 'input', 
     name: 'name', 
     message: 'Your component name', 
     default: 'hoogwerker', 
     store: true 
    }, { 
     type: 'confirm', 
     name: 'model', 
     message: 'Should we create a model for you?', 
     default: true, 
     store: true 
    }, { 
     type: 'confirm', 
     name: 'service', 
     message: 'Should we create a service for you?', 
     default: true, 
     store: true 
    }], function (answers) { 
     this.props.componentName = answers.name 
     this.props.createModel = answers.model 
     this.props.createService = answers.service 
     console.log("**********************"); 
     console.log("***" + (JSON.stringify(answers))); 
     console.log("**********************"); 
     done(); 
    }.bind(this)); 
    } 

    scaffoldFolders() { 
    console.log('scaffoldFolders'); 
    var slugify = _.slugify(this.props.componentName); 
    var classify = _.classify(this.props.componentName); 
    var lowerName = _.decapitalize(_.classify(this.props.componentName)); 

    mkdirp("src/components/" + lowerName); 
    mkdirp("src/components/" + lowerName + "/components"); 
    if (this.props.createModel) { 
     mkdirp("src/components/" + lowerName + "/models"); 
    } 
    if (this.props.createModel) { 
     mkdirp("src/components/" + lowerName + "/services"); 
    } 
    } 

    copyMainFiles() { 
    console.log('copyMainFiles'); 
    var slugify = _.slugify(this.props.componentName); 
    var classify = _.classify(this.props.componentName); 
    var lowerName = _.decapitalize(classify); 
    var dash = _.dasherize(lowerName); 

    var context = { 
     component_name: slugify, 
     component_name_camel: classify, 
     component_name_lower: lowerName, 
     component_name_dash: dash, 
    }; 

    var base = "src/components/" + lowerName + "/"; 

    this.fs.copyTpl(
     this.templatePath('base-files/_component.html'), 
     this.destinationPath(base + lowerName + ".component.html"), 
     context 
    ); 

    this.fs.copyTpl(
     this.templatePath('base-files/_component.scss'), 
     this.destinationPath(base + lowerName + ".component.scss"), 
     context 
    ); 

    this.fs.copyTpl(
     this.templatePath('base-files/_component.ts'), 
     this.destinationPath(base + lowerName + ".component.ts"), 
     context 
    ); 

    this.fs.copyTpl(
     this.templatePath('base-files/_module.ts'), 
     this.destinationPath(base + lowerName + ".module.ts"), 
     context 
    ); 

    this.fs.copyTpl(
     this.templatePath('base-files/_routes.ts'), 
     this.destinationPath(base + lowerName + ".routes.ts"), 
     context 
    ); 

    if (this.props.createModel) { 
     this.fs.copyTpl(
     this.templatePath('model/_model.ts'), 
     this.destinationPath(base + "/models/" + classify + ".ts"), 
     context 
    ); 
    } 

    if (this.props.createService) { 
     this.fs.copyTpl(
     this.templatePath('service/_service.ts'), 
     this.destinationPath(base + "/services/" + lowerName + ".service.ts"), 
     context 
    ); 
    } 
    } 
}; 

module.exports = GlatGenerator; 


// module.exports = base.extend({ 
//  initializing:() => {}, 
//  prompting: () => {}, 
//  configuring: () => {}, 
//  default: () => {}, 
//  writing: () => {}, 
//  conflicts: () => {}, 
//  install: () => {}, 
//  end: () => {} 
// }); 
をして使用するコマンド:

yo glat:component --name="hoogwerker" --model --service 

答えて

1

--nameブールとして解析されている。ここで

は、私が使用しているindex.jsです型を文字列として指定する必要があります。 this.option('name', {type: String})

第2の点は、_optionOrPromptの機能が表示されていないと手伝ってもらえません。しかし、それはあなたの側のバグのように見えますが、関数はすべての値がオプションとして渡されたときにコールバックをトリガーしません。

+0

_optionOrPromptはプラグインからのものです(https://github.com/artefact-group/yeoman-option-or-prompt) – Kiwi

+0

@Kiwiはこのプラグインのようにバグがあります。バグレポートを開くべきです。 –

関連する問題