Hello @kartik,
Here is the code:
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;
});
So use: 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);
}