( filePath: string, source: string, defaults?: CodegenDefaults, resolver?: ModelTypeResolver )
| 403 | } |
| 404 | |
| 405 | function updateFile( |
| 406 | filePath: string, |
| 407 | source: string, |
| 408 | defaults?: CodegenDefaults, |
| 409 | resolver?: ModelTypeResolver |
| 410 | ): boolean { |
| 411 | let changed = false |
| 412 | |
| 413 | const synced = syncModelSource(source) |
| 414 | if (synced !== source) { |
| 415 | changed = true |
| 416 | source = synced |
| 417 | } |
| 418 | |
| 419 | const next = source.replace( |
| 420 | blockRe, |
| 421 | (_match, indent: string, rawOptions: string, body: string, endIndent: string) => { |
| 422 | const options = applyDefaults(parseBlockOptions(rawOptions), defaults) |
| 423 | const existingContent = trimTrailingNewline(body) |
| 424 | const generatedContent = trimTrailingNewline( |
| 425 | normaliseGeneratedContent( |
| 426 | options, |
| 427 | filePath, |
| 428 | renderPreset(options, { filename: filePath, existingContent }, source, resolver) |
| 429 | ) |
| 430 | ) |
| 431 | |
| 432 | const nextBody = generatedContent.length > 0 ? `${indentBlock(generatedContent, indent)}\n` : "" |
| 433 | const replacement = `${indent}// codegen:start ${rawOptions}\n${nextBody}${endIndent}// codegen:end` |
| 434 | |
| 435 | if (replacement !== _match) { |
| 436 | changed = true |
| 437 | } |
| 438 | |
| 439 | return replacement |
| 440 | } |
| 441 | ) |
| 442 | |
| 443 | if (next !== source) { |
| 444 | fs.writeFileSync(filePath, next) |
| 445 | } |
| 446 | |
| 447 | return changed |
| 448 | } |
| 449 | |
| 450 | interface ParsedArgs { |
| 451 | files: Array<string> |
no test coverage detected
searching dependent graphs…