UNPKG

@viewdo/dxp-story-cli

Version:
40 lines (32 loc) 1.19 kB
const fs = require('fs'); const hasPath = path => { try { fs.accessSync(path, fs.constants.F_OK); return true; } catch (err) { console.log(err); return false; } } module.exports = (iVXConfig) => { const { build, stories } = iVXConfig; const storyKeys = Object.keys(stories); storyKeys.forEach((storyKey) => { const folderPath = `${build}/${storyKey}`; const stylePath = `${folderPath}/text-templates/compiled.css`; const jsonFilePath = `${folderPath}/story.json`; if (hasPath(stylePath) && hasPath(jsonFilePath)) { const style = fs.readFileSync(`${folderPath}/text-templates/compiled.css`, 'utf-8'); const jsonFile = fs.readFileSync(`${folderPath}/story.json`, 'utf-8'); const json = JSON.parse(jsonFile); const { metadata = {} } = json; const updatedMetadata = Object.assign(metadata, { style: style }); const newJSON = Object.assign(json, { metadata: updatedMetadata }); fs.writeFileSync(jsonFilePath, JSON.stringify(newJSON, null, 4)); } }); }