xen-orchestra/scripts/run-script
2018-02-09 17:56:03 +01:00

52 lines
1.4 KiB
JavaScript
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env node
const { delimiter } = require('path')
const { forEach, fromEvent } = require('promise-toolbox')
const { spawn } = require('child_process')
const { getPackages } = require('./utils')
const { env } = process
// run a script for each package (also run pre and post)
//
// TODO: https://docs.npmjs.com/misc/scripts#environment
require('exec-promise')(args => {
const parallel = args[0] === '--parallel'
const script = args[parallel ? 1 : 0]
let errors = 0
return getPackages(true)
[parallel ? 'map' : 'forEach'](({ dir, name, package: { scripts } }) => {
if (scripts == null) {
return
}
const spawnOpts = {
cwd: dir,
env: Object.assign({}, env, {
PATH: `${dir}/node_modules/.bin${delimiter}${env.PATH}`,
}),
shell: true,
stdio: 'inherit',
}
return forEach.call([`pre${script}`, script, `post${script}`], script => {
const command = scripts[script]
if (command !== undefined) {
console.log(`* ${name}:${script} `, command)
return fromEvent(spawn(command, spawnOpts), 'exit').then(code => {
if (code !== 0) {
++errors
console.log(`* ${name}:${script} Error:`, code)
}
})
}
})
})
.then(() => {
if (errors !== 0) {
throw errors
}
})
})