-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake-json.js
executable file
·31 lines (27 loc) · 933 Bytes
/
make-json.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env node
const fs = require('fs');
const yaml = require('js-yaml');
const camelizeObject = require('camelize');
const dataDir = __dirname + '/data';
const personDir = dataDir + '/person';
const personFile = dataDir + '/person.json';
const personData = {};
const ancYamlFile = dataDir + '/anc.yaml';
const ancJsonFile = dataDir + '/anc.json';
fs.readdirSync(personDir).forEach(file => {
if (!/\.yaml$/.test(file)) {
return;
}
const d = yaml.safeLoad(fs.readFileSync(personDir + '/' + file));
personData[d.code] = camelizeObject(d);
});
fs.writeFileSync(personFile, JSON.stringify(personData));
const ancData = yaml.safeLoad(fs.readFileSync(ancYamlFile));
ancData.commissioners = Object.entries(ancData.commissioners).reduce(
function (acc, [key, value]) {
acc[key] = camelizeObject(value);
return acc;
},
{}
);
fs.writeFileSync(ancJsonFile, JSON.stringify(ancData));