2017-04-19 21:15:28 +02:00
|
|
|
'use strict';
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2017-06-30 23:11:40 +02:00
|
|
|
const _ = require('lodash');
|
2017-04-19 21:15:28 +02:00
|
|
|
const fork = require('child_process').fork;
|
2017-07-01 11:17:46 +02:00
|
|
|
const bodyParser = require('body-parser');
|
2017-04-19 21:15:28 +02:00
|
|
|
const express = require('express');
|
2017-06-28 22:47:16 +02:00
|
|
|
const rimRaf = require('rimraf');
|
2017-07-02 00:05:58 +02:00
|
|
|
const path = require('path');
|
2017-04-19 21:15:28 +02:00
|
|
|
const Server = require('./server');
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2017-04-19 21:15:28 +02:00
|
|
|
const forks = process.forks = [];
|
2017-06-28 22:47:16 +02:00
|
|
|
process.server = new Server('http://localhost:55551/');
|
|
|
|
process.server2 = new Server('http://localhost:55552/');
|
|
|
|
process.server3 = new Server('http://localhost:55553/');
|
2017-07-01 11:17:46 +02:00
|
|
|
const app = express();
|
|
|
|
app.use(bodyParser.json());
|
|
|
|
app.use(bodyParser.urlencoded({
|
|
|
|
extended: true
|
|
|
|
}));
|
|
|
|
process.express = app;
|
2017-04-19 21:15:28 +02:00
|
|
|
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) {
|
2017-07-02 00:05:58 +02:00
|
|
|
const storageDir = path.join(__dirname, `/../${dir}`);
|
|
|
|
const configPath = path.join(__dirname, '../', conf);
|
|
|
|
rimRaf(storageDir, function(err) {
|
2017-06-30 23:11:40 +02:00
|
|
|
if(_.isNil(err) === false) {
|
|
|
|
reject(err);
|
|
|
|
}
|
2017-06-28 22:47:16 +02:00
|
|
|
const filteredArguments = process.execArgv = process.execArgv.filter(function(x) {
|
|
|
|
// filter out --debug-brk and --inspect-brk since Node7
|
|
|
|
return (x.indexOf('--debug-brk') === -1 && x.indexOf('--inspect-brk') === -1);
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
|
|
|
|
2017-06-28 22:47:16 +02:00
|
|
|
const childFork = fork(__dirname + '/../../../bin/verdaccio',
|
2017-07-02 00:05:58 +02:00
|
|
|
['-c', configPath],
|
2017-06-28 22:47:16 +02:00
|
|
|
{
|
|
|
|
silent: !process.env.TRAVIS
|
2017-07-02 00:05:58 +02:00
|
|
|
// silent: false
|
2017-06-28 22:47:16 +02:00
|
|
|
}
|
2017-04-19 21:15:28 +02:00
|
|
|
);
|
2017-06-28 22:47:16 +02:00
|
|
|
|
|
|
|
forks.push(childFork);
|
|
|
|
|
|
|
|
childFork.on('message', function(msg) {
|
2017-04-19 21:15:28 +02:00
|
|
|
if ('verdaccio_started' in msg) {
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
});
|
2017-06-28 22:47:16 +02:00
|
|
|
|
|
|
|
childFork.on('error', function(err) {
|
2017-04-19 21:15:28 +02:00
|
|
|
reject(err);
|
|
|
|
});
|
2017-06-28 22:47:16 +02:00
|
|
|
|
2017-06-30 23:11:40 +02:00
|
|
|
childFork.on('disconnect', function(err) {
|
|
|
|
reject(err);
|
|
|
|
});
|
|
|
|
|
|
|
|
childFork.on('exit', function(err) {
|
|
|
|
reject(err);
|
|
|
|
});
|
|
|
|
|
2017-06-28 22:47:16 +02:00
|
|
|
process.execArgv = filteredArguments;
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2013-12-19 16:11:54 +01:00
|
|
|
|
|
|
|
process.on('exit', function() {
|
2017-06-30 23:11:40 +02:00
|
|
|
if (_.isNil(forks[0]) === false) {
|
2017-03-04 00:39:26 +01:00
|
|
|
forks[0].kill();
|
|
|
|
}
|
2017-06-30 23:11:40 +02:00
|
|
|
if (_.isNil(forks[1]) === false) {
|
2017-03-04 00:39:26 +01:00
|
|
|
forks[1].kill();
|
|
|
|
}
|
2017-06-30 23:11:40 +02:00
|
|
|
if (_.isNil(forks[2]) === false) {
|
2017-03-04 00:39:26 +01:00
|
|
|
forks[2].kill();
|
|
|
|
}
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|