Created
June 14, 2013 14:56
-
-
Save jessefreeman/5782520 to your computer and use it in GitHub Desktop.
A quick build script I wrote to generate Win8, WP8 and web builds of my Impact games
This file contains hidden or 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) { | |
| grunt.loadNpmTasks('grunt-shell'); | |
| grunt.loadNpmTasks('grunt-express-server'); | |
| grunt.loadNpmTasks('grunt-contrib-watch'); | |
| grunt.loadNpmTasks('grunt-contrib-copy'); | |
| grunt.loadNpmTasks('grunt-text-replace'); | |
| grunt.loadNpmTasks('grunt-contrib-clean'); | |
| grunt.loadNpmTasks('grunt-contrib-uglify'); | |
| grunt.loadNpmTasks('grunt-open'); | |
| // Project settings | |
| var rootProject = "./Projects/SuperJetroidStarterKitWin8/"; | |
| var wp8Project = "./Projects/SuperJetroidStarterKitWP8/"; | |
| var deployDir = "./Deploy/"; | |
| var entityJSON = grunt.file.read(rootProject+"media/textures/entities.txt"); | |
| var screensJSON = grunt.file.read(rootProject+"media/textures/screens.txt"); | |
| // Project configuration. | |
| grunt.initConfig({ | |
| pkg: grunt.file.readJSON('package.json'), | |
| shell: { | |
| multiple: { | |
| command: [ | |
| 'cd '+deployDir+'/tmp', | |
| 'php tools/bake.php lib/impact/impact.js lib/game/main.js js/game.min.js' | |
| ].join('&&'), | |
| options: { | |
| stdout: true | |
| } | |
| } | |
| }, | |
| copy: { | |
| tmp: { | |
| files: [ | |
| { expand: true, cwd: 'Projects/SuperJetroidStarterKitWin8/', src: ['index.html'], dest: deployDir+'/tmp/', filter: 'isFile'}, | |
| { expand: true, cwd: 'Projects/SuperJetroidStarterKitWin8/', src: ['css/**', 'js/**', 'lib/**', 'media/**', '!**/*.txt', 'tools/**', '!js/default.js', '!css/snap-view.css'], dest: deployDir+'tmp/' } | |
| ] | |
| }, | |
| web: { | |
| files: [ | |
| { expand: true, cwd: deployDir+'tmp', src: ['./**'], dest: deployDir+'web/' } | |
| ] | |
| }, | |
| blog: { | |
| files: [ | |
| { expand: true, cwd: deployDir+'tmp', src: ['./**'], dest: deployDir+'blog/' } | |
| ] | |
| }, | |
| wp8: { | |
| files: [ | |
| { expand: true, cwd: deployDir+'tmp', src: ['./**', '!./media/sounds/*.ogg'], dest: wp8Project+'Html/' }, | |
| { expand: true, cwd: 'Resources/build/', src: ['console-log-wp8.js'], dest: wp8Project+'Html/js/', filter: 'isFile'} | |
| ] | |
| } | |
| , | |
| win8: { | |
| files: [ | |
| { expand: true, cwd: deployDir+'tmp', src: ['js/game.min.js'], dest: rootProject, filter: 'isFile'} | |
| ] | |
| } | |
| }, | |
| clean: { | |
| deploy: ["Deploy"], | |
| tmp: [deployDir+"tmp"], | |
| phone: [wp8Project+'Html/'], | |
| lib: [deployDir+"tmp/tools", deployDir+"tmp/lib"] | |
| }, | |
| replace: { | |
| gamePath: { | |
| src: [deployDir+'tmp/index.html'], // source files array (supports minimatch) | |
| dest: deployDir+'tmp/index.html', // destination directory or file | |
| replacements: [{ | |
| from: '<script type="text/javascript" src="lib/impact/impact.js"></script>', // string replacement | |
| to: '' | |
| }, | |
| { | |
| from: rootProject+'lib/game/main.js', // string replacement | |
| to: rootProject+'js/game.min.js' | |
| }, | |
| { | |
| from: 'lib/game/main.js', // string replacement | |
| to: 'js/game.min.js' | |
| }, | |
| { | |
| from: rootProject+'lib/game/main.js', // string replacement | |
| to: rootProject+'js/game.min.js' | |
| }] | |
| }, | |
| textureAtlas: { | |
| src: [deployDir+'tmp/lib/game/packed-textures.js'], // source files array (supports minimatch) | |
| dest: deployDir+'tmp/lib/game/packed-textures.js', // destination directory or file | |
| replacements: [{ | |
| from: 'this.entityJSON', | |
| to: entityJSON | |
| }, | |
| { | |
| from: 'this.screenJSON', | |
| to: screensJSON | |
| }] | |
| }, | |
| blog: { | |
| src: [deployDir+'blog/js/game.min.js'], | |
| dest: deployDir+'blog/js/game.min.js', | |
| replacements: [{ | |
| from: 'media', | |
| to: '/wp-content/games/super-resident-raver/media/' | |
| }] | |
| }, | |
| wp8:{ | |
| src: [wp8Project+'Html/js/resize-game.js'], | |
| dest: wp8Project+'Html/js/resize-game.js', | |
| replacements: [{ | |
| from: 'gameCanvas.style.marginTop = ', | |
| to: 'gameCanvas.style.top = 0;//' | |
| }, | |
| { | |
| from: 'gameCanvas.style.marginLeft = ', | |
| to: 'gameCanvas.style.left = 0;//' | |
| }] | |
| } | |
| }, | |
| uglify: { | |
| tmp: { | |
| options: { | |
| beautify: false, | |
| mangle: true | |
| }, | |
| files: { | |
| 'Deploy/tmp/js/game.min.js': ['Deploy/tmp/js/game.min.js'] | |
| } | |
| } | |
| }, | |
| express: { | |
| options: { | |
| background: true | |
| }, | |
| dev: { | |
| options: { | |
| script: 'server.js' | |
| } | |
| } | |
| }, | |
| watch: { | |
| express: { | |
| files: [rootProject+'lib/**/*.js'], | |
| tasks: ['express:dev'], | |
| options: { | |
| nospawn: true //Without this option specified express won't be reloaded | |
| } | |
| } | |
| }, | |
| open: { | |
| dev: { | |
| path: 'http://localhost:8080/Projects/SuperJetroidStarterKitWin8/index.html' | |
| }, | |
| web: { | |
| path: 'http://localhost:8080/Deploy/Web/index.html' | |
| } | |
| } | |
| }); | |
| // Default task(s). | |
| grunt.registerTask('default', ['express:dev', 'open:dev', 'watch']); | |
| grunt.registerTask('bake', ['clean:deploy', | |
| 'copy:tmp', | |
| 'replace:textureAtlas', | |
| 'shell', | |
| 'uglify', | |
| 'clean:lib', | |
| 'replace:gamePath', | |
| 'copy:web', | |
| 'clean:phone', | |
| 'copy:wp8', | |
| 'copy:blog', | |
| 'replace:blog', | |
| 'copy:win8', | |
| 'clean:tmp']); | |
| grunt.registerTask('debug', ['clean:deploy', | |
| 'copy:tmp', | |
| 'replace:textureAtlas', | |
| 'copy:web', | |
| 'clean:phone', | |
| 'copy:wp8', | |
| 'copy:blog', | |
| 'replace:blog']); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment