Files
HexTowerDefense3/tools/generateAssetManifest.js
2025-05-17 15:55:08 +02:00

39 lines
984 B
JavaScript

const fs = require("fs");
const path = require("path");
const basePath = path.join(__dirname, "../src/assets");
function detectType(filepath) {
const ext = path.extname(filepath).toLowerCase();
if ([".svg", ".png", ".jpg"].includes(ext)) return "image";
if ([".mp3", ".ogg", ".wav"].includes(ext)) return "audio";
return "other";
}
function walk(dir, acc = []) {
const entries = fs.readdirSync(dir);
for (const entry of entries) {
if (entry == "manifest.json") continue;
const fullPath = path.join(dir, entry);
const relPath = path.relative(basePath, fullPath).replace(/\\/g, "/");
const stat = fs.statSync(fullPath);
if (stat.isDirectory()) {
walk(fullPath, acc);
} else {
acc.push({
path: relPath,
type: detectType(fullPath),
size: stat.size,
});
}
}
return acc;
}
const assets = walk(basePath);
fs.writeFileSync(
path.join(basePath, "manifest.json"),
JSON.stringify(assets, null, 2)
);