Automate "cordova prepare" to run after every www files changes using gulp?


#1

HI there,

is there a way to automate the cordova prepare command? I am making changes to the common folder www and I would like to copy the changes over to the platform ‘www’ without having to manually execute cordova prepare from the CLI each single time.

I tried to modify the gulp file with no success…any suggestion?

I added this to the gulpfile.js but no luck:

gulp.task("cordova-prepare", function() {
sh.exec("cordova prepare");
});

gulp.task("cordova-watch", function() {
gulp.watch([//
"www/**/*.html", //
"www/**/*.css", //
"www/**/*.js", //
"www/index.html"//
], //
["cordova-prepare"]);
})

#2

I don’t know why your code doesn’t work, but this works for me:

gulp.task('execPrepare', function(){
    sh.exec('cordova prepare android');
});

gulp.task('watchWww', function(){
    gulp.watch('./www/**/*', ['execPrepare']);
});

add it to gulpfile.js and run ‘gulp watchWww’ from the command line


#3

@mirko77 Just for curiosity, does the copy you want to do aim to bypass the ionic build android command too?
When you want to run your code on your device, don’t you execute ionic run android (that of course, copy all the www directory inside the specific platform folder) ?

In other words, what is the real benefit of cordova/ionic prepare?

My guess is that you want it to allow Eclipse or another IDE to build itself the component instead of Ionic CLI, right?