installer.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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.1.29"
  31. # Min Bun Version
  32. MIN_VERSION = "0.7.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 / "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. # FNM config.
  59. class Fnm(SimpleNamespace):
  60. """FNM constants."""
  61. # The FNM version.
  62. VERSION = "1.35.1"
  63. FILENAME = get_fnm_name()
  64. # The URL to the fnm release binary
  65. INSTALL_URL = (
  66. f"https://github.com/Schniz/fnm/releases/download/v{VERSION}/{FILENAME}.zip"
  67. )
  68. @classproperty
  69. @classmethod
  70. def DIR(cls) -> Path:
  71. """The directory to store fnm.
  72. Returns:
  73. The directory to store fnm.
  74. """
  75. from reflex.config import environment
  76. return environment.REFLEX_DIR / "fnm"
  77. @classproperty
  78. @classmethod
  79. def EXE(cls):
  80. """The fnm executable binary.
  81. Returns:
  82. The fnm executable binary.
  83. """
  84. return cls.DIR / ("fnm.exe" if IS_WINDOWS else "fnm")
  85. # Node / NPM config
  86. class Node(SimpleNamespace):
  87. """Node/ NPM constants."""
  88. # The Node version.
  89. VERSION = "22.10.0"
  90. # The minimum required node version.
  91. MIN_VERSION = "18.17.0"
  92. @classproperty
  93. @classmethod
  94. def BIN_PATH(cls):
  95. """The node bin path.
  96. Returns:
  97. The node bin path.
  98. """
  99. return (
  100. Fnm.DIR
  101. / "node-versions"
  102. / f"v{cls.VERSION}"
  103. / "installation"
  104. / ("bin" if not IS_WINDOWS else "")
  105. )
  106. @classproperty
  107. @classmethod
  108. def PATH(cls):
  109. """The default path where node is installed.
  110. Returns:
  111. The default path where node is installed.
  112. """
  113. return cls.BIN_PATH / ("node.exe" if IS_WINDOWS else "node")
  114. @classproperty
  115. @classmethod
  116. def NPM_PATH(cls):
  117. """The default path where npm is installed.
  118. Returns:
  119. The default path where npm is installed.
  120. """
  121. return cls.BIN_PATH / "npm"
  122. class PackageJson(SimpleNamespace):
  123. """Constants used to build the package.json file."""
  124. class Commands(SimpleNamespace):
  125. """The commands to define in package.json."""
  126. DEV = "next dev"
  127. EXPORT = "next build"
  128. EXPORT_SITEMAP = "next build && next-sitemap"
  129. PROD = "next start"
  130. PATH = "package.json"
  131. DEPENDENCIES = {
  132. "@babel/standalone": "7.25.8",
  133. "@emotion/react": "11.13.3",
  134. "axios": "1.7.7",
  135. "json5": "2.2.3",
  136. "next": "14.2.15",
  137. "next-sitemap": "4.2.3",
  138. "next-themes": "0.3.0",
  139. "react": "18.3.1",
  140. "react-dom": "18.3.1",
  141. "react-focus-lock": "2.13.2",
  142. "socket.io-client": "4.8.0",
  143. "universal-cookie": "7.2.1",
  144. }
  145. DEV_DEPENDENCIES = {
  146. "autoprefixer": "10.4.20",
  147. "postcss": "8.4.47",
  148. "postcss-import": "16.1.0",
  149. }