forked from Bitcoindefi/OpenAO
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexportFrontendNpcs.ts
More file actions
52 lines (42 loc) · 1.46 KB
/
Copy pathexportFrontendNpcs.ts
File metadata and controls
52 lines (42 loc) · 1.46 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import fs from "fs";
import path from "path";
import pool from "../db";
import { exportFrontendNpcs } from "../repositories/gameNpcs";
function getOptionValue(name: string): string | null {
const index = process.argv.findIndex(
(argument) => argument === `--${name}`,
);
if (index < 0) {
return null;
}
const nextValue = process.argv[index + 1];
return nextValue?.trim() ? nextValue.trim() : null;
}
function resolveOutputPath(): string {
const configuredPath = getOptionValue("output");
if (configuredPath) {
return path.resolve(process.cwd(), configuredPath);
}
return path.resolve(__dirname, "../jsons/npcs.frontend.json");
}
function formatBytes(bytes: number): string {
return `${(bytes / 1024).toFixed(1)} KB`;
}
async function main(): Promise<void> {
const outputPath = resolveOutputPath();
const npcs = await exportFrontendNpcs();
const json = `${JSON.stringify(npcs)}\n`;
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
fs.writeFileSync(outputPath, json, "utf8");
console.log(`NPCs frontend exportados a ${outputPath}`);
console.log(`Total NPCs: ${Object.keys(npcs).length}`);
console.log(`Tamanio: ${formatBytes(Buffer.byteLength(json, "utf8"))}`);
}
void main()
.catch((error) => {
console.error("No se pudo exportar el npcs.json de frontend", error);
process.exit(1);
})
.finally(async () => {
await pool.end();
});