-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d87702a
commit 3945cb3
Showing
8 changed files
with
129 additions
and
28 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 |
---|---|---|
@@ -1,4 +1,7 @@ | ||
node_modules | ||
dist | ||
|
||
.env* | ||
.env* | ||
|
||
app | ||
polar.ts |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,41 @@ | ||
import path from 'node:path'; | ||
import fs from 'node:fs/promises'; | ||
|
||
const envFiles = ['.env', '.env.local']; | ||
|
||
const resolveEnvPaths = async () => { | ||
const cwd = process.cwd(); | ||
const paths = envFiles.map(file => path.join(cwd, file)); | ||
|
||
const existingFiles = await Promise.all( | ||
paths.map(async (filePath) => { | ||
try { | ||
await fs.access(filePath); | ||
return filePath; | ||
} catch { | ||
return null; | ||
} | ||
}) | ||
); | ||
|
||
return existingFiles.filter(Boolean); | ||
}; | ||
|
||
export const appendEnvironmentVariables = async (variables: Record<string, string>) => { | ||
const envPaths = await resolveEnvPaths(); | ||
|
||
for (const envPath of envPaths) { | ||
if (!envPath) continue; | ||
|
||
const envFile = await fs.readFile(envPath, 'utf8'); | ||
|
||
const newEnvFile = Object.entries(variables).reduce((acc, [key, value]) => { | ||
if (!acc.includes(`${key}=`)) { | ||
return `${acc}\n${key}=${value}`; | ||
} | ||
return acc; | ||
}, envFile); | ||
|
||
await fs.writeFile(envPath, newEnvFile); | ||
} | ||
} |
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
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
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,16 @@ | ||
import { Spinner } from "@inkjs/ui"; | ||
import { render } from "ink"; | ||
import React from "react"; | ||
|
||
export const environmentDisclaimer = async (promise: Promise<void>) => { | ||
const { unmount, clear, waitUntilExit } = render( | ||
<Spinner label="Configuring environment variables..." />, | ||
); | ||
|
||
promise.then(() => { | ||
clear(); | ||
unmount(); | ||
}); | ||
|
||
await waitUntilExit(); | ||
}; |