0

I would like to create/update file(s) after the dependencies have been installed, when the generator(generator-custom) has been executed.

$ yo custom

Any pointer would be very helpful.


For example, I am trying to update the devDependencies section of the package.json with respect to the dependent packages devDependencies after the dependencies have been installed. However I am unable to achieve it. Please find the below code snippet.

install: function () {
  this.installDependencies({
    skipInstall: this.options['skip-install'],
    callback: function () {
      var pkgPath = process.cwd() + '/package.json';
      var pkg = require(pkgPath);
      pkg.devDependencies = {
        "grunt": "~0.4.2"
      };
      this.write(pkgPath, JSON.stringify(pkg));
    }.bind(this)
  });
}

The idea behind updating the package.json, was to rerun the installDependencies function. So that when ever the core package updates its dependency, the generator does not require to update its template.

As suggested by @SimonBoudrias, the above is not efficient way to perform the operation. The dependent packages can be installed by using peerDependencies of the main dependent package.


4

1 回答 1

0

我想在安装依赖项后创建/更新文件,同时执行生成器(生成器自定义)。

以下代码段服务于所需的用例。

this.npmInstall(['npm-module'], {}, function() {
  this.write('path/to/file', 'file-content');
}.bind(this));
于 2015-04-26T19:49:48.830 回答