Separate build per use

This commit is contained in:
Arlo Breault 2019-05-08 16:46:51 -04:00
parent 2d8a1690ba
commit 4d40f17487
6 changed files with 94 additions and 25 deletions

View file

@ -3,41 +3,49 @@ fs = require 'fs'
# All coffeescript files required. # All coffeescript files required.
FILES = [ FILES = [
'shims.coffee'
'util.coffee'
'init.coffee'
'proxypair.coffee'
'websocket.coffee'
'broker.coffee' 'broker.coffee'
'ui.coffee'
'snowflake.coffee'
'config.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 = [ FILES_SPEC = [
'spec/util.spec.coffee'
'spec/ui.spec.coffee'
'spec/broker.spec.coffee' 'spec/broker.spec.coffee'
'spec/init.spec.coffee'
'spec/proxypair.spec.coffee' 'spec/proxypair.spec.coffee'
'spec/snowflake.spec.coffee' 'spec/snowflake.spec.coffee'
'spec/ui.spec.coffee'
'spec/util.spec.coffee'
'spec/websocket.spec.coffee' 'spec/websocket.spec.coffee'
'spec/init.spec.coffee'
] ]
FILES_ALL = FILES.concat FILES_SPEC
OUTFILE = 'snowflake.js' OUTFILE = 'snowflake.js'
STATIC = 'static' STATIC = 'static'
copyStaticFiles = -> copyStaticFiles = ->
exec 'cp ' + STATIC + '/* build/' exec 'cp ' + STATIC + '/* build/'
compileCoffee = (outDir) -> compileCoffee = (outDir, init) ->
exec 'cat ' + FILES.join(' ') + ' | coffee -cs > ' + outDir + '/' + OUTFILE, (err, stdout, stderr) -> files = FILES.concat('init-' + init + '.coffee')
exec 'cat ' + files.join(' ') + ' | coffee -cs > ' + outDir + '/' + OUTFILE, (err, stdout, stderr) ->
throw err if err throw err if err
task 'test', 'snowflake unit tests', -> task 'test', 'snowflake unit tests', ->
exec 'mkdir -p test' exec 'mkdir -p test'
exec 'jasmine init >&-' exec 'jasmine init >&-'
# Simply concat all the files because we're not using node exports. # Simply concat all the files because we're not using node exports.
jasmineFiles = FILES_ALL jasmineFiles = FILES.concat('init-badge.coffee', FILES_SPEC)
outFile = 'test/bundle.spec.coffee' outFile = 'test/bundle.spec.coffee'
exec 'echo "TESTING = true" > ' + outFile exec 'echo "TESTING = true" > ' + outFile
exec 'cat ' + jasmineFiles.join(' ') + ' | cat >> ' + outFile exec 'cat ' + jasmineFiles.join(' ') + ' | cat >> ' + outFile
@ -50,15 +58,22 @@ task 'test', 'snowflake unit tests', ->
task 'build', 'build the snowflake proxy', -> task 'build', 'build the snowflake proxy', ->
exec 'mkdir -p build' exec 'mkdir -p build'
copyStaticFiles() copyStaticFiles()
compileCoffee('build') compileCoffee('build', 'badge')
console.log 'Snowflake prepared.' console.log 'Snowflake prepared.'
task 'webext', 'build the webextension', -> task 'webext', 'build the webextension', ->
compileCoffee('webext') exec 'mkdir -p webext'
compileCoffee('webext', 'webext')
console.log 'Webextension prepared.' 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', -> task 'lint', 'ensure idiomatic coffeescript', ->
proc = spawn 'coffeelint', FILES_ALL, { filesAll = FILES.concat(INITS, FILES_SPEC)
proc = spawn 'coffeelint', filesAll, {
file: 'coffeelint.json' file: 'coffeelint.json'
stdio: 'inherit' stdio: 'inherit'
} }

View file

@ -1,3 +1,6 @@
###
Entry point.
###
snowflake = null snowflake = null
@ -14,9 +17,6 @@ log = (msg) ->
dbg = (msg) -> log msg if debug or (snowflake?.ui instanceof DebugUI) dbg = (msg) -> log msg if debug or (snowflake?.ui instanceof DebugUI)
###
Entry point.
###
init = () -> init = () ->
config = new Config config = new Config
@ -28,8 +28,6 @@ init = () ->
ui = new BadgeUI() ui = new BadgeUI()
else if (document.getElementById('status') != null) else if (document.getElementById('status') != null)
ui = new DebugUI() ui = new DebugUI()
else if (document.getElementById('webext') != null)
ui = new WebExtUI()
else else
ui = new UI() ui = new UI()

19
proxy/init-node.coffee Normal file
View file

@ -0,0 +1,19 @@
###
Entry point.
###
config = new Config
ui = new UI()
broker = new Broker config.brokerUrl
snowflake = new Snowflake config, ui, broker
log = (msg) ->
console.log 'Snowflake: ' + msg
dbg = log
log '== snowflake proxy =='
dbg 'Contacting Broker at ' + broker.url
snowflake.setRelayAddr config.relayAddr
snowflake.beginWebRTC()

39
proxy/init-webext.coffee Normal file
View file

@ -0,0 +1,39 @@
###
Entry point.
###
debug = false
snowflake = null
# Log to both console and UI if applicable.
# Requires that the snowflake and UI objects are hooked up in order to
# log to console.
log = (msg) ->
console.log 'Snowflake: ' + msg
snowflake?.ui.log msg
dbg = (msg) -> log msg if debug
init = () ->
config = new Config
ui = new WebExtUI()
broker = new Broker config.brokerUrl
snowflake = new Snowflake config, ui, broker
log '== snowflake proxy =='
# Otherwise, begin setting up WebRTC and acting as a proxy.
dbg 'Contacting Broker at ' + broker.url
snowflake.setRelayAddr config.relayAddr
snowflake.beginWebRTC()
# Notification of closing tab with active proxy.
window.onbeforeunload = ->
if !silenceNotifications && Snowflake.MODE.WEBRTC_READY == snowflake.state
return Snowflake.MESSAGE.CONFIRMATION
null
window.onunload = ->
pair.close() for pair in snowflake.proxyPairs
null
window.onload = init

View file

@ -12,7 +12,7 @@
"build": "cake build", "build": "cake build",
"webext": "cake webext", "webext": "cake webext",
"clean": "cake clean", "clean": "cake clean",
"prepublish": "npm run build", "prepublish": "cake node",
"start": "node build/snowflake.js" "start": "node build/snowflake.js"
}, },
"bin": { "bin": {

View file

@ -19,8 +19,6 @@ if module?.exports
WebSocket = require 'ws' WebSocket = require 'ws'
{ XMLHttpRequest } = require 'xmlhttprequest' { XMLHttpRequest } = require 'xmlhttprequest'
process.nextTick () -> init
else else
window = this window = this
document = window.document document = window.document