snowflake/proxy/Cakefile
2019-05-16 12:07:06 -04:00

83 lines
2.1 KiB
CoffeeScript

fs = require 'fs'
{ exec, spawn, execSync } = require 'child_process'
# All coffeescript files required.
FILES = [
'broker.coffee'
'config.coffee'
'proxypair.coffee'
'snowflake.coffee'
'ui.coffee'
'util.coffee'
'websocket.coffee'
'shims.coffee'
]
INITS = [
'init-badge.coffee'
'init-node.coffee'
'init-webext.coffee'
]
FILES_SPEC = [
'spec/broker.spec.coffee'
'spec/init.spec.coffee'
'spec/proxypair.spec.coffee'
'spec/snowflake.spec.coffee'
'spec/ui.spec.coffee'
'spec/util.spec.coffee'
'spec/websocket.spec.coffee'
]
OUTFILE = 'snowflake.js'
STATIC = 'static'
copyStaticFiles = ->
exec 'cp ' + STATIC + '/* build/'
compileCoffee = (outDir, init) ->
files = FILES.concat('init-' + init + '.coffee')
exec 'cat ' + files.join(' ') + ' | coffee -cs > ' + outDir + '/' + OUTFILE, (err, stdout, stderr) ->
throw err if err
task 'test', 'snowflake unit tests', ->
exec 'mkdir -p test'
exec 'jasmine init >&-'
# Simply concat all the files because we're not using node exports.
jasmineFiles = FILES.concat('init-badge.coffee', FILES_SPEC)
outFile = 'test/bundle.spec.coffee'
exec 'echo "TESTING = true" > ' + outFile
exec 'cat ' + jasmineFiles.join(' ') + ' | cat >> ' + outFile
execSync 'coffee -cb ' + outFile
proc = spawn 'jasmine', ['test/bundle.spec.js'], {
stdio: 'inherit'
}
proc.on "exit", (code) -> process.exit code
task 'build', 'build the snowflake proxy', ->
exec 'mkdir -p build'
copyStaticFiles()
compileCoffee('build', 'badge')
console.log 'Snowflake prepared.'
task 'webext', 'build the webextension', ->
exec 'mkdir -p webext'
compileCoffee('webext', 'webext')
console.log 'Webextension prepared.'
task 'node', 'build the node binary', ->
exec 'mkdir -p build'
compileCoffee('build', 'node')
console.log 'Node prepared.'
task 'lint', 'ensure idiomatic coffeescript', ->
filesAll = FILES.concat(INITS, FILES_SPEC)
proc = spawn 'coffeelint', filesAll, {
file: 'coffeelint.json'
stdio: 'inherit'
}
proc.on "exit", (code) -> process.exit code
task 'clean', 'remove all built files', ->
exec 'rm -r build'