@percy/agent
Version:
An agent process for integrating with Percy.
81 lines (80 loc) • 3.63 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const command_1 = require("@oclif/command");
const configuration_1 = require("../configuration/configuration");
const configuration_service_1 = require("../services/configuration-service");
const static_snapshot_service_1 = require("../services/static-snapshot-service");
const logger_1 = require("../utils/logger");
const percy_command_1 = require("./percy-command");
class Snapshot extends percy_command_1.default {
async run() {
await super.run();
const { args, flags } = this.parse(Snapshot);
const configurationService = new configuration_service_1.default();
configurationService.applyFlags(flags);
configurationService.applyArgs(args);
const configuration = configurationService.configuration;
// exit gracefully if percy will not run
if (!this.percyWillRun()) {
this.exit(0);
}
const baseUrl = configuration['static-snapshots']['base-url'];
// check that base url starts with a slash and exit if it is missing
if (baseUrl[0] !== '/') {
logger_1.default.warn('The base-url flag must begin with a slash.');
this.exit(1);
}
await this.agentService.start(configuration);
this.logStart();
const staticSnapshotService = new static_snapshot_service_1.default(configuration['static-snapshots']);
// start the snapshot service
await staticSnapshotService.start();
// take the snapshots
await staticSnapshotService.snapshotAll();
// stop the static snapshot and agent services
await staticSnapshotService.stop();
await this.agentService.stop();
}
}
Snapshot.description = 'Snapshot a directory containing a pre-built static website.';
Snapshot.hidden = false;
Snapshot.args = [{
name: 'snapshotDirectory',
description: 'A path to the directory you would like to snapshot',
required: true,
}];
Snapshot.examples = [
'$ percy snapshot _site/',
'$ percy snapshot _site/ --base-url "/blog/"',
'$ percy snapshot _site/ --ignore-files "/blog/drafts/**"',
];
Snapshot.flags = {
'snapshot-files': command_1.flags.string({
char: 's',
description: 'Glob or comma-seperated string of globs for matching the files and directories to snapshot.',
default: configuration_1.DEFAULT_CONFIGURATION['static-snapshots']['snapshot-files'],
}),
'ignore-files': command_1.flags.string({
char: 'i',
description: 'Glob or comma-seperated string of globs for matching the files and directories to ignore.',
default: configuration_1.DEFAULT_CONFIGURATION['static-snapshots']['ignore-files'],
}),
'base-url': command_1.flags.string({
char: 'b',
description: 'If your static files will be hosted in a subdirectory, instead \n' +
'of the webserver\'s root path, set that subdirectory with this flag.',
default: configuration_1.DEFAULT_CONFIGURATION['static-snapshots']['base-url'],
}),
// from exec command. needed to start the agent service.
'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 = Snapshot;