-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ] ); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Platform argument is not working as I expected. Sorry for that. Usage is grunt exec:[:platform]