Search code examples
javascriptgulpjspm

Install all JSPM dependencies in gulp task


I want to have one command to download all dependencies the project need. This should be a gulp dependencies. I have a JSPM dependencies in the fronted and I can install them by typing jspm install in the command line. I want to automate it with gulp (it would take care about other dependencies, too, like pip, composer etc).

Here is what I have tried:

gulp.task('dependencies', ['deps-composer', 'deps-jspm', 'deps-pip']);

// others

gulp.task('deps-jspm', function (done) {
  require('jspm').install().then(done);
});

However, it only creates an empty jspm_packages directory and does not download anything.

I have succeeded with the following

gulp.task('deps-jspm', function (done) {
  require('child_process').execSync('jspm install');
});

but it looks like an overkill and it requires the jspm to be installed globally.

The directory structure is normal, i.e. there is a package.json, config.js and gulpfile.js in the root directory.


Solution

  • jspm.install() expects a package name as its first argument in order to install a specific package. If you want to install all packages you have to pass true (see the docs):

    gulp.task('deps-jspm', function (done) {
      require('jspm').install(true).then(done);
    });