2017-04-19 21:15:28 +02:00
|
|
|
'use strict';
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2017-04-19 21:15:28 +02:00
|
|
|
const fork = require('child_process').fork;
|
|
|
|
const express = require('express');
|
|
|
|
const rimraf = require('rimraf');
|
|
|
|
const Server = require('./server');
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2017-04-19 21:15:28 +02:00
|
|
|
const forks = process.forks = [];
|
|
|
|
process.server = Server('http://localhost:55551/');
|
|
|
|
process.server2 = Server('http://localhost:55552/');
|
2017-03-04 00:39:26 +01:00
|
|
|
process.server3 = Server('http://localhost:55553/');
|
2017-04-19 21:15:28 +02:00
|
|
|
process.express = express();
|
|
|
|
process.express.listen(55550);
|
2014-07-22 20:24:19 +02:00
|
|
|
|
2017-04-19 21:15:28 +02:00
|
|
|
module.exports.start = function(dir, conf) {
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
rimraf(__dirname + '/../' + dir, function() {
|
|
|
|
// filter out --debug-brk
|
|
|
|
let oldArgv = process.execArgv;
|
|
|
|
process.execArgv = process.execArgv.filter(function(x) {
|
|
|
|
return x !== '--debug-brk';
|
|
|
|
});
|
|
|
|
|
|
|
|
const f = fork(__dirname + '/../../../bin/verdaccio'
|
|
|
|
, ['-c', __dirname + '/../' + conf]
|
|
|
|
, {silent: !process.env.TRAVIS}
|
|
|
|
);
|
|
|
|
forks.push(f);
|
|
|
|
f.on('message', function(msg) {
|
|
|
|
if ('verdaccio_started' in msg) {
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
f.on('error', function(err) {
|
|
|
|
reject(err);
|
|
|
|
});
|
|
|
|
process.execArgv = oldArgv;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2013-12-19 16:11:54 +01:00
|
|
|
|
|
|
|
process.on('exit', function() {
|
2017-03-04 00:39:26 +01:00
|
|
|
if (forks[0]) {
|
|
|
|
forks[0].kill();
|
|
|
|
}
|
|
|
|
if (forks[1]) {
|
|
|
|
forks[1].kill();
|
|
|
|
}
|
|
|
|
if (forks[2]) {
|
|
|
|
forks[2].kill();
|
|
|
|
}
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|