Skip to content

Commit d8d3038

Browse files
committed
use rungulp worker
1 parent f06ef4b commit d8d3038

File tree

3 files changed

+87
-9
lines changed

3 files changed

+87
-9
lines changed

app/asset/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
"height": 0
1111
},
1212
"dependencies": {
13-
"gulp": "~3.5.2"
13+
"gulp": "~3.5.2",
14+
"pretty-hrtime": "~0.2.0",
15+
"semver": "~2.2.1",
16+
"liftoff": "~0.8.4",
17+
"gulp-util": "~2.2.14"
1418
}
1519
}

app/main.ls

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,17 @@ remove-watcher = (dir) ->
2727
# XXX: cb to call on child exit
2828

2929
create-watcher = (target, dir) ->
30-
exec = require 'child_process' .execFile
31-
child = exec 'node_modules/.bin/gulp' <[--require LiveScript ]> ++ target, {cwd: dir}, (error, stdout, stderr) ->
32-
# XXX: some console feedback
33-
console.log 'stdout: ' + stdout
34-
#console.log 'stderr: ' + stderr
35-
console.log 'exec error: ' + error if error isnt null
36-
children.push child
37-
folders-info.{}[dir]child = child
30+
console.log "create #dir"
31+
spawn = require 'child_process' .spawn
32+
child = spawn 'node' ['./rungulp.js'] {stdio: ['ipc']}
33+
child.on \error ->
34+
console.log 'error' + it
35+
child.on \message ->
36+
console.log "[#dir] message " it
37+
child.on \exit ->
38+
console.log "[#dir] exit #it"
39+
child.send {target, dir}
40+
folders-info[dir] = {child}
3841

3942
gui = require 'nw.gui'
4043
win = gui.Window.get!

app/rungulp.ls

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
require! <[liftoff gulp fs]>
2+
3+
handleArguments = (args) ->
4+
argv = args.argv
5+
cliPackage = require './package'
6+
versionFlag = argv.v or argv.version
7+
tasksFlag = argv.T or argv.tasks
8+
tasks = argv._
9+
toRun = if tasks.length then tasks else ['default']
10+
if versionFlag
11+
gutil.log 'CLI version', cliPackage.version
12+
gutil.log 'Local version', args.modulePackage.version if args.localPackage
13+
process.exit 0
14+
if not args.modulePath
15+
gutil.log (gutil.colors.red 'No local gulp install found in'), gutil.colors.magenta args.cwd
16+
gutil.log gutil.colors.red 'Try running: npm install gulp'
17+
process.exit 1
18+
if not args.configPath
19+
gutil.log gutil.colors.red 'No gulpfile found'
20+
process.exit 1
21+
if semver.gt cliPackage.version, args.modulePackage.version
22+
gutil.log gutil.colors.red 'Warning: gulp version mismatch:'
23+
gutil.log gutil.colors.red 'Running gulp is', cliPackage.version
24+
gutil.log gutil.colors.red 'Local gulp (installed in gulpfile dir) is', args.modulePackage.version
25+
gulpFile = require args.configPath
26+
gutil.log 'Using gulpfile', gutil.colors.magenta args.configPath
27+
gulpInst = require args.modulePath
28+
logEvents gulpInst
29+
if process.cwd! isnt args.cwd
30+
process.chdir args.cwd
31+
gutil.log 'Working directory changed to', gutil.colors.magenta args.cwd
32+
process.nextTick (->
33+
return logTasks gulpFile, gulpInst if tasksFlag
34+
gulpInst.start.apply gulpInst, toRun)
35+
36+
logTasks = (gulpFile, localGulp) ->
37+
tree = taskTree localGulp.tasks
38+
tree.label = 'Tasks for ' + gutil.colors.magenta gulpFile
39+
40+
formatError = (e) ->
41+
return e.message if not e.err
42+
if e.err.message then return e.err.message
43+
JSON.stringify e.err
44+
45+
logEvents = (gulpInst) ->
46+
gulpInst.on 'task_start', (e) ->
47+
process.send {running: e.task}
48+
gutil.log 'Running', '\'' + gutil.colors.cyan e.task + '\'...'
49+
gulpInst.on 'task_stop', (e) ->
50+
time = prettyTime e.hrDuration
51+
gutil.log 'Finished', '\'' + gutil.colors.cyan e.task + '\'', 'in', gutil.colors.magenta time
52+
gulpInst.on 'task_err', (e) ->
53+
msg = formatError e
54+
time = prettyTime e.hrDuration
55+
gutil.log 'Errored', '\'' + gutil.colors.cyan e.task + '\'', 'in', (gutil.colors.magenta time), gutil.colors.red msg
56+
gulpInst.on 'task_not_found', (err) ->
57+
gutil.log gutil.colors.red 'Task \'' + err.task + '\' was not defined in your gulpfile but you tried to run it.'
58+
gutil.log 'Please check the documentation for proper gulpfile formatting.'
59+
process.exit 1
60+
61+
gutil = require 'gulp-util'
62+
prettyTime = require 'pretty-hrtime'
63+
semver = require 'semver'
64+
cli = new liftoff name: 'gulp'
65+
66+
cli.on 'require', (name) -> gutil.log 'Requiring external module', gutil.colors.magenta name
67+
cli.on 'requireFail', (name) -> gutil.log (gutil.colors.red 'Failed to load external module'), gutil.colors.magenta name
68+
69+
try require \LiveScript
70+
process.on \message ({dir, target}) ->
71+
cli.launch (-> handleArguments @), {cwd: dir, _: [target]}

0 commit comments

Comments
 (0)