MCPcopy
hub / github.com/yamadashy/repomix / createIgnoreFile

Function createIgnoreFile

src/cli/actions/initAction.ts:128–178  ·  view source on GitHub ↗
(rootDir: string, isGlobal: boolean)

Source from the content-addressed store, hash-verified

126};
127
128export const createIgnoreFile = async (rootDir: string, isGlobal: boolean): Promise<boolean> => {
129 if (isGlobal) {
130 prompts.log.info(`Skipping ${pc.green('.repomixignore')} file creation for global configuration.`);
131 return false;
132 }
133
134 const ignorePath = path.resolve(rootDir, '.repomixignore');
135 const createIgnore = await prompts.confirm({
136 message: `Do you want to create a ${pc.green('.repomixignore')} file?`,
137 });
138 if (!createIgnore) {
139 prompts.log.info(`Skipping ${pc.green('.repomixignore')} file creation.`);
140 return false;
141 }
142 if (prompts.isCancel(createIgnore)) {
143 onCancelOperation();
144 return false;
145 }
146
147 let isIgnoreFileExists = false;
148 try {
149 await fs.access(ignorePath);
150 isIgnoreFileExists = true;
151 } catch {
152 // File doesn't exist, so we can proceed
153 }
154
155 if (isIgnoreFileExists) {
156 const overwrite = await prompts.confirm({
157 message: `A ${pc.green('.repomixignore')} file already exists. Do you want to overwrite it?`,
158 });
159
160 if (!overwrite) {
161 prompts.log.info(`${pc.green('.repomixignore')} file creation skipped. Existing file will not be modified.`);
162 return false;
163 }
164 }
165
166 const defaultIgnoreContent = `# Add patterns to ignore here, one per line
167# Example:
168# *.log
169# tmp/
170`;
171
172 await fs.writeFile(ignorePath, defaultIgnoreContent);
173 prompts.log.success(
174 pc.green('Created .repomixignore file!\n') + pc.dim(`Path: ${path.relative(rootDir, ignorePath)}`),
175 );
176
177 return true;
178};

Callers 2

runInitActionFunction · 0.85
initAction.test.tsFile · 0.85

Calls 3

infoMethod · 0.80
successMethod · 0.80
onCancelOperationFunction · 0.70

Tested by

no test coverage detected