-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmakeIndex.js
More file actions
25 lines (21 loc) · 776 Bytes
/
makeIndex.js
File metadata and controls
25 lines (21 loc) · 776 Bytes
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
const fs = require('fs').promises;
function copyObj(o) {
return JSON.parse(JSON.stringify(o));
}
(async function start() {
const parsedDb = await fs.readFile('./spec_fixed.json').then((c) => JSON.parse(c));
const { version } = parsedDb;
const { keywordsMapping } = parsedDb;
const dbIndex = parsedDb.result.reduce((o, el) => {
const names = el.tags.list.slice(0);
// eslint-disable-next-line no-restricted-syntax
for (const tag of names) {
const copyOfEl = copyObj(el);
copyOfEl.tags.list = [tag];
// eslint-disable-next-line no-param-reassign
o[tag] = copyOfEl;
}
return o;
}, {});
await fs.writeFile('./specindex.json', JSON.stringify({ version, keywordsMapping, index: dbIndex }), { encoding: 'utf-8' });
}());