FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
jamstack-cms/createLocalConfig.js at master · jamstack-cms/jamstack-cms · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
jamstack-cms
/
jamstack-cms
Public
Notifications
You must be signed in to change notification settings
Fork
67
Star
722
Code
Issues
11
Pull requests
22
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
jamstack-cms
/
createLocalConfig.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
48 lines (45 loc) · 1.46 KB
Breadcrumbs
jamstack-cms
/
createLocalConfig.js
Copy path
File metadata and controls
48 lines (45 loc) · 1.46 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
44
45
46
47
48
const
fs
=
require
(
'fs'
)
const
stripJsonComments
=
require
(
'strip-json-comments'
)
const
config
=
'./src/aws-exports.js'
/*
* This function will take the base Amplify config, remove the API key reference, write the base
* config to jamstack-config.js, create a local reference to the API key for local development,
* and write that configuration to jamstack-api-key.js
*/
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
=
newJson
.
replace
(
'export default awsmobile'
,
'module.exports = awsmobile'
)
newJson
=
JSON
.
parse
(
newJson
)
fs
.
writeFile
(
'jamstack-config.js'
,
newJson
,
'utf8'
,
function
(
err
,
success
)
{
if
(
err
)
{
throw
err
}
console
.
log
(
'JAMstack config successfully created!'
)
}
)
items
.
forEach
(
item
=>
{
if
(
item
.
includes
(
'aws_appsync_apiKey'
)
)
{
let
text
=
item
.
replace
(
"\\n"
,
""
)
text
=
text
.
replace
(
/
(
\\
)
/
gm
,
""
)
const
fileData
=
`const fileData = {
${
text
}
}
module.exports = fileData
`
fs
.
writeFile
(
'jamstack-api-key.js'
,
fileData
,
'utf8'
,
function
(
err
)
{
if
(
err
)
{
throw
err
}
console
.
log
(
'JAMstack API key config successfully created!'
)
}
)
}
}
)
}
)
Back
|
FazBrowse Home
|
New Git URL