installer.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. """File for constants related to the installation process. (Bun/FNM/Node)."""
  2. from __future__ import annotations
  3. import platform
  4. from pathlib import Path
  5. from types import SimpleNamespace
  6. from .base import IS_WINDOWS
  7. from .utils import classproperty
  8. def get_fnm_name() -> str | None:
  9. """Get the appropriate fnm executable name based on the current platform.
  10. Returns:
  11. The fnm executable name for the current platform.
  12. """
  13. platform_os = platform.system()
  14. if platform_os == "Windows":
  15. return "fnm-windows"
  16. elif platform_os == "Darwin":
  17. return "fnm-macos"
  18. elif platform_os == "Linux":
  19. machine = platform.machine()
  20. if machine == "arm" or machine.startswith("armv7"):
  21. return "fnm-arm32"
  22. elif machine.startswith("aarch") or machine.startswith("armv8"):
  23. return "fnm-arm64"
  24. return "fnm-linux"
  25. return None
  26. # Bun config.
  27. class Bun(SimpleNamespace):
  28. """Bun constants."""
  29. # The Bun version.
  30. VERSION = "1.2.0"
  31. # Min Bun Version
  32. MIN_VERSION = "1.1.0"
  33. # URL to bun install script.
  34. INSTALL_URL = "https://raw.githubusercontent.com/reflex-dev/reflex/main/scripts/bun_install.sh"
  35. # URL to windows install script.
  36. WINDOWS_INSTALL_URL = (
  37. "https://raw.githubusercontent.com/reflex-dev/reflex/main/scripts/install.ps1"
  38. )
  39. # Path of the bunfig file
  40. CONFIG_PATH = "bunfig.toml"
  41. @classproperty
  42. @classmethod
  43. def ROOT_PATH(cls):
  44. """The directory to store the bun.
  45. Returns:
  46. The directory to store the bun.
  47. """
  48. from reflex.config import environment
  49. return environment.REFLEX_DIR.get() / "bun"
  50. @classproperty
  51. @classmethod
  52. def DEFAULT_PATH(cls):
  53. """Default bun path.
  54. Returns:
  55. The default bun path.
  56. """
  57. return cls.ROOT_PATH / "bin" / ("bun" if not IS_WINDOWS else "bun.exe")
  58. DEFAULT_CONFIG = """
  59. [install]
  60. registry = "{registry}"
  61. """
  62. # FNM config.
  63. class Fnm(SimpleNamespace):
  64. """FNM constants."""
  65. # The FNM version.
  66. VERSION = "1.35.1"
  67. FILENAME = get_fnm_name()
  68. # The URL to the fnm release binary
  69. INSTALL_URL = (
  70. f"https://github.com/Schniz/fnm/releases/download/v{VERSION}/{FILENAME}.zip"
  71. )
  72. @classproperty
  73. @classmethod
  74. def DIR(cls) -> Path:
  75. """The directory to store fnm.
  76. Returns:
  77. The directory to store fnm.
  78. """
  79. from reflex.config import environment
  80. return environment.REFLEX_DIR.get() / "fnm"
  81. @classproperty
  82. @classmethod
  83. def EXE(cls):
  84. """The fnm executable binary.
  85. Returns:
  86. The fnm executable binary.
  87. """
  88. return cls.DIR / ("fnm.exe" if IS_WINDOWS else "fnm")
  89. # Node / NPM config
  90. class Node(SimpleNamespace):
  91. """Node/ NPM constants."""
  92. # The Node version.
  93. VERSION = "22.11.0"
  94. # The minimum required node version.
  95. MIN_VERSION = "18.18.0"
  96. @classproperty
  97. @classmethod
  98. def BIN_PATH(cls):
  99. """The node bin path.
  100. Returns:
  101. The node bin path.
  102. """
  103. return (
  104. Fnm.DIR
  105. / "node-versions"
  106. / f"v{cls.VERSION}"
  107. / "installation"
  108. / ("bin" if not IS_WINDOWS else "")
  109. )
  110. @classproperty
  111. @classmethod
  112. def PATH(cls):
  113. """The default path where node is installed.
  114. Returns:
  115. The default path where node is installed.
  116. """
  117. return cls.BIN_PATH / ("node.exe" if IS_WINDOWS else "node")
  118. @classproperty
  119. @classmethod
  120. def NPM_PATH(cls):
  121. """The default path where npm is installed.
  122. Returns:
  123. The default path where npm is installed.
  124. """
  125. return cls.BIN_PATH / "npm"
  126. class PackageJson(SimpleNamespace):
  127. """Constants used to build the package.json file."""
  128. class Commands(SimpleNamespace):
  129. """The commands to define in package.json."""
  130. DEV = "next dev"
  131. EXPORT = "next build"
  132. EXPORT_SITEMAP = "next build && next-sitemap"
  133. PROD = "next start"
  134. PATH = "package.json"
  135. DEPENDENCIES = {
  136. "@babel/standalone": "7.26.6",
  137. "@emotion/react": "11.14.0",
  138. "axios": "1.7.9",
  139. "json5": "2.2.3",
  140. "next": "15.1.6",
  141. "next-sitemap": "4.2.3",
  142. "next-themes": "0.4.4",
  143. "react": "18.3.1",
  144. "react-dom": "18.3.1",
  145. "react-focus-lock": "2.13.5",
  146. "socket.io-client": "4.8.1",
  147. "universal-cookie": "7.2.2",
  148. }
  149. DEV_DEPENDENCIES = {
  150. "autoprefixer": "10.4.20",
  151. "postcss": "8.5.1",
  152. "postcss-import": "16.1.0",
  153. }