constants.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { LogLevel } from "./types";
  2. const modeRaw = "#{{MODE}}";
  3. const branchRaw = "#{{BRANCH}}";
  4. const hostRaw = "#{{HOST}}";
  5. const buildNumberRaw = "#{{BUILD_NUMBER}}";
  6. /** The mode in which the script was built (production or development) */
  7. export const mode = (modeRaw.match(/^#{{.+}}$/) ? "production" : modeRaw) as "production" | "development";
  8. /** The branch to use in various URLs that point to the GitHub repo */
  9. export const branch = (branchRaw.match(/^#{{.+}}$/) ? "main" : branchRaw) as "main" | "develop";
  10. /** Path to the GitHub repo */
  11. export const repo = "Sv443/BetterYTM";
  12. /** Which host the userscript was installed from */
  13. export const host = (hostRaw.match(/^#{{.+}}$/) ? "github" : hostRaw) as "github" | "greasyfork" | "openuserjs";
  14. /** The build number of the userscript */
  15. export const buildNumber = (buildNumberRaw.match(/^#{{.+}}$/) ? "BUILD_ERROR!" : buildNumberRaw) as string; // asserted as generic string instead of literal
  16. /** Names of platforms by value of {@linkcode host} */
  17. export const platformNames: Record<typeof host, string> = {
  18. github: "GitHub",
  19. greasyfork: "GreasyFork",
  20. openuserjs: "OpenUserJS",
  21. };
  22. /** Default compression format used throughout BYTM */
  23. export const compressionFormat: CompressionFormat = "deflate-raw";
  24. /**
  25. * How much info should be logged to the devtools console
  26. * 0 = Debug (show everything) or 1 = Info (show only important stuff)
  27. */
  28. export const defaultLogLevel: LogLevel = mode === "production" ? LogLevel.Info : LogLevel.Debug;
  29. /** Info about the userscript, parsed from the userscript header (tools/post-build.js) */
  30. export const scriptInfo = {
  31. name: GM.info.script.name,
  32. version: GM.info.script.version,
  33. namespace: GM.info.script.namespace,
  34. } as const;