Created
March 8, 2018 17:17
-
-
Save dsample/e8529d1a856d614df174c6c5cf59515f to your computer and use it in GitHub Desktop.
Convert a directory of YAML to JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const yaml = require('yamljs') | |
const fs = require('fs') | |
const directory = process.argv[2] || '.' | |
fs.readdirSync(directory) | |
.filter(f => f.endsWith('.yaml')) | |
.map(f => f.substring(0,f.indexOf('.yaml'))) | |
.forEach((name) => { | |
const fromYaml = yaml.load(name + '.yaml') | |
const json = JSON.stringify(fromYaml,null,2) | |
fs.writeFile(name + '.json', json, () => {console.log(`Converted ${name}.yaml`)}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment