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 May 2, 2019
1 parent 119dccb commit 18d33f8
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 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 @@ -60,18 +61,26 @@ 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 rawIgnoreGlob = flags['ignore-files'] as string
const rawSnapshotGlob = flags['snapshot-files'] as string

const snapshotGlobs = rawSnapshotGlob.split(',')
const baseUrlFlag = flags['base-url'] as string
const rawIgnoreGlobFlag = flags['ignore-files'] as string
const rawSnapshotGlobFlag = flags['snapshot-files'] as string

const ignoreGlobs = rawIgnoreGlob ? rawIgnoreGlob.split(',') : []
const snapshotGlobs = rawSnapshotGlobFlag.split(',')

const ignoreGlobs = rawIgnoreGlobFlag ? rawIgnoreGlobFlag.split(',') : []

// exit gracefully if percy will not run
if (!this.percyWillRun()) { this.exit(0) }

// check that the base url passed in starts with a slash and exit if it is missing

// 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'] || snapshotGlobs
const ignoreFilesRegex = staticSiteConfiguration['ignore-files'] || ignoreGlobs

// 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.')
this.exit(1)
Expand Down

0 comments on commit 18d33f8

Please sign in to comment.