You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.7 KiB
CoffeeScript
51 lines
1.7 KiB
CoffeeScript
fs = require 'fs'
|
|
{exec,spawn} = require 'child_process'
|
|
util = require 'util'
|
|
glob = require 'glob'
|
|
|
|
sources = [
|
|
'gamepad.coffee'
|
|
'init.coffee'
|
|
]
|
|
sourcestring = ""
|
|
for source in sources
|
|
sourcestring += 'src/'+source+' '
|
|
|
|
task 'watch', 'Watch source files and build changes', ->
|
|
watch = spawn "node_modules/coffeescript/bin/coffee", ['-c', '-w', '-m', '--no-header', '-j', 'lib/index.js', sourcestring]
|
|
watch.stdout.on 'data', (data) -> console.log data.toString().trim()
|
|
|
|
task 'compile', 'Compile all CoffeeScript files', ->
|
|
# prepare lib directory
|
|
if not fs.existsSync 'lib'
|
|
fs.mkdirSync 'lib'
|
|
|
|
# run coffee-script compile
|
|
exec "cat #{sourcestring} > lib/index.coffee"
|
|
|
|
files = glob.sync('src/mappings/*.json')
|
|
mappings = []
|
|
for file in files
|
|
data = JSON.parse(fs.readFileSync(file))
|
|
mappings.push data
|
|
code = fs.readFileSync("lib/index.coffee")
|
|
writestr = "mappings = JSON.parse('#{JSON.stringify(mappings)}')"
|
|
code = writestr + "\n\n" + code
|
|
fs.writeFileSync("lib/index.coffee", code)
|
|
|
|
exec "node_modules/coffeescript/bin/coffee --compile --map --no-header lib/index.coffee", (err, stdout, stderr) ->
|
|
if err
|
|
util.log err
|
|
process.exit 1 # abort npm packaging
|
|
fs.unlink("lib/index.coffee", () -> )
|
|
util.log "Compiled CoffeeScript."
|
|
|
|
task 'build', 'Compile and minify all CoffeeScript files', ->
|
|
invoke 'compile'
|
|
exec 'closure-compiler --compilation_level ECMASCRIPT5 --compilation_level SIMPLE --create_source_map=lib/index.min.js.map --js_output_file lib/index.min.js lib/index.js', (err) ->
|
|
if err
|
|
util.log err
|
|
process.exit 1 # abort npm packaging
|
|
fs.appendFileSync('lib/index.min.js', "\n//# sourceMappingURL=index.min.js.map")
|
|
util.log "Minified JavaScript."
|