file.helper.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import fs from "fs";
  2. import path from "path";
  3. export function getJsonData(file: string): unknown {
  4. const str = fs.readFileSync(file).toString();
  5. return JSON.parse(str);
  6. }
  7. export let factorioPath: string = "";
  8. var isWin = process.platform === "win32";
  9. if (isWin) {
  10. const appDataPath = process.env["AppData"] || `${process.env["HOME"] ?? ""}/Library/Application Support`;
  11. factorioPath = `${appDataPath}/Factorio`;
  12. } else {
  13. factorioPath = `/home/clovis/shared/Factorio`;
  14. }
  15. export const scriptOutputPath = `${factorioPath}/script-output`;
  16. export const dataRawPath = `${scriptOutputPath}/data-raw-dump.json`;
  17. type Locale = Record<string, string>;
  18. export function getLocale(file: string): Locale {
  19. const path = `${scriptOutputPath}/${file}`;
  20. return getJsonData(path) as Locale;
  21. }
  22. export function checkIcons(icons: string[]) {
  23. const missing: string[] = [];
  24. for (const icon of icons) {
  25. const fullPath = path.resolve(scriptOutputPath, icon);
  26. if (!fs.existsSync(fullPath)) missing.push(fullPath);
  27. }
  28. if (missing.length > 0) {
  29. console.log(`❌ ${missing.length} icon(s) are missing:`);
  30. console.log(missing.map((p) => ` • ${p}`).join("\n"));
  31. }
  32. }