Search code examples
cordovagulpcordova-cli

Gulp hook before 'cordova build xxx'


I have my gulpfile.js with some tasks and I want to execute one task when I do cordova build

I created a before_build folder inside of the hooks folder with a simple console.log("a")in a js file.

But whe I run for example cordova build android it says 'console' is undefined, I have to do something else to run Javascript? I couldn´t find more info.

Thanks!

EDIT:

I added #!/usr/bin/env node at the top of my .js file and the console.log works but now I want to do gulp myTask and is throwing to me gulp is not defined


Solution

  • You can run it without leaving Node by pasting this code into the file before_build/010_compile_css.js:

    #!/usr/bin/env node
    
    var gulp = require('gulp');
    var path  = require('path');
    
    var rootdir = process.argv[2];
    var gulpfile = path.join(rootdir, 'gulpfile.js');
    
    process.stdout.write('Compiling SCSS');
    
    require(gulpfile);
    
    //interaction
    gulp.start('scss');