-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cakefile
60 lines (49 loc) · 2.56 KB
/
Cakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
[fs, {dirname}, {spawnSync}, CoffeeScript] = ['fs', 'path', 'child_process', 'coffeescript'].map require
modules = ['util', 'atom', 'reagent', 're-frame', 'jsx-runtime']
deps = "mithril/mount,mithril/render,mithril/redraw,mithril/hyperscript"
depsRoute = "#{deps},mithril/route"
option '-o', '--outfile [FILE]', "output filename ('.min' is added automatically when minifying)"
option '-m', '--minify', "minify the bundle"
option '-s', '--source', "source index file"
option '-x', '--expose [PACKAGES]', "list of packages to expose (comma-separated)"
build = (options) ->
outfile = options.outfile or "dist/mreframe.js"
outfile = outfile.replace(/\.js$/, ".min.js") if options.minify
source = options.source or "."
console.log outfile
fs.mkdirSync dirname(outfile), recursive: on
bundler = require('browserify')().require source, expose: 'mreframe'
bundler.require "#{source}/#{s}", expose: "mreframe/#{s}" for s in (options.modules or [])
bundler.require s, expose: s for s in options.expose?.split(',') or [] when s
bundler.plugin 'tinyify' if options.minify
bundler.bundle().on('error', console.error).pipe fs.createWriteStream outfile
@
buildNodeps = (options) ->
build {source: "./src", outfile: "dist/mreframe-nodeps.js", modules, ...options}
buildStandalone = (options) ->
build {outfile: "dist/mreframe.js", modules, expose: deps, ...options}
buildRoute = (options) ->
build {outfile: "dist/mreframe-route.js", modules, expose: depsRoute, ...options}
task 'transpile', "transpile coffeescript files", ->
for dir in ['.', './src', './examples'] when fs.existsSync(dir)
for s in fs.readdirSync(dir) when s.match /\.coffee$/
src = "#{dir}/#{s}"
console.log src
code = fs.readFileSync src, 'utf-8'
fs.writeFileSync src.replace(/\.coffee$/, ".js"), CoffeeScript.compile code
@
task 'build', "build a standalone bundle", buildStandalone
task 'build:route', "build with 'mithril/route' included", buildRoute
task 'build:nodeps', "build without including mithril dependencies", buildNodeps
task 'build:all', "build all bundles (regular and minified)", ->
for f in [buildStandalone, buildNodeps, buildRoute]
f {}
f minify: on
task 'clean', "clean build/transpilation output", ->
require('rimraf').sync s for s in ["*.js", "src/*.js", "examples/*.js", "dist/"]
task 'test', "run unit tests", ->
spawnSync 'coffee', ["test/all.coffee"], stdio: 'inherit'
task 'perftest', "run performance tests", ->
for test in ['mithril', 'mreframe']
console.log "\t#{test}"
spawnSync 'node', ["performance/test-perf.#{test}.js"], stdio: 'inherit'