【问题标题】:Yeoman generator not outputting anythingYeoman 发电机不输出任何东西
【发布时间】:2018-02-12 04:54:31
【问题描述】:

我正在尝试编写一个非常基本的生成器,它将创建 4 个与组件相关的文件。此时生成器需要做的就是从命令行获取组件名称,然后创建 4 个具有该名称的文件。生成器运行良好,但完成后不执行任何操作。

我的index.js 里面/app

'use strict';
//Require dependencies
var chalk = require('chalk');
var yosay = require('yosay');
var Generator = require('yeoman-generator');

module.exports = class extends Generator {
    prompting() {
      var done = this.async();
      this.prompt({
        type: 'input',
        name: 'componentName',
        message: 'Your component name',
        default: this.appname
      }, (answers) => {
        this.props = answers
      });
    }

    writing() {
        const componentName = this.props.componentName;

        this.fs.copyTpl(
            `${this.templatePath()}/**/!(_)*`,
            this.destinationPath(),
            this.props
        );

        this.fs.copyTpl(
            this.templatePath('src/_component.js'),
            this.destinationPath(`${componentName}.js`),
            this.props
        );

        this.fs.copyTpl(
            this.templatePath('src/_component.spec.js'),
            this.destinationPath(`${componentName}.spec.js`),
            this.props
        );

        this.fs.copyTpl(
            this.templatePath('src/_component.scss'),
            this.destinationPath(`${componentName}.scss`),
            this.props
        );

        this.fs.copyTpl(
            this.templatePath('src/_component.pug'),
            this.destinationPath(`${componentName}.pug`),
            this.props
        );
    }

    install() {
        this.installDependencies();
    }
};

【问题讨论】:

    标签: command-line-interface yeoman yeoman-generator


    【解决方案1】:

    要输出内容,请使用this.log("your message")。您可以在end() 函数中使用它来通知用户生成已完成

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-31
      • 1970-01-01
      • 1970-01-01
      • 2022-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多