UNPKG

@viewdo/dxp-story-cli

Version:
30 lines (22 loc) 615 B
const fs = require('fs') const path = require('path') const YAML = require('json-to-pretty-yaml') function ensureDirectoryExistence(filePath) { var dirname = path.dirname(filePath); if (fs.existsSync(dirname)) { return true; } ensureDirectoryExistence(dirname); fs.mkdirSync(dirname); } module.exports = async (options, next = 0) => { let result = next let { file, output = file.replace('.yaml', '.json') } = options let json_object = JSON.parse(fs.readFileSync(file)) ensureDirectoryExistence(output) fs.writeFileSync(output, YAML.stringify(json_object)) return result }