Files
ycode/scripts/rea/expert-package-export.mjs
T

22 lines
1.4 KiB
JavaScript

/** Exact public REA export. Does not read ASAR or installed files itself. */
import fs from 'node:fs'
import { spawnSync } from 'node:child_process'
import crypto from 'node:crypto'
const inventory = JSON.parse(fs.readFileSync('.tmp/rea-expert-package-inventory.json', 'utf8'))
const paths = process.argv.slice(2)
if (!paths.length) throw new Error('Select exact paths')
const r = spawnSync(process.execPath, ['.tmp/rea-css-runtime/scripts/rea.mjs', 'export-selected-artifact-text',
inventory.inputPath, inventory.rootSha256, JSON.stringify(paths)], {encoding:'utf8', maxBuffer:32*1024*1024})
if (r.status !== 0) throw new Error(r.stderr || r.stdout || `REA exited ${r.status}`)
const evidence = JSON.parse(r.stdout)
if (evidence.normalized_result.root_sha256 !== inventory.rootSha256) throw new Error('REA root mismatch')
for (const file of evidence.normalized_result.files) {
const sha = crypto.createHash('sha256').update(file.text).digest('hex')
if (sha !== file.sha256) throw new Error(`Text SHA mismatch: ${file.path}`)
const expected = inventory.files.find(item => item.path === file.path)
if (expected && expected.sha256 !== sha) throw new Error(`Inventory SHA mismatch: ${file.path}`)
}
const output = `.tmp/rea-expert-package-${evidence.evidence_id}.json`
fs.writeFileSync(output,JSON.stringify(evidence))
console.log(JSON.stringify({output,evidenceId:evidence.evidence_id,files:evidence.normalized_result.files.map(({text,...metadata})=>metadata)},null,2))