Files
ycode/scripts/rea/cpp-expert-prepare-directory.mjs

36 lines
2.5 KiB
JavaScript

/** Install formal provider/CLI in isolated REA runtime only; never reads original target. */
import fs from 'node:fs/promises'
import path from 'node:path'
import crypto from 'node:crypto'
const root=path.resolve('.tmp/rea-css-runtime'),hash=s=>crypto.createHash('sha256').update(s).digest('hex')
const source=await fs.readFile('scripts/rea/cpp-expert-directory-provider.mjs','utf8')
await fs.writeFile(path.join(root,'dist/artifacts/SelectedDirectoryText.js'),source)
let cli=await fs.readFile(path.join(root,'scripts/rea.mjs'),'utf8')
if(!cli.includes('inspect-selected-directory-text-root')){
const anchor='} else if (args[0] === "export-selected-artifact-text") {'
if(cli.split(anchor).length!==2)throw Error('REA CLI anchor mismatch')
cli=cli.replace(anchor,`} else if (args[0] === "inspect-selected-directory-text-root") {
const { inspectSelectedDirectory } = await import("../dist/artifacts/SelectedDirectoryText.js");
process.stdout.write(JSON.stringify(await inspectSelectedDirectory(args[1])) + "\\n");
} else if (args[0] === "export-selected-directory-text") {
const { exportSelectedDirectoryText } = await import("../dist/artifacts/SelectedDirectoryText.js");
process.stdout.write(JSON.stringify(await exportSelectedDirectoryText(args[1],args[2],JSON.parse(args[3]))) + "\\n");
${anchor}`)
await fs.writeFile(path.join(root,'scripts/rea.mjs'),cli)
}
if(!cli.includes('export-selected-directory-binary')){
const anchor='} else if (args[0] === "export-selected-artifact-text") {'
if(cli.split(anchor).length!==2)throw Error('REA CLI binary anchor mismatch')
cli=cli.replace(anchor,`} else if (args[0] === "export-selected-directory-binary") {
const { exportSelectedDirectoryBinary } = await import("../dist/artifacts/SelectedDirectoryText.js");
process.stdout.write(JSON.stringify(await exportSelectedDirectoryBinary(args[1],args[2],JSON.parse(args[3]))) + "\\n");
${anchor}`)
await fs.writeFile(path.join(root,'scripts/rea.mjs'),cli)
}
const manifestPath=path.join(root,'css-repair-manifest.json'),manifest=JSON.parse(await fs.readFile(manifestPath,'utf8'))
manifest.files.find(f=>f.path==='scripts/rea.mjs').modified_sha256=hash(cli)
manifest.files=manifest.files.filter(f=>f.path!=='dist/artifacts/SelectedDirectoryText.js')
manifest.files.push({path:'dist/artifacts/SelectedDirectoryText.js',original_sha256:null,modified_sha256:hash(source)})
await fs.writeFile(manifestPath,JSON.stringify(manifest,null,2)+'\n')
console.log(JSON.stringify({root,providerSha256:hash(source),cliSha256:hash(cli),files:manifest.files.length}))