-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprep.js
executable file
·43 lines (37 loc) · 1.91 KB
/
prep.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
32
33
34
35
36
37
38
39
40
41
42
43
const fs = require('fs')
const parseJSON = filePath => {
let fileName = ''
try {
fileName = filePath.lastIndexOf('/') == -1 ? filePath : filePath.substring(filePath.lastIndexOf('/') + 1);
return JSON.parse(fs.readFileSync(filePath, 'utf-8'))
} catch (error) {
throw new Error(`"${fileName}" is not a valid json file`)
}
}
// change the path below if the schema file needs to be relocated elsewhere
let schema = parseJSON('./src/schema/outline.json');
Object.keys(schema).map(platform => {
if (schema[platform]['fields']) {
Object.keys(schema[platform]['fields']).map(field => {
if (schema[platform]['fields'][field]['dependent']) {
if (schema[platform]['fields'][field]['type'].toLowerCase() === 'case') {
Object.keys(schema[platform]['fields'][field]['case']).map(c => {
if (schema[platform]['fields'][field]['case'][c]['data']) {
let dataPath = schema[platform]['fields'][field]['case'][c]['data']
schema[platform]['fields'][field]['case'][c]['data'] = parseJSON(`./src/data/${dataPath}`)
}
})
} else if (schema[platform]['fields'][field]['data']) {
let dataPath = schema[platform]['fields'][field]['data']
schema[platform]['fields'][field]['data'] = parseJSON(`./src/data/${dataPath}`)
}
} else {
if (schema[platform]['fields'][field]['data']) {
let dataPath = schema[platform]['fields'][field]['data']
schema[platform]['fields'][field]['data'] = parseJSON(`./src/data/${dataPath}`)
}
}
})
}
})
fs.writeFileSync('./src/data/processed/overall.json', JSON.stringify(schema, null, 2), 'utf8', err => { });