(- fix api) Patch Tput's handling of columns
[Paws.js.git] / Cakefile
blob2f560c699e4e3182611015ffd819879c8650747d
1 _       = require 'lodash'
3 # Configuration vars.
4 option '-w', '--watch',          '(test, compile:client) watch files for changes, and recompile results'
5 option '-W', '--wait',           '(*:open) open browser and wait'
6 option '-g', '--grep [PATTERN]', '(test) see `mocha --help`'
7 option '-i', '--invert',         '(test) see `mocha --help`'
8 option '-r', '--reporter [REP]', '(test) specify Mocha reporter to display test results'
9 option '-t', '--tests',          '(compile:client) include tests in the bundle'
10 option '-a', '--browser [BROW]', '(*:open) select browser to use'
12 config =
13    dirs:
14       source:     'Source'
15       tests:      'Test'
16       docs:       'Documentation'
17       products:   'Library'
18    mocha:
19       reporter:   'spec'
20       ui:         'bdd'
21       env:        'test'
22    docco:
23       browser:    'Google Chrome' # Browser to open HTML documentation in
24    
25    package:    require './package.json'
27 open_wait_task = (opts, path) ->
28    browser = spawn 'open',
29       _.compact [ path, '-a', opts.browser ? config.docco.browser, (if opts.wait then '-W') ]
30    
31    if opts.wait
32       browser.on 'exit', -> invoke 'clean'
35 # I try to use standard `make`-target names for these tasks.
36 # See: http://www.gnu.org/software/make/manual/make.html#Standard-Targets
37 {spawn, exec}  = require 'child_process'
38 path           = require 'path'
39 task 'test', 'run testsuite through Mocha', (options) ->
40    env = Object.create process.env,
41       NODE_ENV: { value: config.mocha.env }
42    
43    child = spawn path.resolve('./node_modules/.bin/mocha'),
44       _.compact [ '--grep', (options.grep or '.'), (if options.invert then '--invert')
45                   '--watch' if options.watch
46                   '--compilers', 'coffee:coffee-script'
47                   '--reporter',   options.reporter or config.mocha.reporter
48                   '--ui',         config.mocha.ui
49                   path.resolve config.dirs.tests ]
50       stdio: 'inherit'
51       cwd: path.resolve config.dirs.tests
52       env: env
53    child.on 'exit', (code) -> process.on('exit', -> process.exit code) if code > 0
55 task 'test:client', (options) ->
56    options.tests = true
57    invoke 'compile:client'
58    invoke 'test:client:open'
60 task 'test:client:open', (options) ->
61    open_wait_task options, path.join(config.dirs.products, 'tests.html')
63 task 'travis', ->
64    exec 'npm run-script coveralls', (error) ->
65       process.exit 1 if error
66       invoke 'test'
67       
69 { document: docco } = require 'docco'
70 task 'docs', 'generate HTML documentation via Docco', (options) ->
71    docco [path.join config.dirs.source, '*'], { output: config.dirs.docs }, ->
72       invoke 'docs:open' if options.wait
73 task 'docs:open', (options) ->
74    open_wait_task options, path.join(config.dirs.docs, 'Paws.html')
77 #task 'compile', "write out JavaScript to lib/", -> # NYI
79 browserify = require 'browserify'
80 coffeeify  = require 'coffeeify'
81 glob       = require 'glob'
82 fs         = require 'fs'
83 task 'compile:client', "bundle JavaScript through Browserify", (options) ->
84    bundle = browserify()
85      #watch: options.watch # FIXME: Lost in 1.0 -> 2.0
86      #cache: true # FIXME: Lost in 1.0 -> 2.0
87      #exports: ['require', 'process'] # FIXME: Lost in 1.0 -> 2.0
88    bundle.transform coffeeify
89    
90    bundle.ignore 'vm'
91    
92    bundle.add path.resolve process.cwd(), config.dirs.source, 'Paws.coffee'
93    if options.tests
94       bundle.add path.resolve process.cwd(), file for file in glob.sync config.package.testling.files
95    
96    bundle.bundle(debug: yes).pipe fs.createWriteStream(
97       config.package.main.replace(/(?=\.(?:js|coffee))|$/, '.bundle') )
100 task 'clean', "remove git-ignore'd build products", ->
101    exec 'npm run-script clean', (error) ->
102       process.exit 1 if error
104 task 'html',  -> invoke 'docs'
105 #task 'build', -> invoke 'compile'