(hbcFilePath)
| 43 | }); |
| 44 | |
| 45 | function processHBCFile(hbcFilePath) { |
| 46 | const hashFilePath = path.join(PROJECT_ROOT, 'bundle-hash.json'); |
| 47 | |
| 48 | if (!fs.existsSync(hashFilePath)) { |
| 49 | console.warn(`[Hermesc Wrapper] ⚠️ Hash file not found: ${hashFilePath}`); |
| 50 | console.warn(`[Hermesc Wrapper] Skipping metadata injection.`); |
| 51 | process.exit(0); |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | if (!fs.existsSync(hbcFilePath)) { |
| 56 | console.warn(`[Hermesc Wrapper] ⚠️ HBC file not found: ${hbcFilePath}`); |
| 57 | console.warn(`[Hermesc Wrapper] Skipping metadata injection.`); |
| 58 | process.exit(0); |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | try { |
| 63 | const hashData = JSON.parse(fs.readFileSync(hashFilePath, 'utf8')); |
| 64 | const { contentHash } = hashData; |
| 65 | |
| 66 | console.log(`[Hermesc Wrapper] 📝 Injecting metadata into HBC...`); |
| 67 | console.log(`[Hermesc Wrapper] Hash: ${contentHash.slice(0, 16)}...`); |
| 68 | |
| 69 | const hbcBuffer = fs.readFileSync(hbcFilePath); |
| 70 | |
| 71 | const metadata = { contentHash }; |
| 72 | const metadataJson = JSON.stringify(metadata); |
| 73 | |
| 74 | const MAGIC = Buffer.from('RNUPDATE', 'utf8'); |
| 75 | const jsonBuffer = Buffer.from(metadataJson, 'utf8'); |
| 76 | const lengthBuffer = Buffer.alloc(4); |
| 77 | lengthBuffer.writeUInt32LE(jsonBuffer.length); |
| 78 | |
| 79 | const finalBuffer = Buffer.concat([ |
| 80 | hbcBuffer, |
| 81 | MAGIC, |
| 82 | jsonBuffer, |
| 83 | lengthBuffer, |
| 84 | MAGIC, |
| 85 | ]); |
| 86 | |
| 87 | fs.writeFileSync(hbcFilePath, finalBuffer); |
| 88 | |
| 89 | console.log(`[Hermesc Wrapper] ✅ Successfully injected metadata into: ${hbcFilePath}`); |
| 90 | console.log(`[Hermesc Wrapper] 🧹 Cleaning up hash file...`); |
| 91 | |
| 92 | process.exit(0); |
| 93 | } catch (error) { |
| 94 | console.error(`[Hermesc Wrapper] ❌ Failed to process HBC file:`, error); |
| 95 | process.exit(1); |
| 96 | } |
| 97 | } |
no test coverage detected