@percy/agent
Version:
An agent process for integrating with Percy.
82 lines (81 loc) • 2.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const command_1 = require("@oclif/command");
const path = require("path");
const configuration_1 = require("../configuration/configuration");
const configuration_service_1 = require("../services/configuration-service");
const health_checker_1 = require("../utils/health-checker");
const percy_command_1 = require("./percy-command");
class Start extends percy_command_1.default {
async run() {
await super.run();
// If Percy is disabled or is missing a token, gracefully exit here
if (!this.percyWillRun()) {
this.exit(0);
}
const { flags } = this.parse(Start);
if (flags.detached) {
this.runDetached();
}
else {
await this.runAttached();
}
await health_checker_1.default(flags.port);
}
async runAttached() {
const { flags } = this.parse(Start);
process.on('SIGHUP', async () => {
await this.agentService.stop();
process.exit(0);
});
process.on('SIGINT', async () => {
await this.agentService.stop();
process.exit(0);
});
process.on('SIGTERM', async () => {
await this.agentService.stop();
process.exit(0);
});
const configuration = new configuration_service_1.default().applyFlags(flags);
await this.agentService.start(configuration);
this.logStart();
}
runDetached() {
const { flags } = this.parse(Start);
const pid = this.processService.runDetached([
path.resolve(`${__dirname}/../../bin/run`),
'start',
'-p', String(flags.port),
'-t', String(flags['network-idle-timeout']),
]);
if (pid) {
this.logStart();
}
else {
this.logger.warn('percy is already running');
}
}
}
Start.description = 'Starts the percy process.';
Start.hidden = true;
Start.examples = [
'$ percy start\n' +
`info: percy has started on port ${configuration_1.DEFAULT_CONFIGURATION.agent.port}.`,
];
Start.flags = {
'detached': command_1.flags.boolean({
char: 'd',
description: 'start as a detached process',
}),
'network-idle-timeout': command_1.flags.integer({
char: 't',
default: configuration_1.DEFAULT_CONFIGURATION.agent['asset-discovery']['network-idle-timeout'],
description: 'asset discovery network idle timeout (in milliseconds)',
}),
'port': command_1.flags.integer({
char: 'p',
default: configuration_1.DEFAULT_CONFIGURATION.agent.port,
description: 'port',
}),
};
exports.default = Start;