2017-11-19 16:08:04 +01:00
|
|
|
// @flow
|
|
|
|
import _ from 'lodash';
|
2017-11-27 07:15:09 +01:00
|
|
|
import VerdaccioProcess from './server_process';
|
|
|
|
import type {IVerdaccioConfig, IServerProcess} from './types';
|
2017-11-19 16:08:04 +01:00
|
|
|
|
|
|
|
export class VerdaccioConfig implements IVerdaccioConfig {
|
|
|
|
|
|
|
|
storagePath: string;
|
|
|
|
configPath: string;
|
|
|
|
domainPath: string;
|
|
|
|
|
|
|
|
constructor(storagePath: string, configPath: string, domainPath: string) {
|
|
|
|
this.storagePath = storagePath;
|
|
|
|
this.configPath = configPath;
|
|
|
|
this.domainPath = domainPath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class VerdaccioServer {
|
|
|
|
|
|
|
|
serverProcess: IServerProcess;
|
|
|
|
pid: number;
|
|
|
|
|
|
|
|
constructor(config: IVerdaccioConfig) {
|
2017-11-27 07:15:09 +01:00
|
|
|
console.log("*************VerdaccioServer****************");
|
2017-11-19 16:08:04 +01:00
|
|
|
this.serverProcess = new VerdaccioProcess(config);
|
2017-11-27 07:15:09 +01:00
|
|
|
console.log("*************VerdaccioServer****************");
|
2017-11-19 16:08:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
start(): Promise<any> {
|
2017-11-27 07:15:09 +01:00
|
|
|
console.log("*************VerdaccioServer******start**********");
|
2017-11-19 16:08:04 +01:00
|
|
|
return this.serverProcess.init().then(this.debugCheck);
|
|
|
|
}
|
|
|
|
|
2017-11-27 07:15:09 +01:00
|
|
|
debugCheck = (): Promise<any> => {
|
|
|
|
console.log("*************VerdaccioServer******debugCheck**********");
|
2017-11-19 16:08:04 +01:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
this.serverProcess.getBridge().debug().status(200).then((body) => {
|
|
|
|
if (_.isNil(body.pid)) {
|
|
|
|
reject();
|
|
|
|
}
|
2017-11-27 07:15:09 +01:00
|
|
|
console.log("*************body.pid;******debugCheck**********", body.pid);
|
2017-11-19 16:08:04 +01:00
|
|
|
this.pid = body.pid;
|
2017-11-27 07:15:09 +01:00
|
|
|
console.log("************authTestUser***");
|
2017-11-19 16:08:04 +01:00
|
|
|
return this.authTestUser().catch(function(reason: any) {
|
2017-11-27 07:15:09 +01:00
|
|
|
console.log("************authTestUser**reason*", reason);
|
2017-11-19 16:08:04 +01:00
|
|
|
reject(reason);
|
|
|
|
});
|
|
|
|
}).catch(function(reason: any) {
|
|
|
|
reject(reason);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
authTestUser(): Promise<any> {
|
|
|
|
return this.serverProcess.getBridge().auth('test', 'test')
|
|
|
|
.status(201)
|
|
|
|
.body_ok(/'test'/);
|
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
notify() {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|