forked from sombochea/verdaccio-ui
d1b3e6e3b5
* build: add e2e testing scripts * build: add e2e testing scripts * chore: fix script * chore: fix script * chore: ignore e2e normal test * chore: fix node_latest_browser * chore: move lint to prepare * chore: fix lint * chore: add local theme * fix: e2e tests
61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import path from 'path';
|
|
import { fork } from 'child_process';
|
|
|
|
import { HTTP_STATUS } from '@verdaccio/commons-api';
|
|
|
|
export const CREDENTIALS = {
|
|
user: 'foo',
|
|
password: 'test',
|
|
};
|
|
|
|
export default class VerdaccioProcess {
|
|
private bridge;
|
|
private config;
|
|
private childFork;
|
|
|
|
public constructor(config, bridge) {
|
|
this.config = config;
|
|
this.bridge = bridge;
|
|
}
|
|
|
|
public init(verdaccioPath) {
|
|
return new Promise((resolve, reject) => {
|
|
this._start(verdaccioPath, resolve, reject);
|
|
});
|
|
}
|
|
|
|
private _start(verdaccioPath: string, resolve: Function, reject: Function) {
|
|
const verdaccioRegisterWrap: string = path.join(__dirname, verdaccioPath);
|
|
const childOptions = {
|
|
silent: false,
|
|
};
|
|
|
|
const { configPath, port } = this.config;
|
|
this.childFork = fork(verdaccioRegisterWrap, ['-c', configPath, '-l', port as string], childOptions);
|
|
|
|
this.childFork.on('message', msg => {
|
|
// verdaccio_started is a message that comes from verdaccio in debug mode that notify has been started
|
|
if ('verdaccio_started' in msg) {
|
|
this.bridge
|
|
.debug()
|
|
.status(HTTP_STATUS.OK)
|
|
.then(body => {
|
|
this.bridge
|
|
.auth(CREDENTIALS.user, CREDENTIALS.password)
|
|
.status(HTTP_STATUS.CREATED)
|
|
.body_ok(new RegExp(CREDENTIALS.user))
|
|
.then(() => resolve([this, body.pid]), reject);
|
|
}, reject);
|
|
}
|
|
});
|
|
|
|
this.childFork.on('error', err => reject([err, this]));
|
|
this.childFork.on('disconnect', err => reject([err, this]));
|
|
this.childFork.on('exit', err => reject([err, this]));
|
|
}
|
|
|
|
public stop(): void {
|
|
return this.childFork.kill('SIGINT');
|
|
}
|
|
}
|