@percy/agent
Version:
An agent process for integrating with Percy.
55 lines (54 loc) • 2.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const command_1 = require("@oclif/command");
const spawn = require("cross-spawn");
const configuration_1 = require("../configuration/configuration");
const configuration_service_1 = require("../services/configuration-service");
const percy_command_1 = require("./percy-command");
class Exec extends percy_command_1.default {
async run() {
await super.run();
const { argv } = this.parse(Exec);
const { flags } = this.parse(Exec);
const command = argv.shift();
if (!command) {
this.logger.info('You must supply a command to run after --');
this.logger.info('Example:');
this.logger.info('$ percy exec -- echo "run your test suite"');
return;
}
if (this.percyWillRun()) {
const configuration = new configuration_service_1.default().applyFlags(flags);
await this.agentService.start(configuration);
this.logStart();
}
// Even if Percy will not run, continue to run the subprocess
const spawnedProcess = spawn(command, argv, { stdio: 'inherit' });
spawnedProcess.on('exit', async (code) => {
if (this.percyWillRun()) {
await this.agentService.stop();
}
process.exit(code);
});
}
}
Exec.description = 'Start and stop Percy around a supplied command.';
Exec.hidden = false;
Exec.strict = false;
Exec.examples = [
'$ percy exec -- echo \"percy is running around this echo command\"',
'$ percy exec -- bash -c "echo foo && echo bar"',
];
Exec.flags = {
'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 = Exec;