| 64 | } |
| 65 | |
| 66 | async function main() { |
| 67 | const args = parseArgs(process.argv); |
| 68 | const repoRoot = resolve(args.repoRoot); |
| 69 | const ref = args.ref; // for filesystem backend, ref is informational only |
| 70 | const outDir = resolve(args.outDir); |
| 71 | if (!existsSync(outDir)) mkdirSync(outDir, { recursive: true }); |
| 72 | |
| 73 | const dependencies = await loadJSON(join(repoRoot, 'Support', 'Dependencies', 'Dependencies.json')); |
| 74 | |
| 75 | // Dynamic import of ESM core |
| 76 | const coreUrl = pathToFileURL(join(__dirname, 'amalgamationCore.js')).href; |
| 77 | const { buildSingleLibraryHeadersUsingContext } = await import(coreUrl); |
| 78 | |
| 79 | // Filesystem backend context |
| 80 | const ctx = { |
| 81 | ref, |
| 82 | orderDir: 'Support/SingleFileLibs', |
| 83 | dependencies, |
| 84 | // Use system-appropriate line endings |
| 85 | lineEndings: process.platform === 'win32' ? 'crlf' : 'lf', |
| 86 | async listTree() { |
| 87 | const roots = [ |
| 88 | join(repoRoot, 'Libraries'), |
| 89 | join(repoRoot, 'LibrariesExtra'), |
| 90 | join(repoRoot, 'Support', 'SingleFileLibs'), // for per-library order JSON files |
| 91 | ]; |
| 92 | const files = []; |
| 93 | for (const r of roots) { |
| 94 | if (!existsSync(r)) continue; |
| 95 | files.push(...listFilesRecursive(r)); |
| 96 | } |
| 97 | const rel = files.map(f => ({ type: 'blob', path: f.substring(repoRoot.length + 1).replaceAll('\\', '/') })); |
| 98 | return rel; |
| 99 | }, |
| 100 | async readFile(_ref, path) { |
| 101 | return await readText(join(repoRoot, path)); |
| 102 | }, |
| 103 | async getVersionString(_ref) { |
| 104 | // Try to mimic Python version: <latest tag> (<short sha>) |
| 105 | // For simplicity here, return just the short HEAD sha via git, falling back to 'unknown' |
| 106 | try { |
| 107 | const { execSync } = require('node:child_process'); |
| 108 | const tag = execSync('git describe --tags --abbrev=0', { cwd: repoRoot, stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim(); |
| 109 | const sha = execSync('git rev-parse --short HEAD', { cwd: repoRoot, stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim(); |
| 110 | return `${tag} (${sha})`; |
| 111 | } catch { return 'unknown'; } |
| 112 | }, |
| 113 | }; |
| 114 | |
| 115 | const libraries = args.all ? Object.keys(dependencies) : [args.library]; |
| 116 | for (const lib of libraries) { |
| 117 | process.stdout.write(`Amalgamating ${lib}... `); |
| 118 | const content = await buildSingleLibraryHeadersUsingContext(lib, ctx); |
| 119 | const outPath = join(outDir, `SaneCpp${lib}.h`); |
| 120 | const standaloneOutPath = join(outDir, `SaneCpp${lib}Standalone.h`); |
| 121 | await writeText(outPath, content.regular); |
| 122 | await writeText(standaloneOutPath, content.standalone); |
| 123 | console.log('done'); |