Files
SGF/scripts/package-inventory-read.mjs
2026-11-02 20:29:34 +02:00

17 lines
1.2 KiB
JavaScript

import fs from 'node:fs';
import path from 'node:path';
import crypto from 'node:crypto';
const source=path.resolve('packages/inventory-read'),target=path.resolve('../compras/packages/inventory-read/releases/0.1.0');
const sha=b=>crypto.createHash('sha256').update(b).digest('hex');
const files=['bootstrap.php','src/InventoryReader.php','src/InventoryReadSession.php'];
const manifest={id:'tempo-inventory-read',version:'0.1.0',files:Object.fromEntries(files.map(p=>[p,sha(fs.readFileSync(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('Immutable local artifact differs; create another version instead of replacing it');
for(const p of files)if(sha(fs.readFileSync(path.join(target,p)))!==manifest.files[p])throw Error('Installed development artifact altered');
}else{
for(const p of files){fs.mkdirSync(path.dirname(path.join(target,p)),{recursive:true});fs.copyFileSync(path.join(source,p),path.join(target,p));}
fs.writeFileSync(path.join(target,'manifest.json'),body);
}
console.log(JSON.stringify({package:manifest.id,version:manifest.version,manifest_sha256:sha(Buffer.from(body)),files:files.length,purchasing_activation:false}));