forked from atom/atom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask-bootstrap.coffee
54 lines (47 loc) · 1.38 KB
/
task-bootstrap.coffee
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
{userAgent, taskPath} = process.env
handler = null
setupGlobals = ->
global.attachEvent = ->
console =
warn: -> emit 'task:warn', arguments...
log: -> emit 'task:log', arguments...
error: -> emit 'task:error', arguments...
trace: ->
global.__defineGetter__ 'console', -> console
global.document =
createElement: ->
setAttribute: ->
getElementsByTagName: -> []
appendChild: ->
documentElement:
insertBefore: ->
removeChild: ->
getElementById: -> {}
createComment: -> {}
createDocumentFragment: -> {}
global.emit = (event, args...) ->
process.send({event, args})
global.navigator = {userAgent}
global.window = global
handleEvents = ->
process.on 'uncaughtException', (error) ->
console.error(error.message, error.stack)
process.on 'message', ({event, args}={}) ->
return unless event is 'start'
isAsync = false
async = ->
isAsync = true
(result) ->
emit('task:completed', result)
result = handler.bind({async})(args...)
emit('task:completed', result) unless isAsync
setupDeprecations = ->
Grim = require 'grim'
Grim.on 'updated', ->
deprecations = Grim.getDeprecations().map (deprecation) -> deprecation.serialize()
Grim.clearDeprecations()
emit('task:deprecations', deprecations)
setupGlobals()
handleEvents()
setupDeprecations()
handler = require(taskPath)