From ca7fc2b473440386f5cf4da629d0395cc18a5ca9 Mon Sep 17 00:00:00 2001 From: Michael Padon Date: Wed, 17 Apr 2019 10:15:28 -0500 Subject: [PATCH] Consume percy.yml settings but fall back to flags and defaults if it doesn't exist --- src/commands/snapshot.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/commands/snapshot.ts b/src/commands/snapshot.ts index 2f777b24..8b10e7f1 100644 --- a/src/commands/snapshot.ts +++ b/src/commands/snapshot.ts @@ -2,6 +2,7 @@ import {flags} from '@oclif/command' import Constants from '../services/constants' import {StaticSnapshotOptions} from '../services/static-snapshot-options' import StaticSnapshotService from '../services/static-snapshot-service' +import configuration, {StaticSiteSnapshotConfiguration} from '../utils/configuration' import logger from '../utils/logger' import PercyCommand from './percy-command' @@ -62,13 +63,19 @@ export default class Snapshot extends PercyCommand { const port = flags.port as number const staticServerPort = port + 1 const networkIdleTimeout = flags['network-idle-timeout'] as number - const baseUrl = flags['base-url'] as string - const ignoreFilesRegex = flags['ignore-files'] as string - const snapshotFilesRegex = flags['snapshot-files'] as string + const baseUrlFlag = flags['base-url'] as string + const ignoreFilesRegexFlag = flags['ignore-files'] as string + const snapshotFilesRegexFlag = flags['snapshot-files'] as string // exit gracefully if percy will not run if (!this.percyWillRun()) { this.exit(0) } + // read configurations from the percy.yml file + const staticSiteConfiguration = (configuration().static_site || {}) as StaticSiteSnapshotConfiguration + const baseUrl = staticSiteConfiguration['base-url'] || baseUrlFlag + const snapshotFilesRegex = staticSiteConfiguration['snapshot-files'] || snapshotFilesRegexFlag + const ignoreFilesRegex = staticSiteConfiguration['ignore-files'] || ignoreFilesRegexFlag + // check that base url starts with a slash and exit if it is missing if (baseUrl[0] !== '/') { logger.warn('The base-url flag must begin with a slash.')