Guy Korland
Guy Korland

Reputation: 9568

Can grunt install its own plugins?

It seems like if want to runt grunt on a "clean" machine we must write an external script that runs "npm install" first.

Is there a way to make grunt run first "npm install" to install its plugins in devDependencies?

Upvotes: 0

Views: 32

Answers (1)

raidendev
raidendev

Reputation: 2799

Grunt is just a node module and like any other module it's uses npm for dependency management. As I know, npm itself can not be accessed programmatically from modules.

But your questions can be solved in the grunt-way. Grunt has an interface called grunt.task.exists. You can use it for checking if the tasks were loaded and if something's not, then run grunt-shell's task containing npm install. One of the ways to implement this is to dynamically create aliases:

function safeTasks(tasks) {
  exists: for (var task in config) {
    if (!grunt.task.exists(task)) {
      tasks.unshift('shell:dependencies');
      break exists;
    }
  }

  return tasks;
}

grunt.registerTask('default', safeTasks(['one', 'another']));

Where config is the object passed to grunt.initConfig().

Upvotes: 1

Related Questions