MCPcopy Create free account
hub / github.com/CommandCodeAI/BaseAI / updateGitignore

Function updateGitignore

packages/baseai/src/init/index.ts:236–267  ·  view source on GitHub ↗
({
	gitignoreEntry
}: {
	gitignoreEntry: string;
})

Source from the content-addressed store, hash-verified

234}
235
236async 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
269async function createEnvBaseAIExample(): Promise<void> {
270 const envBaseAIExamplePath = path.join(

Callers 1

initFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected