( options: Options, filename: string, contents: string, )
| 194 | export const ESLINT_IGNORE = "module.exports = ['build/']\n"; |
| 195 | |
| 196 | async 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 | |
| 235 | async function generateESLintConfig(options: Options): Promise<void> { |
| 236 | return generateConfigFile(options, './eslint.config.js', ESLINT_CONFIG); |
no test coverage detected
searching dependent graphs…