mirror of
https://github.com/davidmarkclements/0x.git
synced 2026-01-25 14:47:55 +00:00
Merge pull request #134 from mafintosh/allow-onPort-to-be-a-fn
allow onPort to be a function
This commit is contained in:
commit
0d3089b032
@ -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) => {
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -137,4 +137,4 @@ function collectInliningInfo (sp) {
|
||||
cb()
|
||||
}))
|
||||
return inlined
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user