0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-23 22:27:34 -05:00
verdaccio/test/functional/lib/server_process.js
2018-01-07 07:59:36 +00:00

71 lines
No EOL
1.6 KiB
JavaScript

// @flow
import _ from 'lodash';
import rimRaf from 'rimraf';
import path from 'path';
import {fork} from 'child_process';
import type {IVerdaccioConfig, IServerBridge, IServerProcess} from './types';
export default class VerdaccioProcess implements IServerProcess {
bridge: IServerBridge;
config: IVerdaccioConfig;
childFork: any;
constructor(config: IVerdaccioConfig, bridge: IServerBridge) {
this.config = config;
this.bridge = bridge;
}
init(): Promise<any> {
return new Promise((resolve, reject) => {
const verdaccioRegisterWrap: string = path.join(__dirname, '../../../bin/verdaccio');
const storageDir: string = path.join(__dirname, `/../${this.config.storagePath}`);
const configPath: string = path.join(__dirname, '../', this.config.configPath);
rimRaf(storageDir, (err) => {
if (_.isNil(err) === false) {
reject(err);
}
this.childFork = fork(verdaccioRegisterWrap,
['-c', configPath],
{
silent: false
}
);
this.childFork.on('message', (msg) => {
if ('verdaccio_started' in msg) {
this.bridge.debug().status(200).then((body) => {
this.bridge.auth('test', 'test')
.status(201)
.body_ok(/'test'/)
.then(() => {
resolve([this, body.pid]);
}, reject)
}, reject);
}
});
this.childFork.on('error', function(err) {
reject(err);
});
this.childFork.on('disconnect', function(err) {
reject(err);
});
this.childFork.on('exit', function(err) {
reject(err);
});
});
});
}
stop(): void {
return this.childFork.kill('SIGINT');
}
}