Skip to content

Instantly share code, notes, and snippets.

@MadRiver44
Created December 20, 2019 15:18
Show Gist options
  • Save MadRiver44/820eae6a9e200285ffc1bbb5468cdc48 to your computer and use it in GitHub Desktop.
Save MadRiver44/820eae6a9e200285ffc1bbb5468cdc48 to your computer and use it in GitHub Desktop.
Create a .json file from reading backstop.yml file -- updateConfig.js
/**
* This script creates a `backstop.json` file from `backstop.yml` and all <label>.yml files included in scenarios directory
* `backstop.json` is a configuration file that BackstopJS uses to create screenshots of components
*
*/
const fs = require('fs')
const path = require('path')
const yaml = require('js-yaml')
const backstopJSON = yaml.load(fs.readFileSync(path.resolve('./backstop.yml')))
backstopJSON.scenarios = fs
.readdirSync(path.resolve('backstop_data', 'scenarios'))
.filter(file => file.match(/\.yml/i))
.map(file => yaml.load(fs.readFileSync(path.resolve('backstop_data', 'scenarios', file))))
fs.writeFileSync(path.join('./backstop.json'), JSON.stringify(backstopJSON, null, 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment