-
Notifications
You must be signed in to change notification settings - Fork 3
/
generateRomsList.js
32 lines (25 loc) · 933 Bytes
/
generateRomsList.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* eslint-disable import/no-extraneous-dependencies */
import fg from "fast-glob";
import fs from "fs";
const entries = fg.sync(["roms/**/*.{gb,gbc}"]);
const roms = entries.map((e) => e.replace("roms/", "")).sort();
const PATH = "../roms";
function generateOutput(items) {
const imports = items.map((item, i) => {
const key = `rom${i}`;
return {
import: `import ${key} from '${PATH}/${item}'`,
key,
name: item,
};
});
const importStatements = imports.map((item) => item.import).join("\n");
const exportObj = imports
.map((item) => `{ name: '${item.name}', url: ${item.key} }`)
.join(",");
const exportStatement = `export const roms = [${exportObj}]`;
return `/* eslint-disable simple-import-sort/imports */\n// AUTOGENERATED\n${importStatements}\n\n${exportStatement}`;
}
// TODO format with biome
const out = generateOutput(roms)
fs.writeFileSync(`${import.meta.dirname}/browser/romsList.ts`, out);