diff --git a/lib/util.js b/lib/util.js index b876960..3d5d243 100644 --- a/lib/util.js +++ b/lib/util.js @@ -18,6 +18,15 @@ function when (ee, evt) { } function spawnOnPort (cmd, port) { + if (typeof cmd === 'function') { + return new Promise((resolve, reject) => { + cmd(port, err => { + if (err) reject(err) + else resolve(0, null) + }) + }) + } + const sp = execSpawn(envString(cmd, {PORT: port + ''}), {stdio: 'inherit'}) return new Promise((resolve, reject) => { sp.on('exit', (code, signal) => { diff --git a/lib/validate.js b/lib/validate.js index a970ed9..e89b4c3 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -6,6 +6,9 @@ module.exports = (schema) => { return validate function validate (args) { + const onPortFn = typeof args.onPort === 'function' && args.onPort + if (onPortFn) delete args.onPort + const privateProps = { workingDir: {type: 'string'} } @@ -14,7 +17,10 @@ module.exports = (schema) => { properties: {...schema.properties, ...privateProps} } ) - if (valid(args)) return + if (valid(args)) { + if (onPortFn) args.onPort = onPortFn + return + } const [{keyword, dataPath, params, message}] = valid.errors if (keyword === 'type') { const flag = dataPath.substr( diff --git a/platform/v8.js b/platform/v8.js index 8896485..841bbaf 100644 --- a/platform/v8.js +++ b/platform/v8.js @@ -137,4 +137,4 @@ function collectInliningInfo (sp) { cb() })) return inlined -} \ No newline at end of file +}