Automatic run gulp tasks via npm

Have I got a treat for you: I went ahead and made you a simple npm module to handle this.

gulp-npm-script-sync

Here is the gist of it:

  var file = fs.readFileSync(config.path || 'package.json', 'utf-8');
  var pkg = JSON.parse(file);
  var tasks = gulp.tasks;

  pkg.scripts = pkg.scripts || {};

  Object.keys(tasks).forEach(function (t) {
    pkg.scripts[t] = 'gulp '+tasks[t].name;
  });

The full source does stuff like write the package.json back with the same indention and stuff.

So yeah go ahead: npm install --save-dev gulp-npm-script-sync

Stick this in your gulpfile:

var gulp = require('gulp');
var sync = require('gulp-npm-script-sync');

// your gulpfile contents

sync(gulp);

Every time you update your gulpfile with a new task it will update your package.json.

You can even throw it inside a gulp task:

gulp.task('sync', function () {
  sync(gulp);
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)