Skip to content

Instantly share code, notes, and snippets.

@sgimeno
Last active January 3, 2016 10:39
Show Gist options
  • Save sgimeno/8451156 to your computer and use it in GitHub Desktop.
Save sgimeno/8451156 to your computer and use it in GitHub Desktop.
A Gruntfile for Apache Cordova app development. Mimics Cordova CLI commands. Usage: ''grunt exec:<command>[:platform]".
module.exports = function ( grunt ) {
/**
* Load required Grunt tasks. These are installed based on the versions listed
* in `package.json` when you do `npm install` in this directory.
*/
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-exec');
/**
* This is the configuration object Grunt uses to give each plugin its
* instructions.
*/
var taskConfig = {
/**
* The 'watch' task watches the files modified during development and runs
* the Cordova 'prepare' task which will copy your 'www' folder to the
* platform specific build directory (ie: platforms/android/assets/www)
*/
watch: {
scripts: {
files: [
'www/*.html',
'www/js/**/*.js',
'www/css/**/*.css',
'www/spec/**/*.js',
'www/res/**/*.*',
'www/img/**/*.*',
],
tasks: ['prepare'],
options: {
spawn: false,
},
},
},
exec: {
prepare: {
command: function(){
return 'cordova prepare';
}
},
build: {
command: function(){
return 'cordova build';
}
},
run: {
command: function(){
return 'cordova run';
}
}
}
};
grunt.initConfig( grunt.util._.extend( taskConfig ) );
grunt.registerTask( 'default', [ 'watch' ] );
grunt.registerTask( 'prepare', ['exec:prepare'] );
grunt.registerTask( 'build', ['prepare', 'exec:build' ] );
grunt.registerTask( 'run', ['build', 'exec:run' ] );
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment