-
Notifications
You must be signed in to change notification settings - Fork 181
/
removeProps.js
41 lines (37 loc) · 1005 Bytes
/
removeProps.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
const fs = require('fs')
const dir = require('node-dir')
const SOURCE_DIR = './config/default/common/config/wv.json/layers/'
const removeKeys = [
'product',
'title',
'subtitle',
'inactive',
'daynight',
'tracks'
]
const errCallback = (err) => {
if (err) {
console.log(err)
throw err
}
}
function processConfig (filePath) {
const pathStrings = filePath.split('/')
const fileName = pathStrings[pathStrings.length - 1]
if (!fileName.includes('.json')) {
return
}
const layerJson = JSON.parse(fs.readFileSync(filePath, 'utf-8'))
const layerId = Object.keys(layerJson.layers)[0]
removeKeys.forEach((key) => {
const entry = layerJson.layers[layerId]
// Leave ID prop on WMS entries
if (entry.type === 'wms' && key === 'id') return
delete layerJson.layers[layerId][key]
})
fs.writeFile(`${filePath}`, JSON.stringify(layerJson, null, 2), errCallback)
}
dir.files(SOURCE_DIR, (err, files) => {
if (err) throw err
files.forEach(processConfig)
})