Skip to content

Instantly share code, notes, and snippets.

@jmfrancois
Last active September 18, 2019 08:29
Show Gist options
  • Save jmfrancois/30635ff37580196e84f8d1da1fb4cc95 to your computer and use it in GitHub Desktop.
Save jmfrancois/30635ff37580196e84f8d1da1fb4cc95 to your computer and use it in GitHub Desktop.
To split CMF settings.json files into multiple ones.
#!/usr/bin/env node
const fs = require('fs');
const settings = require(process.argv[2]);
if (!settings.props) {
console.log('no props in this file');
process.exit();
}
const extra = Object.keys(settings).filter(key => key !== 'props');
const newSettings = Object.keys(settings.props).reduce((acc, key) => {
const splitted = key.split('#');
if (splitted.length < 2) {
acc.props[key] = settings.props[key];
return acc;
}
const component = splitted[0];
if (!acc[component]) {
acc[component] = {}
}
acc[component][key] = settings.props[key];
return acc;
}, { props: {}});
extra.reduce((acc, key) => {
acc[key] = settings[key];
}, newSettings.props);
Object.keys(newSettings).forEach(key => {
console.log('create ', `${key}.json`);
fs.writeFileSync(`${key}.json`, JSON.stringify({ props: newSettings[key] }, null, 2));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment