Merge pull request #134 from mafintosh/allow-onPort-to-be-a-fn

allow onPort to be a function
This commit is contained in:
David Mark Clements 2018-07-17 15:49:20 +02:00 committed by GitHub
commit 0d3089b032
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 2 deletions

View File

@ -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) => {

View File

@ -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(

View File

@ -137,4 +137,4 @@ function collectInliningInfo (sp) {
cb()
}))
return inlined
}
}