-
Notifications
You must be signed in to change notification settings - Fork 181
/
renameProps.js
37 lines (32 loc) · 898 Bytes
/
renameProps.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
const fs = require('fs')
const dir = require('node-dir')
const { GIT_HOME } = process.env
const SOURCE_DIR = `${GIT_HOME}/layers-config/layer-metadata/v1.0/`
const renameKeys = {
period: 'layerPeriod'
}
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 metadataJson = JSON.parse(fs.readFileSync(filePath, 'utf-8'))
Object.keys(renameKeys).forEach((key) => {
const entry = metadataJson
const newKey = renameKeys[key]
entry[newKey] = entry[key]
delete entry[key]
})
fs.writeFile(`${filePath}`, JSON.stringify(metadataJson, null, 2), errCallback)
}
dir.files(SOURCE_DIR, (err, files) => {
if (err) throw err
files.forEach(processConfig)
})