MCPcopy
hub / github.com/google/gts / generateConfigFile

Function generateConfigFile

src/init.ts:196–233  ·  view source on GitHub ↗
(
  options: Options,
  filename: string,
  contents: string,
)

Source from the content-addressed store, hash-verified

194export const ESLINT_IGNORE = "module.exports = ['build/']\n";
195
196async function generateConfigFile(
197 options: Options,
198 filename: string,
199 contents: string,
200) {
201 let existing;
202 try {
203 existing = await read(filename, 'utf8');
204 } catch (e) {
205 const err = e as Error & {code?: string};
206 if (err.code === 'ENOENT') {
207 /* not found, create it. */
208 } else {
209 throw new Error(`Unknown error reading ${filename}: ${err.message}`);
210 }
211 }
212
213 let writeFile = true;
214 if (existing && existing === contents) {
215 options.logger.log(`No edits needed in ${filename}`);
216 return;
217 } else if (existing) {
218 writeFile = await query(
219 `${chalk.bold(filename)} already exists`,
220 'Overwrite',
221 false,
222 options,
223 );
224 }
225
226 if (writeFile) {
227 options.logger.log(`Writing ${filename}...`);
228 if (!options.dryRun) {
229 await writeFileAtomic(filename, contents);
230 }
231 options.logger.log(contents);
232 }
233}
234
235async function generateESLintConfig(options: Options): Promise<void> {
236 return generateConfigFile(options, './eslint.config.js', ESLINT_CONFIG);

Callers 5

generateESLintConfigFunction · 0.85
generateESLintIgnoreFunction · 0.85
generateTsConfigFunction · 0.85
generatePrettierConfigFunction · 0.85
generateEditorConfigFunction · 0.85

Calls 1

queryFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…