1 Commits

Author SHA1 Message Date
irene 78e8a7decf merge: feat/bom-generator into master 2026-09-09 17:53:11 +09:00
+18 -15
View File
@@ -1,11 +1,22 @@
#!/usr/bin/env tsx
#!/usr/bin/env node
// 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 { resolve, relative } from "node:path";
import { resolve, relative, join } from "node:path";
import { createInterface } from "node:readline";
type Asset = { path: string; size: number; description: string; hash: string };
type Asset = { path: string; size: number; description: string };
const ASSET_DIRS = ["audio", "images", "fonts", "videos"];
@@ -16,16 +27,10 @@ function walk(dir: string): Asset[] {
if (entry.isDirectory()) {
assets.push(...walk(full));
} 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({
path: relative(".", full),
size: s.size,
size: statSync(full).size,
description: "",
hash,
});
}
}
@@ -79,13 +84,11 @@ async function main() {
)).trim();
}
// Build YAML
// Build YAML manually (no dependency)
let yaml = "---\nbom:\n";
for (const a of all) {
yaml += ` - file: ${a.path}\n`;
yaml += ` size: ${a.size}\n`;
yaml += ` hash: ${a.hash}\n`;
yaml += ` description: "${a.description.replace(/"/g, '\\"')}"\n`;
const desc = a.description.replace(/"/g, '\\"');
yaml += ` ${a.path}:\n description: "${desc}"\n`;
}
yaml += `total_files: ${all.length}\ntotal_size: ${totalSize}\n...`;