forked from jamstack-cms/jamstack-cms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateBaseConfig.js
32 lines (29 loc) · 907 Bytes
/
createBaseConfig.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
const fs = require('fs')
const stripJsonComments = require('strip-json-comments')
const config = './src/aws-exports.js'
/*
* This function will take the main AWS Exports, remove the API key reference,
* and write the new configuration to jamstack-config.js
*/
function createbaseConfig() {
fs.readFile(config, 'utf8', function (err, data) {
if (err) {
throw err
}
const stripped = stripJsonComments(data)
var content = JSON.stringify(stripped)
const items = content.split(',')
const withoutAPIKey = items.filter(item => {
return !(item.includes('aws_appsync_apiKey'))
})
let newJson = withoutAPIKey.join(',')
newJson = JSON.parse(newJson)
fs.writeFile('jamstack-config.js', newJson, 'utf8', function(err, success) {
if (err) {
throw err
}
console.log('JAMstack config successfully created!')
})
})
}
createbaseConfig()