MCPcopy Create free account
hub / github.com/effect-app/libs / updateFile

Function updateFile

packages/eslint-codegen-model/src/cli.ts:405–448  ·  view source on GitHub ↗
(
  filePath: string,
  source: string,
  defaults?: CodegenDefaults,
  resolver?: ModelTypeResolver
)

Source from the content-addressed store, hash-verified

403}
404
405function 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
450interface ParsedArgs {
451 files: Array<string>

Callers 1

runFunction · 0.85

Calls 8

applyDefaultsFunction · 0.90
parseBlockOptionsFunction · 0.90
trimTrailingNewlineFunction · 0.90
renderPresetFunction · 0.90
indentBlockFunction · 0.90
syncModelSourceFunction · 0.85
replaceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…