| 234 | } |
| 235 | |
| 236 | async function updateGitignore({ |
| 237 | gitignoreEntry |
| 238 | }: { |
| 239 | gitignoreEntry: string; |
| 240 | }): Promise<void> { |
| 241 | const gitignorePath = path.join(process.cwd(), '.gitignore'); |
| 242 | |
| 243 | try { |
| 244 | let gitignoreContent = ''; |
| 245 | try { |
| 246 | gitignoreContent = await fs.readFile(gitignorePath, 'utf-8'); |
| 247 | } catch (error) { |
| 248 | // File doesn't exist, create it with the new entry |
| 249 | await fs.writeFile(gitignorePath, gitignoreEntry); |
| 250 | return; // Exit the function as we've already added the entry |
| 251 | } |
| 252 | |
| 253 | // Check if the exact entry already exists |
| 254 | if (!gitignoreContent.includes(gitignoreEntry)) { |
| 255 | // Ensure there's a newline before adding the new entry if the file isn't empty |
| 256 | const updatedContent = gitignoreContent.endsWith('\n') |
| 257 | ? gitignoreContent + gitignoreEntry |
| 258 | : gitignoreContent + '\n' + gitignoreEntry; |
| 259 | |
| 260 | await fs.writeFile(gitignorePath, updatedContent); |
| 261 | } |
| 262 | } catch (error) { |
| 263 | p.log.error( |
| 264 | `Error updating .gitignore: ${error instanceof Error ? error.message : String(error)}` |
| 265 | ); |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | async function createEnvBaseAIExample(): Promise<void> { |
| 270 | const envBaseAIExamplePath = path.join( |