2016-09-09 13:18:53 +03:00
|
|
|
fs = require 'fs'
|
|
|
|
{exec,spawn} = require 'child_process'
|
|
|
|
util = require 'util'
|
|
|
|
sources = [
|
|
|
|
'markdown.coffee'
|
|
|
|
'view.coffee'
|
|
|
|
'unit.coffee'
|
|
|
|
'character.coffee'
|
|
|
|
'room.coffee'
|
|
|
|
'localize.coffee'
|
2016-09-10 04:44:27 +03:00
|
|
|
'random.coffee'
|
2016-09-09 13:18:53 +03:00
|
|
|
'salet.coffee'
|
|
|
|
]
|
|
|
|
sourcestring = ""
|
|
|
|
for source in sources
|
|
|
|
sourcestring += 'src/'+source+' '
|
|
|
|
|
|
|
|
task 'watch', 'Watch source files and build changes', ->
|
|
|
|
watch = spawn "coffee", ['-c', '-w', '--no-header', '-j', 'lib/index.js', sourcestring]
|
|
|
|
watch.stdout.on 'data', (data) -> console.log data.toString().trim()
|
|
|
|
|
|
|
|
task 'build', 'Compile all CoffeeScript files', ->
|
|
|
|
# prepare lib directory
|
|
|
|
if not fs.existsSync 'lib'
|
|
|
|
fs.mkdirSync 'lib'
|
|
|
|
|
|
|
|
# run coffee-script compile
|
2016-09-10 04:44:27 +03:00
|
|
|
exec "cat #{sourcestring} | coffee --compile --stdio --no-header > lib/index.js", (err, stdout, stderr) ->
|
2016-09-09 13:18:53 +03:00
|
|
|
if err
|
|
|
|
util.log err
|
|
|
|
process.exit 1 # abort npm packaging
|
|
|
|
util.log "Compiled CoffeeScript."
|
2016-09-12 08:23:18 +03:00
|
|
|
exec "closure-compiler --js_output_file lib/index.min.js lib/index.js", (err) ->
|
|
|
|
if err
|
|
|
|
util.log err
|
|
|
|
process.exit 1 # abort npm packaging
|
|
|
|
util.log "Minified JavaScript."
|