|
|
|
|
@ -3,23 +3,45 @@ |
|
|
|
|
const path = require('path'); |
|
|
|
|
const fs = require('fs'); |
|
|
|
|
const extend = require('util')._extend; |
|
|
|
|
const { exec } = require('child_process'); |
|
|
|
|
const { spawn } = require('child_process'); |
|
|
|
|
const net = require('net'); |
|
|
|
|
const processes = []; |
|
|
|
|
let exitCode; |
|
|
|
|
|
|
|
|
|
const baseDir = path.resolve(__dirname, '..'); |
|
|
|
|
const srcDir = path.resolve(baseDir); |
|
|
|
|
|
|
|
|
|
const isPortTaken = (port) => new Promise((resolve, reject) => { |
|
|
|
|
const tester = net.createServer() |
|
|
|
|
.once('error', (err) => (err.code === 'EADDRINUSE' ? resolve(true) : reject(err))) |
|
|
|
|
.once('listening', () => tester.once('close', () => resolve(false)).close()) |
|
|
|
|
.listen(port); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const waitPortRelease = (port) => new Promise((resolve, reject) => { |
|
|
|
|
isPortTaken(port).then((taken) => { |
|
|
|
|
if (!taken) { |
|
|
|
|
return resolve(); |
|
|
|
|
} |
|
|
|
|
setTimeout(() => { |
|
|
|
|
waitPortRelease(port).then(resolve).catch(reject); |
|
|
|
|
}, 1000); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const appOptions = { |
|
|
|
|
env: { |
|
|
|
|
PORT: 3000, |
|
|
|
|
ROOT_URL: 'http://localhost:3000', |
|
|
|
|
// MONGO_URL: 'mongodb://localhost:27017/test',
|
|
|
|
|
// MONGO_OPLOG_URL: 'mongodb://localhost:27017/local',
|
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
function startProcess(opts, callback) { |
|
|
|
|
const proc = exec( |
|
|
|
|
const proc = spawn( |
|
|
|
|
opts.command, |
|
|
|
|
opts.params, |
|
|
|
|
opts.options |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
@ -57,7 +79,14 @@ function startProcess(opts, callback) { |
|
|
|
|
processes.forEach((p) => p.kill()); |
|
|
|
|
|
|
|
|
|
if (processes.length === 0) { |
|
|
|
|
process.exit(exitCode); |
|
|
|
|
waitPortRelease(appOptions.env.PORT).then(() => { |
|
|
|
|
console.log(`Port ${ appOptions.env.PORT } was released, exiting with code ${ exitCode }`); |
|
|
|
|
process.exit(exitCode); |
|
|
|
|
}).catch((error) => { |
|
|
|
|
console.error(`Error waiting port ${ appOptions.env.PORT } to be released, exiting with code ${ exitCode }`); |
|
|
|
|
console.error(error); |
|
|
|
|
process.exit(exitCode); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
processes.push(proc); |
|
|
|
|
@ -66,7 +95,10 @@ function startProcess(opts, callback) { |
|
|
|
|
function startApp(callback) { |
|
|
|
|
startProcess({ |
|
|
|
|
name: 'Meteor App', |
|
|
|
|
command: 'node /tmp/build-test/bundle/main.js', |
|
|
|
|
command: 'node', |
|
|
|
|
params: ['/tmp/build-test/bundle/main.js'], |
|
|
|
|
// command: 'node',
|
|
|
|
|
// params: ['.meteor/local/build/main.js'],
|
|
|
|
|
waitForMessage: appOptions.waitForMessage, |
|
|
|
|
options: { |
|
|
|
|
cwd: srcDir, |
|
|
|
|
@ -78,7 +110,10 @@ function startApp(callback) { |
|
|
|
|
function startChimp() { |
|
|
|
|
startProcess({ |
|
|
|
|
name: 'Chimp', |
|
|
|
|
command: 'npm run chimp-test', |
|
|
|
|
command: 'npm', |
|
|
|
|
params: ['run', 'chimp-test'], |
|
|
|
|
// command: 'exit',
|
|
|
|
|
// params: ['2'],
|
|
|
|
|
options: { |
|
|
|
|
env: Object.assign({}, process.env, { |
|
|
|
|
NODE_PATH: `${ process.env.NODE_PATH + |
|
|
|
|
|