installer.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. """File for constants related to the installation process. (Bun/FNM/Node)."""
  2. from __future__ import annotations
  3. import os
  4. import platform
  5. from types import SimpleNamespace
  6. from .base import IS_WINDOWS, Dirs, Reflex
  7. def get_fnm_name() -> str | None:
  8. """Get the appropriate fnm executable name based on the current platform.
  9. Returns:
  10. The fnm executable name for the current platform.
  11. """
  12. platform_os = platform.system()
  13. if platform_os == "Windows":
  14. return "fnm-windows"
  15. elif platform_os == "Darwin":
  16. return "fnm-macos"
  17. elif platform_os == "Linux":
  18. machine = platform.machine()
  19. if machine == "arm" or machine.startswith("armv7"):
  20. return "fnm-arm32"
  21. elif machine.startswith("aarch") or machine.startswith("armv8"):
  22. return "fnm-arm64"
  23. return "fnm-linux"
  24. return None
  25. # Bun config.
  26. class Bun(SimpleNamespace):
  27. """Bun constants."""
  28. # The Bun version.
  29. VERSION = "1.0.4"
  30. # Min Bun Version
  31. MIN_VERSION = "0.7.0"
  32. # The directory to store the bun.
  33. ROOT_PATH = os.path.join(Reflex.DIR, "bun")
  34. # Default bun path.
  35. DEFAULT_PATH = os.path.join(ROOT_PATH, "bin", "bun")
  36. # URL to bun install script.
  37. INSTALL_URL = "https://bun.sh/install"
  38. # FNM config.
  39. class Fnm(SimpleNamespace):
  40. """FNM constants."""
  41. # The FNM version.
  42. VERSION = "1.35.1"
  43. # The directory to store fnm.
  44. DIR = os.path.join(Reflex.DIR, "fnm")
  45. FILENAME = get_fnm_name()
  46. # The fnm executable binary.
  47. EXE = os.path.join(DIR, "fnm.exe" if IS_WINDOWS else "fnm")
  48. # The URL to the fnm release binary
  49. INSTALL_URL = (
  50. f"https://github.com/Schniz/fnm/releases/download/v{VERSION}/{FILENAME}.zip"
  51. )
  52. # Node / NPM config
  53. class Node(SimpleNamespace):
  54. """Node/ NPM constants."""
  55. # The Node version.
  56. VERSION = "18.17.0"
  57. # The minimum required node version.
  58. MIN_VERSION = "16.8.0"
  59. # The node bin path.
  60. BIN_PATH = os.path.join(
  61. Fnm.DIR,
  62. "node-versions",
  63. f"v{VERSION}",
  64. "installation",
  65. "bin" if not IS_WINDOWS else "",
  66. )
  67. # The default path where node is installed.
  68. PATH = os.path.join(BIN_PATH, "node.exe" if IS_WINDOWS else "node")
  69. # The default path where npm is installed.
  70. NPM_PATH = os.path.join(BIN_PATH, "npm")
  71. class PackageJson(SimpleNamespace):
  72. """Constants used to build the package.json file."""
  73. class Commands(SimpleNamespace):
  74. """The commands to define in package.json."""
  75. DEV = "next dev"
  76. EXPORT = "next build && next export -o _static"
  77. EXPORT_SITEMAP = "next build && next-sitemap && next export -o _static"
  78. PROD = "next start"
  79. PATH = os.path.join(Dirs.WEB, "package.json")
  80. DEPENDENCIES = {
  81. "axios": "1.4.0",
  82. "focus-visible": "5.2.0",
  83. "framer-motion": "10.16.4",
  84. "json5": "2.2.3",
  85. "next": "13.5.4",
  86. "next-sitemap": "4.1.8",
  87. "next-themes": "0.2.0",
  88. "react": "18.2.0",
  89. "react-dom": "18.2.0",
  90. "socket.io-client": "4.6.1",
  91. "universal-cookie": "4.0.4",
  92. }
  93. DEV_DEPENDENCIES = {
  94. "autoprefixer": "10.4.14",
  95. "postcss": "8.4.24",
  96. }