Fix same-vault Graphify semantic merge
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env node
|
||||
import { promises as fs } from 'node:fs'
|
||||
import { existsSync } from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import {
|
||||
graphStats,
|
||||
normalizeGraphObject,
|
||||
readGraph,
|
||||
writeGraph
|
||||
} from './mnemazine-graph-utils.mjs'
|
||||
|
||||
const argv = process.argv.slice(2)
|
||||
|
||||
function arg(name, fallback = '') {
|
||||
const hit = argv.find(item => item === `--${name}` || item.startsWith(`--${name}=`))
|
||||
if (!hit) return fallback
|
||||
return hit.includes('=') ? hit.split('=').slice(1).join('=') : argv[argv.indexOf(hit) + 1] || fallback
|
||||
}
|
||||
|
||||
function hasFlag(name) {
|
||||
return argv.includes(`--${name}`)
|
||||
}
|
||||
|
||||
const graphPath = path.resolve(arg('graph', path.join(process.env.HOME || '.', 'Мозг/graphify-out/graph.json')))
|
||||
const outPath = arg('out', '')
|
||||
const apply = hasFlag('apply')
|
||||
|
||||
async function main() {
|
||||
if (!existsSync(graphPath)) throw new Error(`graph not found: ${graphPath}`)
|
||||
const beforeGraph = await readGraph(graphPath)
|
||||
const before = graphStats(beforeGraph)
|
||||
const repaired = normalizeGraphObject(beforeGraph)
|
||||
const after = graphStats(repaired.graph)
|
||||
const target = apply ? graphPath : path.resolve(outPath || `${graphPath}.repaired`)
|
||||
|
||||
await fs.mkdir(path.dirname(target), { recursive: true })
|
||||
await writeGraph(target, repaired.graph)
|
||||
|
||||
const summary = {
|
||||
ok: true,
|
||||
applied: apply,
|
||||
graph: graphPath,
|
||||
out: target,
|
||||
before,
|
||||
after,
|
||||
repair: repaired.stats
|
||||
}
|
||||
console.log(JSON.stringify(summary, null, 2))
|
||||
}
|
||||
|
||||
main().catch(error => {
|
||||
console.error(error.message || error)
|
||||
process.exit(1)
|
||||
})
|
||||
Reference in New Issue
Block a user