install-local.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. # Colors for output
  4. GREEN='\033[0;32m'
  5. YELLOW='\033[1;33m'
  6. CYAN='\033[0;36m'
  7. MAGENTA='\033[0;35m'
  8. BOLD='\033[1m'
  9. DIM='\033[2m'
  10. NC='\033[0m'
  11. # Configuration
  12. INSTALL_DIR="${CLINE_INSTALL_DIR:-$HOME/.cline/cli}"
  13. PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
  14. echo ""
  15. echo -e "${MAGENTA}${BOLD}Installing Cline CLI from local build${NC}"
  16. echo ""
  17. # Always rebuild CLI to ensure latest changes
  18. echo -e "${CYAN}→${NC} ${DIM}Rebuilding CLI binaries...${NC}"
  19. cd "$PROJECT_ROOT"
  20. if npm run compile-cli 2>&1 | grep -E "(built|error|Error)" || true; then
  21. echo -e "${GREEN}✓${NC} CLI binaries rebuilt"
  22. else
  23. echo -e "${YELLOW}⚠${NC} CLI build may have issues - check output above"
  24. fi
  25. # Always rebuild standalone to ensure latest cline-core.js
  26. echo -e "${CYAN}→${NC} ${DIM}Rebuilding standalone package (this may take ~30 seconds)...${NC}"
  27. if npm run compile-standalone 2>&1 | tail -5; then
  28. echo -e "${GREEN}✓${NC} Standalone package rebuilt"
  29. else
  30. echo -e "${YELLOW}⚠${NC} Standalone build may have issues - check output above"
  31. fi
  32. echo ""
  33. echo -e "${CYAN}→${NC} ${DIM}Installing to $INSTALL_DIR${NC}"
  34. # Remove existing installation (clean install)
  35. # This ensures no conflicts with old versions and guarantees a fresh state
  36. if [ -d "$INSTALL_DIR" ]; then
  37. echo -e "${YELLOW}→${NC} ${DIM}Removing existing installation for clean install${NC}"
  38. rm -rf "$INSTALL_DIR"
  39. fi
  40. # Create installation directory
  41. mkdir -p "$INSTALL_DIR/bin"
  42. # Copy standalone package first (includes node_modules, cline-core.js, etc.)
  43. rsync -a --exclude='bin' "$PROJECT_ROOT/dist-standalone/" "$INSTALL_DIR/"
  44. # Detect platform for native modules
  45. os=$(uname -s | tr '[:upper:]' '[:lower:]')
  46. arch=$(uname -m)
  47. if [[ "$arch" == "aarch64" ]]; then arch="arm64"; fi
  48. if [[ "$arch" == "x86_64" ]]; then arch="x64"; fi
  49. platform="$os-$arch"
  50. # Copy platform-specific native modules (like better-sqlite3)
  51. if [ -d "$PROJECT_ROOT/dist-standalone/binaries/$platform/node_modules" ]; then
  52. echo -e "${CYAN}→${NC} ${DIM}Installing platform-specific modules for $platform${NC}"
  53. cp -r "$PROJECT_ROOT/dist-standalone/binaries/$platform/node_modules/"* "$INSTALL_DIR/node_modules/" 2>/dev/null || true
  54. fi
  55. # Copy binaries (this will create/overwrite the bin directory)
  56. mkdir -p "$INSTALL_DIR/bin"
  57. cp "$PROJECT_ROOT/cli/bin/cline" "$INSTALL_DIR/bin/"
  58. cp "$PROJECT_ROOT/cli/bin/cline-host" "$INSTALL_DIR/bin/"
  59. # Use system Node.js (symlink to avoid copying large binary)
  60. if command -v node >/dev/null 2>&1; then
  61. ln -sf "$(which node)" "$INSTALL_DIR/bin/node"
  62. echo -e "${GREEN}✓${NC} Linked to system Node.js: $(node --version)"
  63. else
  64. echo -e "${YELLOW}⚠${NC} Node.js not found in PATH. Please install Node.js."
  65. exit 1
  66. fi
  67. # Make binaries executable
  68. chmod +x "$INSTALL_DIR/bin/cline"
  69. chmod +x "$INSTALL_DIR/bin/cline-host"
  70. chmod +x "$INSTALL_DIR/bin/node" 2>/dev/null || true
  71. # Rebuild better-sqlite3 for system Node.js version
  72. echo -e "${CYAN}→${NC} ${DIM}Rebuilding native modules for Node.js $(node --version)...${NC}"
  73. cd "$INSTALL_DIR"
  74. npm rebuild better-sqlite3 > /dev/null 2>&1
  75. cd "$PROJECT_ROOT"
  76. echo -e "${GREEN}✓${NC} Native modules rebuilt"
  77. echo -e "${GREEN}✓${NC} Installed to ${MAGENTA}${BOLD}$INSTALL_DIR${NC}"
  78. # Configure PATH
  79. BIN_DIR="$INSTALL_DIR/bin"
  80. SHELL_CONFIG="$HOME/.zshrc"
  81. if [ -f "$HOME/.bashrc" ]; then
  82. SHELL_CONFIG="$HOME/.bashrc"
  83. fi
  84. if ! grep -q "$BIN_DIR" "$SHELL_CONFIG" 2>/dev/null; then
  85. echo "" >> "$SHELL_CONFIG"
  86. echo "# Cline CLI" >> "$SHELL_CONFIG"
  87. echo "export PATH=\"$BIN_DIR:\$PATH\"" >> "$SHELL_CONFIG"
  88. echo -e "${GREEN}✓${NC} Added to PATH in ${CYAN}$(basename $SHELL_CONFIG)${NC}"
  89. else
  90. echo -e "${GREEN}✓${NC} Already in PATH"
  91. fi
  92. echo ""
  93. echo -e "${GREEN}${BOLD}Installation complete!${NC}"
  94. echo ""
  95. echo -e "Run this to start using ${MAGENTA}${BOLD}cline${NC} immediately:"
  96. echo ""
  97. echo -e "${YELLOW}${BOLD} exec \$SHELL${NC}"
  98. echo ""
  99. echo -e "${DIM}(or just open a new terminal window)${NC}"
  100. echo ""