-
Notifications
You must be signed in to change notification settings - Fork 18
/
start-server.js
64 lines (51 loc) · 1.42 KB
/
start-server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'use strict';
const debug = require('../utilities/debug');
const runEmber = require('../utilities/run-ember');
const defaults = require('lodash/defaults');
const temp = require('../utilities/temp');
module.exports = function runServer(options) {
return new Promise((resolve, reject) => {
options = options || { };
defaults(options, {
port: '49741',
command: 'server',
detectServerStart
});
let args = [
'--port', options.port
];
if (options.additionalArguments) {
args = args.concat(options.additionalArguments);
}
let longRunningServerPromise;
let commandOptions = {
verbose: true,
onOutput(output, child) {
if (options.detectServerStart(output)) {
resolve({
server: child,
longRunningServerPromise
});
}
}
};
args.push(commandOptions);
debug('starting server; command=%s; port=%s', options.command, options.port);
longRunningServerPromise = runEmber(options.command, args, temp.pristineNodeModulesPath)
.then(() => {
throw new Error('The server should not have exited successfully.');
})
.catch(reject);
});
};
function detectServerStart(output) {
let indicators = [
'Ember FastBoot running at',
'Build successful'
];
for (let indicator of indicators) {
if (output.indexOf(indicator) > -1) {
return true;
}
}
}