file.helper.ts 1.0 KB

12345678910111213141516171819202122232425262728293031
  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. const appDataPath = process.env["AppData"] || `${process.env["HOME"] ?? ""}/Library/Application Support`;
  8. export const factorioPath = `${appDataPath}/Factorio`;
  9. export const scriptOutputPath = `${factorioPath}/script-output`;
  10. export const dataRawPath = `${scriptOutputPath}/data-raw-dump.json`;
  11. type Locale = Record<string, string>;
  12. export function getLocale(file: string): Locale {
  13. const path = `${scriptOutputPath}/${file}`;
  14. return getJsonData(path) as Locale;
  15. }
  16. export function checkIcons(icons: string[]) {
  17. const missing: string[] = [];
  18. for (const icon of icons) {
  19. const fullPath = path.resolve(scriptOutputPath, icon);
  20. if (!fs.existsSync(fullPath)) missing.push(fullPath);
  21. }
  22. if (missing.length) {
  23. console.log(`❌ ${missing.length} icon(s) are missing:`);
  24. console.log(missing.map((p) => ` • ${p}`).join("\n"));
  25. }
  26. }