38 lines
940 B
JavaScript
38 lines
940 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) {
|
|
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)
|
|
);
|