mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
Separate build per use
This commit is contained in:
parent
2d8a1690ba
commit
4d40f17487
6 changed files with 94 additions and 25 deletions
|
@ -3,41 +3,49 @@ fs = require 'fs'
|
|||
|
||||
# All coffeescript files required.
|
||||
FILES = [
|
||||
'shims.coffee'
|
||||
'util.coffee'
|
||||
'init.coffee'
|
||||
'proxypair.coffee'
|
||||
'websocket.coffee'
|
||||
'broker.coffee'
|
||||
'ui.coffee'
|
||||
'snowflake.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/util.spec.coffee'
|
||||
'spec/ui.spec.coffee'
|
||||
'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'
|
||||
'spec/init.spec.coffee'
|
||||
]
|
||||
FILES_ALL = FILES.concat FILES_SPEC
|
||||
|
||||
OUTFILE = 'snowflake.js'
|
||||
STATIC = 'static'
|
||||
|
||||
copyStaticFiles = ->
|
||||
exec 'cp ' + STATIC + '/* build/'
|
||||
|
||||
compileCoffee = (outDir) ->
|
||||
exec 'cat ' + FILES.join(' ') + ' | coffee -cs > ' + outDir + '/' + OUTFILE, (err, stdout, stderr) ->
|
||||
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_ALL
|
||||
jasmineFiles = FILES.concat('init-badge.coffee', FILES_SPEC)
|
||||
outFile = 'test/bundle.spec.coffee'
|
||||
exec 'echo "TESTING = true" > ' + outFile
|
||||
exec 'cat ' + jasmineFiles.join(' ') + ' | cat >> ' + outFile
|
||||
|
@ -50,15 +58,22 @@ task 'test', 'snowflake unit tests', ->
|
|||
task 'build', 'build the snowflake proxy', ->
|
||||
exec 'mkdir -p build'
|
||||
copyStaticFiles()
|
||||
compileCoffee('build')
|
||||
compileCoffee('build', 'badge')
|
||||
console.log 'Snowflake prepared.'
|
||||
|
||||
task 'webext', 'build the webextension', ->
|
||||
compileCoffee('webext')
|
||||
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', ->
|
||||
proc = spawn 'coffeelint', FILES_ALL, {
|
||||
filesAll = FILES.concat(INITS, FILES_SPEC)
|
||||
proc = spawn 'coffeelint', filesAll, {
|
||||
file: 'coffeelint.json'
|
||||
stdio: 'inherit'
|
||||
}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
###
|
||||
Entry point.
|
||||
###
|
||||
|
||||
snowflake = null
|
||||
|
||||
|
@ -14,9 +17,6 @@ log = (msg) ->
|
|||
|
||||
dbg = (msg) -> log msg if debug or (snowflake?.ui instanceof DebugUI)
|
||||
|
||||
###
|
||||
Entry point.
|
||||
###
|
||||
init = () ->
|
||||
config = new Config
|
||||
|
||||
|
@ -28,8 +28,6 @@ init = () ->
|
|||
ui = new BadgeUI()
|
||||
else if (document.getElementById('status') != null)
|
||||
ui = new DebugUI()
|
||||
else if (document.getElementById('webext') != null)
|
||||
ui = new WebExtUI()
|
||||
else
|
||||
ui = new UI()
|
||||
|
19
proxy/init-node.coffee
Normal file
19
proxy/init-node.coffee
Normal 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
39
proxy/init-webext.coffee
Normal 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
|
|
@ -12,7 +12,7 @@
|
|||
"build": "cake build",
|
||||
"webext": "cake webext",
|
||||
"clean": "cake clean",
|
||||
"prepublish": "npm run build",
|
||||
"prepublish": "cake node",
|
||||
"start": "node build/snowflake.js"
|
||||
},
|
||||
"bin": {
|
||||
|
|
|
@ -19,8 +19,6 @@ if module?.exports
|
|||
WebSocket = require 'ws'
|
||||
{ XMLHttpRequest } = require 'xmlhttprequest'
|
||||
|
||||
process.nextTick () -> init
|
||||
|
||||
else
|
||||
window = this
|
||||
document = window.document
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue