UNPKG

@viewdo/dxp-story-cli

Version:
40 lines (31 loc) 890 B
const fs = require('fs') const path = require('path') const find_restore_html = (node, ) => { Object.keys(node).forEach((key) => { let htmlProp = /(^.*html)$/gi let pathValue = /^(.*\.html)$/gi if(typeof key == 'string' && htmlProp.test(key)) { let value = node[key] // begins with <(path) if(pathValue.test(value)) { let file_path = path.join(process.cwd(), value) let html = fs.readFileSync(file_path, 'utf8') node[key] = html || '' } } if(typeof node[key] === 'object') { find_restore_html(node[key]) } }) } module.exports = async (options, next = 0) => { let result = next let { file, output } = options let json_object = JSON.parse(fs.readFileSync(file, 'utf8')) find_restore_html(json_object) fs.writeFileSync(output, JSON.stringify(json_object, null, 2)) return result }