27 lines
2.2 KiB
JavaScript
27 lines
2.2 KiB
JavaScript
// Reads only REA materialized evidence, verifies it against the current ASAR inventory.
|
|
import fs from 'node:fs'
|
|
import path from 'node:path'
|
|
import { createHash } from 'node:crypto'
|
|
import postcss from 'postcss'
|
|
|
|
const receipt = JSON.parse(fs.readFileSync('.tmp/rea-typography-evidence.json', 'utf8'))
|
|
const extraction = receipt.extraction.normalized_result
|
|
const member = extraction.artifacts.find((item) => item.relative_path === 'tokens-Df-i-zsO.css')
|
|
const occurrence = receipt.matchedOccurrences.normalized_result.items.find((item) => item.artifact_id === member?.artifact_id)
|
|
if (!member || occurrence?.hash_status !== 'verified') throw new Error('CSS identity is not verified against the ASAR inventory')
|
|
const source = fs.readFileSync(path.join(extraction.output_root, member.relative_path), 'utf8')
|
|
if (createHash('sha256').update(source).digest('hex') !== member.sha256) throw new Error('REA materialized CSS digest mismatch')
|
|
const declarations = []
|
|
postcss.parse(source).walkDecls((declaration) => {
|
|
if (declaration.parent.selector !== ':root') return
|
|
if (/^--wb-(?:font-|spacing-)/.test(declaration.prop) || /^--wb-button-(?:font-size|line-height|icon-size|height)-(?:small|medium|large)$/.test(declaration.prop)) {
|
|
declarations.push({ name: declaration.prop, value: declaration.value, offset: declaration.source.start.offset })
|
|
}
|
|
})
|
|
const outputDirectory = 'src/renderer/src/workbuddy/typography'
|
|
fs.mkdirSync(outputDirectory, { recursive: true })
|
|
const header = `/* REA ${receipt.extraction.evidence_id}; ${member.relative_path}\n * SHA-256 ${member.sha256}\n * Matched current ASAR artifact ${occurrence.artifact_id}.\n * Generated by npm run recover:typography; unmodified selected root declarations. */\n`
|
|
fs.writeFileSync(path.join(outputDirectory, 'tokens.css'), header + ':root {\n' + declarations.map((item) => ` ${item.name}: ${item.value};`).join('\n') + '\n}\n')
|
|
fs.writeFileSync('.tmp/rea-typography/token-manifest.json', JSON.stringify({ evidenceId: receipt.extraction.evidence_id, source: member.relative_path, sha256: member.sha256, inventoryEvidence: receipt.matchedOccurrences.evidence_id, declarations }, null, 2) + '\n')
|
|
console.log(`Recovered ${declarations.length} verified typography/spacing token declarations`)
|