GitRoot

craft your forge, build your project, grow your community freely
 1// SPDX-FileCopyrightText: 2025 Romain Maneschi <romain@gitroot.dev>
 2//
 3// SPDX-License-Identifier: EUPL-1.2
 4
 5import fs from 'node:fs';
 6
 7const inputPath = 'init.sh'; 
 8const outputPath = 'assembly/embedded-data.ts';
 9
10try {
11  const buffer = fs.readFileSync(inputPath);
12  const bytes = Array.from(buffer).join(', ');
13  
14  const content = `// Generated file - change init.sh and relaunch \`node embed.sj\`
15const INIT_SH: StaticArray<u8> = [${bytes}];
16let _cachedString: string | null = null;
17
18function getMyData(): Uint8Array {
19  const arr = new Uint8Array(INIT_SH.length);
20  for (let i = 0; i < INIT_SH.length; i++) {
21    arr[i] = INIT_SH[i];
22  }
23  return arr;
24}
25
26export function getInitShContent(): string {
27  if (_cachedString === null) {
28    _cachedString = String.UTF8.decode(getMyData().buffer);
29  }
30  return _cachedString as string;
31}
32`;
33  
34  fs.writeFileSync(outputPath, content);
35  console.log(`✅ ${inputPath} generated into ${outputPath}`);
36} catch (err) {
37  console.error("❌ :", err.message);
38}