Skip to content

Instantly share code, notes, and snippets.

@qustosh
Forked from sgimeno/Gruntfile.js
Created January 16, 2014 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qustosh/8451782 to your computer and use it in GitHub Desktop.
Save qustosh/8451782 to your computer and use it in GitHub Desktop.
A Gruntfile for Apache Cordova app development. Includes prepare, build and run tasks to mimic Cordova CLI commands. Usage: 'grunt <command> [platform]'. If no platform is provided Cordova will try to perform the task for all the installed platforms. Default task 'watch' watches for source changes and runs the prepare task.
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/templates/**/*.tpl.html',
'www/js/**/*.js',
'www/css/**/*.css',
'www/spec/**/*.js',
'www/res/**/*.*',
'www/img/**/*.*',
],
tasks: ['prepare'],
options: {
spawn: false,
},
},
},
exec: {
prepare: {
command: function(platform){
return 'cordova prepare' + ((platform) ? ' ' + platform : '');
}
},
build: {
command: function(platform){
return 'cordova build' + ((platform) ? ' ' + platform : '');
}
},
run: {
command: function(platform){
return 'cordova run' + ((platform) ? ' ' + platform : '');
}
}
}
};
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' ] );
};
@sgimeno
Copy link

sgimeno commented Jan 16, 2014

Platform argument is not working as I expected. Sorry for that. Usage is grunt exec:[:platform]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment