|
| 1 | +(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ |
| 2 | +(function (process){ |
| 3 | + |
| 4 | + |
| 5 | +'use strict'; |
| 6 | +var spawn = require('child_process').spawn; |
| 7 | + |
| 8 | +var sh, shFlag, children, args, wait, cmds, verbose, i ,len; |
| 9 | +// parsing argv |
| 10 | +cmds = []; |
| 11 | +args = process.argv.slice(2); |
| 12 | +for (i = 0, len = args.length; i < len; i++) { |
| 13 | + if (args[i][0] === '-') { |
| 14 | + switch (args[i]) { |
| 15 | + case '-w': |
| 16 | + case '--wait': |
| 17 | + wait = true; |
| 18 | + break; |
| 19 | + case '-v': |
| 20 | + case '--verbose': |
| 21 | + verbose = true; |
| 22 | + break; |
| 23 | + case '-h': |
| 24 | + case '--help': |
| 25 | + console.log('-h, --help output usage information'); |
| 26 | + console.log('-v, --verbose verbose logging') |
| 27 | + console.log('-w, --wait will not close sibling processes on error') |
| 28 | + process.exit(); |
| 29 | + break; |
| 30 | + } |
| 31 | + } else { |
| 32 | + cmds.push(args[i]); |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +// called on close of a child process |
| 37 | +function childClose (code) { |
| 38 | + var i, len; |
| 39 | + code = code ? (code.code || code) : code; |
| 40 | + if (verbose) { |
| 41 | + if (code > 0) { |
| 42 | + console.error('`' + this.cmd + '` failed with exit code ' + code); |
| 43 | + } else { |
| 44 | + console.log('`' + this.cmd + '` ended successfully'); |
| 45 | + } |
| 46 | + } |
| 47 | + if (code > 0 && !wait) close(code); |
| 48 | + status(); |
| 49 | +} |
| 50 | + |
| 51 | +function status () { |
| 52 | + if (verbose) { |
| 53 | + var i, len; |
| 54 | + console.log('\n'); |
| 55 | + console.log('### Status ###'); |
| 56 | + for (i = 0, len = children.length; i < len; i++) { |
| 57 | + if (children[i].exitCode === null) { |
| 58 | + console.log('`' + children[i].cmd + '` is still running'); |
| 59 | + } else if (children[i].exitCode > 0) { |
| 60 | + console.log('`' + children[i].cmd + '` errored'); |
| 61 | + } else { |
| 62 | + console.log('`' + children[i].cmd + '` finished'); |
| 63 | + } |
| 64 | + } |
| 65 | + console.log('\n'); |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +// closes all children and the process |
| 70 | +function close (code) { |
| 71 | + var i, len, close = 0, opened = 0; |
| 72 | + |
| 73 | + for (i = 0, len = children.length; i < len; i++) { |
| 74 | + if (!children[i].exitCode) { |
| 75 | + opened++; |
| 76 | + children[i].removeAllListeners('close'); |
| 77 | + if (process.platform === 'win32') { |
| 78 | + children[i].kill("SIGINT"); |
| 79 | + } else { |
| 80 | + spawn(sh,[shFlag,'kill -TERM -'+children[i].pid]); |
| 81 | + } |
| 82 | + if (verbose) console.log('`' + children[i].cmd + '` will now be closed'); |
| 83 | + children[i].on('close', function() { |
| 84 | + closed++; |
| 85 | + if (opened == closed) { |
| 86 | + process.exit(code); |
| 87 | + } |
| 88 | + }); |
| 89 | + } |
| 90 | + } |
| 91 | + if (opened == closed) process.exit(code); |
| 92 | + |
| 93 | +} |
| 94 | + |
| 95 | +// cross platform compatibility |
| 96 | +if (process.platform === 'win32') { |
| 97 | + sh = 'cmd'; |
| 98 | + shFlag = '/c'; |
| 99 | +} else { |
| 100 | + sh = 'sh'; |
| 101 | + shFlag = '-c'; |
| 102 | +} |
| 103 | + |
| 104 | +// start the children |
| 105 | +children = []; |
| 106 | +cmds.forEach(function (cmd) { |
| 107 | + var child = spawn(sh,[shFlag,cmd], { |
| 108 | + cwd: process.cwd, |
| 109 | + env: process.env, |
| 110 | + detached: true, |
| 111 | + stdio: ['pipe', process.stdout, process.stderr] |
| 112 | + }) |
| 113 | + .on('close', childClose); |
| 114 | + child.cmd = cmd |
| 115 | + children.push(child) |
| 116 | +}); |
| 117 | + |
| 118 | +// close all children on ctrl+c |
| 119 | +process.on('SIGINT', close) |
| 120 | + |
| 121 | +}).call(this,require('_process')) |
| 122 | +},{"_process":3,"child_process":2}],2:[function(require,module,exports){ |
| 123 | + |
| 124 | +},{}],3:[function(require,module,exports){ |
| 125 | +// shim for using process in browser |
| 126 | + |
| 127 | +var process = module.exports = {}; |
| 128 | +var queue = []; |
| 129 | +var draining = false; |
| 130 | +var currentQueue; |
| 131 | +var queueIndex = -1; |
| 132 | + |
| 133 | +function cleanUpNextTick() { |
| 134 | + draining = false; |
| 135 | + if (currentQueue.length) { |
| 136 | + queue = currentQueue.concat(queue); |
| 137 | + } else { |
| 138 | + queueIndex = -1; |
| 139 | + } |
| 140 | + if (queue.length) { |
| 141 | + drainQueue(); |
| 142 | + } |
| 143 | +} |
| 144 | + |
| 145 | +function drainQueue() { |
| 146 | + if (draining) { |
| 147 | + return; |
| 148 | + } |
| 149 | + var timeout = setTimeout(cleanUpNextTick); |
| 150 | + draining = true; |
| 151 | + |
| 152 | + var len = queue.length; |
| 153 | + while(len) { |
| 154 | + currentQueue = queue; |
| 155 | + queue = []; |
| 156 | + while (++queueIndex < len) { |
| 157 | + currentQueue[queueIndex].run(); |
| 158 | + } |
| 159 | + queueIndex = -1; |
| 160 | + len = queue.length; |
| 161 | + } |
| 162 | + currentQueue = null; |
| 163 | + draining = false; |
| 164 | + clearTimeout(timeout); |
| 165 | +} |
| 166 | + |
| 167 | +process.nextTick = function (fun) { |
| 168 | + var args = new Array(arguments.length - 1); |
| 169 | + if (arguments.length > 1) { |
| 170 | + for (var i = 1; i < arguments.length; i++) { |
| 171 | + args[i - 1] = arguments[i]; |
| 172 | + } |
| 173 | + } |
| 174 | + queue.push(new Item(fun, args)); |
| 175 | + if (queue.length === 1 && !draining) { |
| 176 | + setTimeout(drainQueue, 0); |
| 177 | + } |
| 178 | +}; |
| 179 | + |
| 180 | +// v8 likes predictible objects |
| 181 | +function Item(fun, array) { |
| 182 | + this.fun = fun; |
| 183 | + this.array = array; |
| 184 | +} |
| 185 | +Item.prototype.run = function () { |
| 186 | + this.fun.apply(null, this.array); |
| 187 | +}; |
| 188 | +process.title = 'browser'; |
| 189 | +process.browser = true; |
| 190 | +process.env = {}; |
| 191 | +process.argv = []; |
| 192 | +process.version = ''; // empty string to avoid regexp issues |
| 193 | +process.versions = {}; |
| 194 | + |
| 195 | +function noop() {} |
| 196 | + |
| 197 | +process.on = noop; |
| 198 | +process.addListener = noop; |
| 199 | +process.once = noop; |
| 200 | +process.off = noop; |
| 201 | +process.removeListener = noop; |
| 202 | +process.removeAllListeners = noop; |
| 203 | +process.emit = noop; |
| 204 | + |
| 205 | +process.binding = function (name) { |
| 206 | + throw new Error('process.binding is not supported'); |
| 207 | +}; |
| 208 | + |
| 209 | +// TODO(shtylman) |
| 210 | +process.cwd = function () { return '/' }; |
| 211 | +process.chdir = function (dir) { |
| 212 | + throw new Error('process.chdir is not supported'); |
| 213 | +}; |
| 214 | +process.umask = function() { return 0; }; |
| 215 | + |
| 216 | +},{}]},{},[1]); |
0 commit comments