安装依赖项在yeoman中不起作用

时间:2020-06-17 15:41:05

标签: javascript node.js yeoman yeoman-generator

写完后,我已经创建了自定义生成器,我想在新创建的目录中运行npm install,该目录具有package.json,而不是在我正在运行my-custom-generator的文件中查找package.json。

index.js

'use strict';
const Generator = require('yeoman-generator');
const chalk = require('chalk');
const yosay = require('yosay');

module.exports = class extends Generator {
  prompting() {
    // Have Yeoman greet the user.
    this.log(
      yosay(
        `Welcome to the epic ${chalk.red(
          "generator-cvsdigital-sdk-nodeapp-generator"
        )} generator!`
      )
    );
    const prompts = [
      {
        type: "input",
        name: "appName",
        message: "Your project name",
        // Defaults to the project's folder name if the input is skipped
        default: "app"
      }
    ];

    return this.prompt(prompts).then(props => {
      // To access props later use this.props.someAnswer;
      this.props = props;
      this._setDefaultValues();
    });
  }

  _setDefaultValues() {
    this.props.appName = this.props.appName || "app";
  }

  writing() {
    const appName = this.props.appName;
    // This.fs.copyTpl(
    //   this.templatePath("package.json"),
    //   this.destinationPath(`${appName}/${"package.json"}`)
    // );
    this.fs.copy(this.templatePath(), this.destinationPath(`${appName}`));
    this.runInstall();
  }

  runInstall() {
    const npmdir = process.cwd() + "/" + this.appname;
    console.log("director", npmdir);
    this.installDependencies({
      npm: true,
      bower: false
    });
  }
};

0 个答案:

没有答案