This repository has been archived by the owner on Apr 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add script to move env variables to Wrangler config on build.
- Loading branch information
1 parent
2f7f8f6
commit e2d9e0e
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const dotenv = require('dotenv'); | ||
const replace = require('replace-in-file'); | ||
|
||
const { resolve } = require('path'); | ||
|
||
dotenv.config(); | ||
|
||
const cwd = resolve(__dirname); | ||
|
||
(async () => { | ||
const replaceOptions = { | ||
files: resolve(cwd, 'sw.js'), | ||
from: [ | ||
/account_id\s=\s""/g, | ||
/AUTH_KEY\s=\s""/g, | ||
/AIRTABLE_API\s=\s""/g, | ||
/AIRTABLE_BOOKMARKS_ENDPOINT\s=\s""/g, | ||
/TWITTER_KEY\s=\s""/g, | ||
/VIMEO_KEY\s=\s""/g, | ||
/YOUTUBE_KEY\s=\s""/g, | ||
], | ||
to: [ | ||
`account_id = "${process.env.CF_ACCOUNT_ID}"`, | ||
`AUTH_KEY = "${process.env.AUTH_KEY}"`, | ||
`AIRTABLE_API = "${process.env.AIRTABLE_API}"`, | ||
`AIRTABLE_BOOKMARKS_ENDPOINT = "${process.env.AIRTABLE_BOOKMARKS_ENDPOINT}"`, | ||
`TWITTER_KEY = "${process.env.TWITTER_KEY}"`, | ||
`VIMEO_KEY = "${process.env.VIMEO_KEY}"`, | ||
`YOUTUBE_KEY = "${process.env.YOUTUBE_KEY}"`, | ||
], | ||
}; | ||
|
||
try { | ||
await replace(replaceOptions); | ||
} catch (error) { | ||
console.error('[setEnv]:', error); | ||
} | ||
})(); |