installer.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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.1.10"
  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(
  36. ROOT_PATH, "bin", "bun" if not IS_WINDOWS else "bun.exe"
  37. )
  38. # URL to bun install script.
  39. INSTALL_URL = "https://bun.sh/install"
  40. # URL to windows install script.
  41. WINDOWS_INSTALL_URL = (
  42. "https://raw.githubusercontent.com/reflex-dev/reflex/main/scripts/install.ps1"
  43. )
  44. # FNM config.
  45. class Fnm(SimpleNamespace):
  46. """FNM constants."""
  47. # The FNM version.
  48. VERSION = "1.35.1"
  49. # The directory to store fnm.
  50. DIR = os.path.join(Reflex.DIR, "fnm")
  51. FILENAME = get_fnm_name()
  52. # The fnm executable binary.
  53. EXE = os.path.join(DIR, "fnm.exe" if IS_WINDOWS else "fnm")
  54. # The URL to the fnm release binary
  55. INSTALL_URL = (
  56. f"https://github.com/Schniz/fnm/releases/download/v{VERSION}/{FILENAME}.zip"
  57. )
  58. # Node / NPM config
  59. class Node(SimpleNamespace):
  60. """Node/ NPM constants."""
  61. # The Node version.
  62. VERSION = "18.17.0"
  63. # The minimum required node version.
  64. MIN_VERSION = "18.17.0"
  65. # The node bin path.
  66. BIN_PATH = os.path.join(
  67. Fnm.DIR,
  68. "node-versions",
  69. f"v{VERSION}",
  70. "installation",
  71. "bin" if not IS_WINDOWS else "",
  72. )
  73. # The default path where node is installed.
  74. PATH = os.path.join(BIN_PATH, "node.exe" if IS_WINDOWS else "node")
  75. # The default path where npm is installed.
  76. NPM_PATH = os.path.join(BIN_PATH, "npm")
  77. class PackageJson(SimpleNamespace):
  78. """Constants used to build the package.json file."""
  79. class Commands(SimpleNamespace):
  80. """The commands to define in package.json."""
  81. DEV = "next dev"
  82. EXPORT = "next build"
  83. EXPORT_SITEMAP = "next build && next-sitemap"
  84. PROD = "next start"
  85. PATH = os.path.join(Dirs.WEB, "package.json")
  86. DEPENDENCIES = {
  87. "@emotion/react": "11.11.1",
  88. "axios": "1.6.0",
  89. "json5": "2.2.3",
  90. "next": "14.0.1",
  91. "next-sitemap": "4.1.8",
  92. "next-themes": "0.2.1",
  93. "react": "18.2.0",
  94. "react-dom": "18.2.0",
  95. "react-focus-lock": "2.11.3",
  96. "socket.io-client": "4.6.1",
  97. "universal-cookie": "4.0.4",
  98. }
  99. DEV_DEPENDENCIES = {
  100. "autoprefixer": "10.4.14",
  101. "postcss": "8.4.31",
  102. "postcss-import": "16.1.0",
  103. }