1 | fs = require 'fs-jetpack'
|
2 | Promise = require 'bluebird'
|
3 | promiseBreak = require 'promise-break'
|
4 | Coffeescript = require 'coffee-script'
|
5 | md5 = require 'md5'
|
6 | path = require 'path'
|
7 | CACHE_DIR = path.resolve '.config','buildcache'
|
8 |
|
9 | process.exit(0) if process.env.CI
|
10 | fs.dir(CACHE_DIR)
|
11 |
|
12 | compileCoffee = (srcFile, destFile)->
|
13 | Promise.resolve()
|
14 | .then ()-> fs.readAsync(srcFile)
|
15 | .then (src)->
|
16 | srcHash = md5(src)
|
17 | cacheDest = path.join(CACHE_DIR, "#{srcHash}.js")
|
18 |
|
19 | Promise.resolve()
|
20 | .then ()-> fs.existsAsync(cacheDest)
|
21 | .then (cacheExists)-> promiseBreak() if cacheExists
|
22 | .then ()-> console.log "Building #{srcFile}"
|
23 | .then ()-> Coffeescript.compile src, {bare:true}
|
24 | .then (output)-> fs.writeAsync cacheDest, output
|
25 | .catch promiseBreak.end
|
26 | .then ()-> fs.copyAsync cacheDest, destFile, overwrite:true
|
27 |
|
28 |
|
29 | task 'build', 'compile lib, test, and benchmark files', ()->
|
30 | Promise.resolve()
|
31 | .then ()-> invoke 'build:lib'
|
32 | .then ()-> invoke 'build:test'
|
33 | .then ()-> invoke 'build:benchmark'
|
34 |
|
35 |
|
36 | task 'build:lib', ()->
|
37 | compileCoffee 'src/index.coffee', 'lib/index.js'
|
38 |
|
39 |
|
40 | task 'build:test', ()->
|
41 | compileCoffee 'test/test.coffee', 'test/test.js'
|
42 |
|
43 |
|
44 | task 'build:benchmark', ()->
|
45 | compileCoffee 'benchmarks/runner.coffee', 'benchmarks/runner.js'
|
46 |
|