diff options
author | Justin Worthe <justin.worthe@gmail.com> | 2014-04-21 08:43:46 +0200 |
---|---|---|
committer | Justin Worthe <justin.worthe@gmail.com> | 2014-04-21 08:43:46 +0200 |
commit | 1b700b59d6f759e1504c94eb0d378c61b7242da3 (patch) | |
tree | 7b3889e6ae1d22f4551cf56157a3cdeebe31d9c3 /Gruntfile.js | |
parent | 883a678635900b80cd9fc99467cbb31e125a007c (diff) |
Scaffolded Phaser template
Diffstat (limited to 'Gruntfile.js')
-rw-r--r-- | Gruntfile.js | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..29e5d02 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,97 @@ +// Generated on 2014-03-28 using generator-phaser-official 0.0.8-rc-2 +'use strict'; +var config = require('./config.json'); +var _ = require('underscore'); +_.str = require('underscore.string'); + +// Mix in non-conflict functions to Underscore namespace if you want +_.mixin(_.str.exports()); + +var LIVERELOAD_PORT = 35729; +var lrSnippet = require('connect-livereload')({port: LIVERELOAD_PORT}); +var mountFolder = function (connect, dir) { + return connect.static(require('path').resolve(dir)); +}; + +module.exports = function (grunt) { + // load all grunt tasks + require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks); + + grunt.initConfig({ + watch: { + scripts: { + files: [ + 'game/**/*.js', + '!game/main.js' + ], + options: { + spawn: false, + livereload: LIVERELOAD_PORT + }, + tasks: ['build'] + } + }, + connect: { + options: { + port: 9000, + // change this to '0.0.0.0' to access the server from outside + hostname: 'localhost' + }, + livereload: { + options: { + middleware: function (connect) { + return [ + lrSnippet, + mountFolder(connect, 'dist') + ]; + } + } + } + }, + open: { + server: { + path: 'http://localhost:9000' + } + }, + copy: { + dist: { + files: [ + // includes files within path and its sub-directories + { expand: true, src: ['assets/**'], dest: 'dist/' }, + { expand: true, flatten: true, src: ['game/plugins/*.js'], dest: 'dist/js/plugins/' }, + { expand: true, flatten: true, src: ['vendor/*.js'], dest: 'dist/js/' }, + { expand: true, src: ['css/**'], dest: 'dist/' }, + { expand: true, src: ['index.html'], dest: 'dist/' } + ] + } + }, + browserify: { + build: { + src: ['game/main.js'], + dest: 'dist/js/game.js' + } + } + }); + + grunt.registerTask('build', ['buildBootstrapper', 'browserify','copy']); + grunt.registerTask('serve', ['build', 'connect:livereload', 'open', 'watch']); + grunt.registerTask('default', ['serve']); + grunt.registerTask('prod', ['build', 'copy']); + + grunt.registerTask('buildBootstrapper', 'builds the bootstrapper file correctly', function() { + var stateFiles = grunt.file.expand('game/states/*.js'); + var gameStates = []; + var statePattern = new RegExp(/(\w+).js$/); + stateFiles.forEach(function(file) { + var state = file.match(statePattern)[1]; + if (!!state) { + gameStates.push({shortName: state, stateName: _.capitalize(state) + 'State'}); + } + }); + config.gameStates = gameStates; + console.log(config); + var bootstrapper = grunt.file.read('templates/_main.js.tpl'); + bootstrapper = grunt.template.process(bootstrapper,{data: config}); + grunt.file.write('game/main.js', bootstrapper); + }); +};
\ No newline at end of file |