import fs from 'node:fs'; import path from 'node:path'; import crypto from 'node:crypto'; const source=path.resolve('packages/inventory-write'),target=path.resolve('../compras/packages/inventory-write/releases/0.1.0'); const sha=p=>crypto.createHash('sha256').update(fs.readFileSync(p)).digest('hex'); const files=['bootstrap.php','src/ReceiptMovementWriter.php']; const manifest={id:'tempo-inventory-receipt-write',version:'0.1.0',files:Object.fromEntries(files.map(p=>[p,sha(path.join(source,p))]))}; const body=JSON.stringify(manifest,null,2)+'\n'; if(fs.existsSync(target)){ if(fs.readFileSync(path.join(target,'manifest.json'),'utf8')!==body)throw Error('Refused to replace immutable development artifact'); for(const file of files)if(sha(path.join(target,file))!==manifest.files[file])throw Error('Development artifact changed'); }else{ for(const file of files){fs.mkdirSync(path.dirname(path.join(target,file)),{recursive:true});fs.copyFileSync(path.join(source,file),path.join(target,file));} fs.writeFileSync(path.join(target,'manifest.json'),body); } console.log(JSON.stringify({id:manifest.id,version:manifest.version,manifest_sha256:sha(path.join(target,'manifest.json')),purchasing_activation:false}));