@viewdo/dxp-story-cli
Version:
README.md
30 lines (22 loc) • 593 B
JavaScript
const fs = require('fs')
const path = require('path')
const YAML = require('yamljs')
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('.json', '.yaml')
} = options
let json_object = YAML.load(file)
ensureDirectoryExistence(output)
fs.writeFileSync(output, JSON.stringify(json_object, null, 2))
return result
}