UNPKG

1.26 kBPlain TextView Raw
1fs = require 'fs-jetpack'
2Promise = require 'bluebird'
3promiseBreak = require 'promise-break'
4Coffeescript = require 'coffee-script'
5md5 = require 'md5'
6path = require 'path'
7CACHE_DIR = path.resolve '.config','buildcache'
8
9process.exit(0) if process.env.CI
10fs.dir(CACHE_DIR)
11
12compileCoffee = (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
29task '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
36task 'build:lib', ()->
37 compileCoffee 'src/index.coffee', 'lib/index.js'
38
39
40task 'build:test', ()->
41 compileCoffee 'test/test.coffee', 'test/test.js'
42
43
44task 'build:benchmark', ()->
45 compileCoffee 'benchmarks/runner.coffee', 'benchmarks/runner.js'
46