desktopProviderConfig.ts 966 B

12345678910111213141516171819202122
  1. import { app } from "electron";
  2. import { join } from "node:path";
  3. import { ZCODE_ENV } from "@zcode/shared";
  4. export function resolveZCodeBuiltinProviderConfigFilePath(options?: {
  5. readonly appPath?: string;
  6. readonly env?: Readonly<Record<string, string | undefined>>;
  7. readonly isPackaged?: boolean;
  8. readonly resourcesPath?: string;
  9. }): string {
  10. const explicitPath = (options?.env ?? process.env)["ZCODE_BUILTIN_PROVIDER_CONFIG_FILE"]?.trim();
  11. if (explicitPath) return explicitPath;
  12. if (options?.isPackaged ?? app.isPackaged) {
  13. return join(
  14. options?.resourcesPath ?? process.resourcesPath,
  15. "config/provider/zcode-builtin.json",
  16. );
  17. }
  18. // 开发态没有 resources 复制步骤,必须与构建注入的产品环境读取同一份源文件。
  19. const filename = ZCODE_ENV === "production" ? "zcode-builtin.json" : "zcode-builtin.test.json";
  20. return join(options?.appPath ?? app.getAppPath(), "../../config/provider", filename);
  21. }