Yeoman Generator: Installing project dependencies in custom folder
Asked Answered
A

1

9

After generating my project scaffolding, I'd like Yeoman to install my npm dependencies in a subfolder, rather than in the main project folder. I have my package.json file in the /gulp subfolder of my project. How can I have Yeoman install the dependencies there? Here is my current function that runs at the end of the generator:

this.on('end', function () {
  if (!this.options['skip-install']) {
    this.installDependencies({
      bower: false,
      npm: true
    });
  }
});
Abaxial answered 12/3, 2014 at 19:6 Comment(0)
A
16

Finally got this working by changing the directory before running this.installDependencies() in index.js, as in:

this.on('end', function () {
  if (!this.options['skip-install']) {

    // Change working directory to 'gulp' for dependency install
    var npmdir = process.cwd() + '/gulp';
    process.chdir(npmdir);

    this.installDependencies({
      bower: false,
      npm: true
    });
  }
});

Hope this helps if you have a different project scaffolding setup.

Abaxial answered 13/3, 2014 at 14:7 Comment(3)
Alternatively, you could also run any shell command (*nix or windows) using this.spawnCommand("npm", ["install"], { cwd: 'scripts'}) where cwd points to the directory you wish to run your command from.Effuse
@KirillG.'s solution works for me. However, a package-lock.json was created in the current directory. Any ideas on why this is happening? This is in the package-lock.json { "lockfileVersion": 1 }Inwrought
@VienTang In order to avoid creating a package-lock on the root try the following javascript this.npmInstall([], { prefix: 'scripts' }); Elva

© 2022 - 2024 — McMap. All rights reserved.