MCPcopy Index your code
hub / github.com/cameri/nostream / ensureEnvFile

Function ensureEnvFile

src/cli/commands/setup.ts:108–138  ·  view source on GitHub ↗
(assumeYes: boolean)

Source from the content-addressed store, hash-verified

106}
107
108const ensureEnvFile = async (assumeYes: boolean): Promise<boolean> => {
109 const envPath = getProjectPath('.env')
110 const envExamplePath = getProjectPath('.env.example')
111
112 if (!fs.existsSync(envPath)) {
113 if (fs.existsSync(envExamplePath)) {
114 fs.copyFileSync(envExamplePath, envPath)
115 } else {
116 fs.writeFileSync(envPath, '', 'utf-8')
117 }
118 }
119
120 const current = fs.readFileSync(envPath, 'utf-8')
121
122 if (!needsSecretReplacement(readEnvSecret(current))) {
123 return true
124 }
125
126 let secret: string
127 try {
128 secret = await resolveSecret(assumeYes)
129 } catch (error) {
130 if (error instanceof SetupCancelledError) {
131 return false
132 }
133 throw error
134 }
135
136 fs.writeFileSync(envPath, upsertSecret(current, secret), 'utf-8')
137 return true
138}
139
140export const runSetup = async (options: SetupOptions): Promise<number> => {
141 setupPrompts.intro('Nostream setup')

Callers 1

runSetupFunction · 0.85

Calls 5

getProjectPathFunction · 0.90
needsSecretReplacementFunction · 0.85
readEnvSecretFunction · 0.85
resolveSecretFunction · 0.85
upsertSecretFunction · 0.85

Tested by

no test coverage detected