Created
December 19, 2015 18:18
-
-
Save shrop/696863fd1f28ed200851 to your computer and use it in GitHub Desktop.
Starts Meteor or Meteor + Mirror then starts Chimp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var path = require('path'), | |
fs = require('fs'), | |
extend = require('util')._extend, | |
exec = require('child_process').exec; | |
var appOptions = { | |
settings: 'settings.json', | |
port: 3000, | |
env: { | |
ROOT_URL: 'http://localhost:3000/' | |
} | |
}; | |
var mirrorOptions = { | |
settings: appOptions.settings, | |
port: 3100, | |
env: { | |
MONGO_URL: 'mongodb://localhost:27017/chimp_db', | |
ROOT_URL: 'http://localhost:3100/' | |
}, | |
logFile: './chimp-mirror.log' | |
}; | |
// ************************************************* | |
// Start Meteor and Chimp (runs tests against the main app) | |
//chimpNoMirror(); | |
// Start Meteor and a Mirror and Chimp (runs tests against the mirror) | |
chimpWithMirror(); | |
// ************************************************* | |
function chimpWithMirror() { | |
appOptions.waitForMessage = 'Started MongoDB'; | |
startApp(function () { | |
startMirror(function () { | |
console.log('=> Test App running at:', mirrorOptions.env.ROOT_URL); | |
console.log('=> Log file: tail -f', path.resolve(mirrorOptions.logFile), '\n'); | |
startChimp('--watch --ddp=' + mirrorOptions.env.ROOT_URL + ' --path=tests') | |
}); | |
}); | |
} | |
function chimpNoMirror() { | |
appOptions.waitForMessage = 'App running at'; | |
startApp(function () { | |
startChimp('--watch --ddp=' + appOptions.env.ROOT_URL + ' --path=tests') | |
}); | |
} | |
function startApp(callback) { | |
startProcess({ | |
name: 'Meteor App', | |
command: 'meteor --settings ' + appOptions.settings + ' --port ' + appOptions.port, | |
waitForMessage: appOptions.waitForMessage, | |
options: { | |
env: extend(appOptions.env, process.env) | |
} | |
}, callback); | |
} | |
function startMirror(callback) { | |
startProcess({ | |
name: 'Meteor Mirror', | |
command: 'meteor --settings ' + mirrorOptions.settings + ' --port ' + mirrorOptions.port, | |
silent: true, | |
logFile: mirrorOptions.logFile, | |
waitForMessage: 'App running at', | |
options: { | |
env: extend(mirrorOptions.env, process.env) | |
} | |
}, callback); | |
} | |
function startChimp(command) { | |
startProcess({ | |
name: 'Chimp', | |
command: '../bin/chimp ' + command | |
}); | |
} | |
function startProcess(opts, callback) { | |
var proc = exec( | |
opts.command, | |
opts.options | |
); | |
if (opts.waitForMessage) { | |
proc.stdout.on('data', function waitForMessage(data) { | |
if (data.toString().match(opts.waitForMessage)) { | |
if (callback) { | |
callback(); | |
} | |
} | |
}); | |
} | |
if (!opts.silent) { | |
proc.stdout.pipe(process.stdout); | |
proc.stderr.pipe(process.stderr); | |
} | |
if (opts.logFile) { | |
var logStream = fs.createWriteStream(opts.logFile, {flags: 'a'}); | |
proc.stdout.pipe(logStream); | |
proc.stderr.pipe(logStream); | |
} | |
proc.on('close', function (code) { | |
console.log(opts.name, 'exited with code ' + code); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment