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

8 lines
1.1 KiB
JavaScript

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