Skip to content

Commit

Permalink
Consume percy.yml settings but fall back to flags and defaults if it …
Browse files Browse the repository at this point in the history
…doesn't exist
  • Loading branch information
maprules1000 committed Apr 17, 2019
1 parent 92f20af commit ca7fc2b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/commands/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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.')
Expand Down

0 comments on commit ca7fc2b

Please sign in to comment.