I found that I had to use __dirname to request the gulpfile.js file.
#!/usr/bin/env node module.exports = function(context) { var Q = context.requireCordovaModule('q'); var deferral = new Q.defer(); var path = require('path'), gulp = require('gulp'), gulpfile = path.join(__dirname, 'gulpfile'); require(gulpfile); gulp.start('myTask').once('task_stop', function(){ console.log('myTask done'); deferral.resolve(); }); return deferral.promise; }
NB: here 'gulpfile.js' and 'hook.js' are in the same directory. You can set your own path to include the js file in the Cordova config.xml file:
<hook type="before_build" src="app/hook.js" />
source share