Files
SGF/scripts/package-inventory-return.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-return'),target=path.resolve('../compras/packages/inventory-return/releases/0.1.0');
const sha=p=>crypto.createHash('sha256').update(fs.readFileSync(p)).digest('hex');
const files=['bootstrap.php','src/DeliveryReturnWriter.php'];const manifest={id:'tempo-inventory-return',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 return artifact differs');for(const f of files)if(sha(path.join(target,f))!==manifest.files[f])throw Error('Return 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')),native_return_command_integrated:false,purchasing_activation:false}));