2014-11-28 19:38:50 -05:00
|
|
|
#- Imports, helpers
|
|
|
|
_ = require 'lodash'
|
|
|
|
_.str = require 'underscore.string'
|
2014-01-03 13:32:13 -05:00
|
|
|
sysPath = require 'path'
|
2014-11-28 19:38:50 -05:00
|
|
|
fs = require('fs')
|
|
|
|
commonjsHeader = fs.readFileSync('node_modules/brunch/node_modules/commonjs-require-definition/require.js', {encoding: 'utf8'})
|
2014-11-28 20:49:41 -05:00
|
|
|
|
|
|
|
|
|
|
|
#- regJoin replace a single '/' with '[\/\\]' so it can handle either forward or backslash
|
2014-11-28 19:38:50 -05:00
|
|
|
regJoin = (s) -> new RegExp(s.replace(/\//, '[\\\/\\\\]'))
|
|
|
|
|
|
|
|
|
|
|
|
#- Build the config
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
exports.config =
|
2014-11-28 19:38:50 -05:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
paths:
|
2014-10-19 01:11:39 -04:00
|
|
|
public: 'public'
|
2014-10-26 14:02:12 -04:00
|
|
|
watched: ['app', 'vendor', 'test/app', 'test/demo']
|
2014-11-28 19:38:50 -05:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
conventions:
|
2014-11-28 19:38:50 -05:00
|
|
|
ignored: (path) -> _.str.startsWith(sysPath.basename(path), '_')
|
|
|
|
|
|
|
|
sourceMaps: 'absoluteUrl'
|
|
|
|
|
2014-10-26 14:02:12 -04:00
|
|
|
overrides:
|
|
|
|
production:
|
2014-11-28 19:38:50 -05:00
|
|
|
sourceMaps: 'absoluteUrl'
|
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
files:
|
|
|
|
javascripts:
|
|
|
|
defaultExtension: 'coffee'
|
|
|
|
joinTo:
|
2014-11-28 19:38:50 -05:00
|
|
|
|
|
|
|
#- app.js, the first file that is loaded. These modules are required to initialize the client.
|
|
|
|
'javascripts/app.js': [
|
|
|
|
|
2014-11-28 20:49:41 -05:00
|
|
|
# IMPORTANT: if you add to this, make sure you also add any other dependencies,
|
|
|
|
# or better yet, put them in a 'core' folder.
|
2014-11-28 19:38:50 -05:00
|
|
|
regJoin('^app/schemas')
|
|
|
|
regJoin('^app/models')
|
|
|
|
regJoin('^app/collections')
|
2014-11-28 20:49:41 -05:00
|
|
|
regJoin('^app/core')
|
|
|
|
regJoin('^app/views/core')
|
2014-11-28 19:38:50 -05:00
|
|
|
'app/locale/locale.coffee'
|
2014-11-28 20:49:41 -05:00
|
|
|
'app/lib/sprites/SpriteBuilder.coffee' # loaded by ThangType
|
2014-11-28 19:38:50 -05:00
|
|
|
]
|
|
|
|
|
|
|
|
#- Wads. Groups of modules by folder which are loaded as a group when needed.
|
2014-11-29 11:54:08 -05:00
|
|
|
'javascripts/app/lib.js': regJoin('^app/lib')
|
2014-11-28 19:38:50 -05:00
|
|
|
'javascripts/app/views/play.js': regJoin('^app/views/play')
|
|
|
|
'javascripts/app/views/editor.js': regJoin('^app/views/editor')
|
|
|
|
|
|
|
|
#- world.js, used by the worker to generate the world in game
|
2014-11-28 20:49:41 -05:00
|
|
|
'javascripts/world.js': [
|
|
|
|
regJoin('^app/lib/world(?!/test)')
|
|
|
|
regJoin('^app/core/CocoClass.coffee')
|
|
|
|
regJoin('^app/core/utils.coffee')
|
|
|
|
regJoin('^vendor/scripts/Box2dWeb-2.1.a.3')
|
|
|
|
regJoin('^vendor/scripts/string_score.js')
|
|
|
|
regJoin('^bower_components/underscore.string')
|
|
|
|
]
|
2014-11-28 19:38:50 -05:00
|
|
|
|
|
|
|
#- vendor.js, all the vendor libraries
|
2014-11-28 20:49:41 -05:00
|
|
|
'javascripts/vendor.js': [
|
|
|
|
regJoin('^vendor/(?!scripts/Box2d)')
|
|
|
|
regJoin('^bower_components/(?!aether)')
|
|
|
|
]
|
2014-11-28 19:38:50 -05:00
|
|
|
|
|
|
|
#- Other vendor libraries in separate bunches
|
2014-11-28 20:49:41 -05:00
|
|
|
|
|
|
|
# Include box2dweb for profiling and IE9
|
|
|
|
# Vector renamed to Box2DVector to avoid name collisions
|
|
|
|
# TODO: move this to assets/lib since we're not really joining anything here?
|
|
|
|
'javascripts/box2d.js': regJoin('^vendor/scripts/Box2dWeb-2.1.a.3')
|
|
|
|
'javascripts/lodash.js': regJoin('^bower_components/lodash/dist/lodash.js')
|
|
|
|
'javascripts/aether.js': regJoin('^bower_components/aether/build/aether.js')
|
2014-11-28 19:38:50 -05:00
|
|
|
|
|
|
|
#- test, demo libraries
|
2014-11-28 20:49:41 -05:00
|
|
|
'javascripts/test-app.js': regJoin('^test/app/')
|
|
|
|
'javascripts/demo-app.js': regJoin('^test/demo/')
|
2014-11-29 16:47:04 -05:00
|
|
|
|
|
|
|
#- More output files are generated at the below
|
2014-06-30 22:16:26 -04:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
order:
|
|
|
|
before: [
|
2014-04-11 13:12:39 -04:00
|
|
|
'bower_components/jquery/dist/jquery.js'
|
2014-01-03 13:32:13 -05:00
|
|
|
'bower_components/lodash/dist/lodash.js'
|
|
|
|
'bower_components/backbone/backbone.js'
|
|
|
|
# Twitter Bootstrap jquery plugins
|
2014-04-05 20:05:03 -04:00
|
|
|
'bower_components/bootstrap/dist/bootstrap.js'
|
2014-01-03 13:32:13 -05:00
|
|
|
# CreateJS dependencies
|
|
|
|
'vendor/scripts/easeljs-NEXT.combined.js'
|
|
|
|
'vendor/scripts/preloadjs-NEXT.combined.js'
|
|
|
|
'vendor/scripts/soundjs-NEXT.combined.js'
|
|
|
|
'vendor/scripts/tweenjs-NEXT.combined.js'
|
|
|
|
'vendor/scripts/movieclip-NEXT.min.js'
|
2014-04-11 14:05:48 -04:00
|
|
|
# Validated Backbone Mediator dependencies
|
|
|
|
'bower_components/tv4/tv4.js'
|
2014-01-03 13:32:13 -05:00
|
|
|
# Aether before box2d for some strange Object.defineProperty thing
|
|
|
|
'bower_components/aether/build/aether.js'
|
2014-10-26 18:34:03 -04:00
|
|
|
'bower_components/fastclick/lib/fastclick.js'
|
2014-04-02 21:41:10 -04:00
|
|
|
'bower_components/d3/d3.min.js'
|
2014-04-22 11:54:35 -04:00
|
|
|
'vendor/scripts/async.js'
|
2014-10-27 16:32:25 -04:00
|
|
|
'vendor/scripts/jquery-ui-1.11.1.js.custom.js'
|
2014-01-03 13:32:13 -05:00
|
|
|
]
|
2014-11-28 19:38:50 -05:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
stylesheets:
|
|
|
|
defaultExtension: 'sass'
|
|
|
|
joinTo:
|
2014-04-07 17:34:36 -04:00
|
|
|
'stylesheets/app.css': /^(app|vendor|bower_components)/
|
2014-01-03 13:32:13 -05:00
|
|
|
order:
|
2014-04-02 17:40:06 -04:00
|
|
|
before: [
|
2014-07-14 12:52:23 -04:00
|
|
|
'app/styles/bootstrap/*'
|
2014-04-03 14:43:09 -04:00
|
|
|
'vendor/styles/nanoscroller.scss'
|
2014-04-02 17:40:06 -04:00
|
|
|
]
|
2014-11-28 19:38:50 -05:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
templates:
|
|
|
|
defaultExtension: 'jade'
|
2014-11-28 19:38:50 -05:00
|
|
|
joinTo:
|
2014-11-29 14:39:37 -05:00
|
|
|
'javascripts/app.js': regJoin('^app/templates/core')
|
2014-11-28 19:38:50 -05:00
|
|
|
'javascripts/app/views/play.js': regJoin('^app/templates/play')
|
|
|
|
'javascripts/app/views/game-menu.js': regJoin('^app/templates/game-menu')
|
|
|
|
'javascripts/app/views/editor.js': regJoin('^app/templates/editor')
|
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
framework: 'backbone'
|
|
|
|
|
|
|
|
plugins:
|
2014-06-07 19:30:01 -04:00
|
|
|
autoReload:
|
2014-06-30 22:16:26 -04:00
|
|
|
delay: 300
|
2014-01-03 13:32:13 -05:00
|
|
|
coffeelint:
|
|
|
|
pattern: /^app\/.*\.coffee$/
|
2014-11-28 19:38:50 -05:00
|
|
|
# pattern: /^dne/ # use this pattern instead if you want to speed compilation
|
2014-01-03 13:32:13 -05:00
|
|
|
options:
|
|
|
|
line_endings:
|
2014-06-30 22:16:26 -04:00
|
|
|
value: 'unix'
|
|
|
|
level: 'error'
|
2014-01-03 13:32:13 -05:00
|
|
|
max_line_length:
|
2014-06-30 22:16:26 -04:00
|
|
|
level: 'ignore'
|
2014-01-03 13:32:13 -05:00
|
|
|
no_trailing_whitespace:
|
2014-06-30 22:16:26 -04:00
|
|
|
level: 'ignore' # PyCharm can't just autostrip for .coffee, needed for .jade
|
2014-01-03 13:32:13 -05:00
|
|
|
no_unnecessary_fat_arrows:
|
2014-06-30 22:16:26 -04:00
|
|
|
level: 'ignore'
|
2014-01-03 13:32:13 -05:00
|
|
|
uglify:
|
2014-11-29 03:29:32 -05:00
|
|
|
mangle:
|
|
|
|
except: ['require']
|
2014-01-03 13:32:13 -05:00
|
|
|
output:
|
2014-01-03 16:49:36 -05:00
|
|
|
semicolons: false
|
2014-09-30 22:57:36 -04:00
|
|
|
sass:
|
|
|
|
mode: 'ruby'
|
2014-10-01 13:58:19 -04:00
|
|
|
allowCache: true
|
2014-06-07 19:30:01 -04:00
|
|
|
|
2014-11-28 19:38:50 -05:00
|
|
|
modules:
|
|
|
|
definition: (path, data) ->
|
|
|
|
needHeaders = [
|
|
|
|
'public/javascripts/app.js'
|
|
|
|
'public/javascripts/world.js'
|
|
|
|
]
|
|
|
|
defn = if path in needHeaders then commonjsHeader else ''
|
|
|
|
return defn
|
|
|
|
|
2014-11-29 16:47:04 -05:00
|
|
|
|
|
|
|
#- Find all .coffee and .jade files in /app
|
|
|
|
|
|
|
|
dirStack = ['./app']
|
|
|
|
coffeeFiles = []
|
|
|
|
jadeFiles = []
|
|
|
|
|
|
|
|
while dirStack.length
|
|
|
|
dir = dirStack.pop()
|
|
|
|
contents = fs.readdirSync(dir)
|
|
|
|
for file in contents
|
|
|
|
fullPath = "#{dir}/#{file}"
|
|
|
|
stat = fs.statSync(fullPath)
|
|
|
|
if stat.isDirectory()
|
|
|
|
dirStack.push(fullPath)
|
|
|
|
else
|
|
|
|
if _.str.endsWith(file, '.coffee')
|
|
|
|
coffeeFiles.push(fullPath)
|
|
|
|
else if _.str.endsWith(file, '.jade')
|
|
|
|
jadeFiles.push(fullPath)
|
|
|
|
|
2014-11-28 19:38:50 -05:00
|
|
|
for file in coffeeFiles
|
|
|
|
inputFile = file.replace('./app', 'app')
|
|
|
|
outputFile = file.replace('.coffee', '.js').replace('./app', 'javascripts/app')
|
|
|
|
exports.config.files.javascripts.joinTo[outputFile] = inputFile
|
2014-11-29 15:46:04 -05:00
|
|
|
|
|
|
|
numBundles = 0
|
|
|
|
|
2014-11-28 19:38:50 -05:00
|
|
|
for file in jadeFiles
|
|
|
|
inputFile = file.replace('./app', 'app')
|
|
|
|
outputFile = file.replace('.jade', '.js').replace('./app', 'javascripts/app')
|
2014-11-29 15:46:04 -05:00
|
|
|
exports.config.files.templates.joinTo[outputFile] = inputFile
|
|
|
|
|
|
|
|
#- If a view template name matches its view, bundle it in there.
|
|
|
|
templateFileName = outputFile.match(/[^/]+$/)[0]
|
|
|
|
viewFileName = _.str.capitalize(_.str.camelize(templateFileName))
|
|
|
|
possibleViewFilePath = outputFile.replace(templateFileName, viewFileName).replace('/templates/', '/views/')
|
|
|
|
if exports.config.files.javascripts.joinTo[possibleViewFilePath]
|
|
|
|
exports.config.files.templates.joinTo[possibleViewFilePath] = inputFile
|
|
|
|
numBundles += 1
|
|
|
|
|
2014-11-29 16:47:04 -05:00
|
|
|
console.log "Got #{coffeeFiles.length} coffee files and #{jadeFiles.length} jade files (bundled #{numBundles} of them together)."
|