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.