1 Commits

Author SHA1 Message Date
irene 8f860e037a feat: add BOM generator (v2 with hashes) 2026-09-09 17:53:11 +09:00
+15 -18
View File
@@ -1,22 +1,11 @@
#!/usr/bin/env node #!/usr/bin/env tsx
// BOM generator — walks asset directories, lists files, prompts for descriptions, outputs BOM.yaml // BOM generator — walks asset directories, lists files, prompts for descriptions, outputs BOM.yaml
//
// Usage:
// npx tsx scripts/bom-gen.ts [asset-root]
//
// Expected directory structure:
// audio/ — audio files
// images/ — image files
// fonts/ — font files
// videos/ — material video clips
//
// Output: BOM.yaml (YAML frontmatter-style)
import { readdirSync, statSync, writeFileSync } from "node:fs"; import { readdirSync, statSync, writeFileSync } from "node:fs";
import { resolve, relative, join } from "node:path"; import { resolve, relative } from "node:path";
import { createInterface } from "node:readline"; import { createInterface } from "node:readline";
type Asset = { path: string; size: number; description: string }; type Asset = { path: string; size: number; description: string; hash: string };
const ASSET_DIRS = ["audio", "images", "fonts", "videos"]; const ASSET_DIRS = ["audio", "images", "fonts", "videos"];
@@ -27,10 +16,16 @@ function walk(dir: string): Asset[] {
if (entry.isDirectory()) { if (entry.isDirectory()) {
assets.push(...walk(full)); assets.push(...walk(full));
} else { } else {
const s = statSync(full);
const content = readFileSync(full);
// Simple hash: first 16 chars of node hash
const { createHash } = await import("node:crypto");
const hash = createHash("md5").update(content).digest("hex").slice(0, 8);
assets.push({ assets.push({
path: relative(".", full), path: relative(".", full),
size: statSync(full).size, size: s.size,
description: "", description: "",
hash,
}); });
} }
} }
@@ -84,11 +79,13 @@ async function main() {
)).trim(); )).trim();
} }
// Build YAML manually (no dependency) // Build YAML
let yaml = "---\nbom:\n"; let yaml = "---\nbom:\n";
for (const a of all) { for (const a of all) {
const desc = a.description.replace(/"/g, '\\"'); yaml += ` - file: ${a.path}\n`;
yaml += ` ${a.path}:\n description: "${desc}"\n`; yaml += ` size: ${a.size}\n`;
yaml += ` hash: ${a.hash}\n`;
yaml += ` description: "${a.description.replace(/"/g, '\\"')}"\n`;
} }
yaml += `total_files: ${all.length}\ntotal_size: ${totalSize}\n...`; yaml += `total_files: ${all.length}\ntotal_size: ${totalSize}\n...`;