MCPcopy Create free account
hub / github.com/TraderAlice/OpenAlice / cleanFile

Function cleanFile

scripts/migrate-order-sentinels.ts:68–88  ·  view source on GitHub ↗
(path: string)

Source from the content-addressed store, hash-verified

66}
67
68function cleanFile(path: string): { dirty: boolean; counts: Map<string, number> } {
69 const counts = new Map<string, number>()
70 const raw = readFileSync(path, 'utf8')
71 const data: CommitFile = JSON.parse(raw)
72 let dirty = false
73
74 for (const commit of data.commits ?? []) {
75 for (const op of commit.operations ?? []) {
76 if (cleanOrderObject(op.order, counts)) dirty = true
77 if (cleanOrderObject(op.changes, counts)) dirty = true
78 }
79 }
80
81 if (dirty) {
82 const serialised = JSON.stringify(data, null, 2) + '\n'
83 const tmp = path + '.tmp'
84 writeFileSync(tmp, serialised, 'utf8')
85 renameSync(tmp, path)
86 }
87 return { dirty, counts }
88}
89
90function main() {
91 let totalFiles = 0

Callers 1

mainFunction · 0.85

Calls 2

cleanOrderObjectFunction · 0.85
parseMethod · 0.80

Tested by

no test coverage detected