From 746b84883e3d06eea20786fde17fa29662bdbbeb Mon Sep 17 00:00:00 2001 From: Boki Date: Tue, 10 Jun 2025 20:05:03 -0400 Subject: [PATCH] added sh versions of the scripts --- bun.lock | 11 +- package.json | 61 ++++++---- scripts/build-all.bat | 85 -------------- scripts/build-all.sh | 150 ++++++++++++++++++++++++ scripts/build-libs.sh | 62 ++++++++++ scripts/clean.sh | 254 ++++++++++++++++++++++++++++++++++++++++ scripts/docker.sh | 190 ++++++++++++++++++++++++++++++ scripts/verify-build.sh | 160 +++++++++++++++++++++++++ 8 files changed, 865 insertions(+), 108 deletions(-) delete mode 100644 scripts/build-all.bat create mode 100755 scripts/build-all.sh create mode 100755 scripts/build-libs.sh create mode 100755 scripts/clean.sh create mode 100755 scripts/docker.sh create mode 100755 scripts/verify-build.sh diff --git a/bun.lock b/bun.lock index 5ad9dff..1c77990 100644 --- a/bun.lock +++ b/bun.lock @@ -381,6 +381,9 @@ }, }, "trustedDependencies": [ + "@tailwindcss/oxide", + "esbuild", + "mongodb-memory-server", "mongodb", ], "packages": { @@ -882,7 +885,7 @@ "@types/mongodb": ["@types/mongodb@4.0.7", "", { "dependencies": { "mongodb": "*" } }, "sha512-lPUYPpzA43baXqnd36cZ9xxorprybxXDzteVKCPAdp14ppHtFJHnXYvNpmBvtMUTb5fKXVv6sVbzo1LHkWhJlw=="], - "@types/node": ["@types/node@22.15.30", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-6Q7lr06bEHdlfplU6YRbgG1SFBdlsfNC4/lX+SkhiTs0cpJkOElmWls8PxDFv4yY/xKb8Y6SO0OmSX4wgqTZbA=="], + "@types/node": ["@types/node@22.15.31", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-jnVe5ULKl6tijxUhvQeNbQG/84fHfg+yMak02cT8QVhBx/F05rAVxCGBYYTh2EKz22D6JF5ktXuNwdx7b9iEGw=="], "@types/pg": ["@types/pg@8.15.4", "", { "dependencies": { "@types/node": "*", "pg-protocol": "*", "pg-types": "^2.2.0" } }, "sha512-I6UNVBAoYbvuWkkU3oosC8yxqH21f4/Jc4DK71JLG3dT2mdlGe1z+ep/LQGXaKaOgcvUrsQoPRqfgtMcvZiJhg=="], @@ -1266,7 +1269,7 @@ "fastq": ["fastq@1.19.1", "", { "dependencies": { "reusify": "^1.0.4" } }, "sha512-GwLTyxkCXjXbxqIhTsMI2Nui8huMPtnxg7krajPJAjnEG/iiOS7i+zCtWGZR9G0NBKbXKh6X9m9UIsYX/N6vvQ=="], - "fdir": ["fdir@6.4.5", "", { "peerDependencies": { "picomatch": "^3 || ^4" }, "optionalPeers": ["picomatch"] }, "sha512-4BG7puHpVsIYxZUbiUE3RqGloLaSSwzYie5jvasC4LWuBWzZawynvYouhjbQKw2JuIGYdm0DzIxl8iVidKlUEw=="], + "fdir": ["fdir@6.4.6", "", { "peerDependencies": { "picomatch": "^3 || ^4" }, "optionalPeers": ["picomatch"] }, "sha512-hiFoqpyZcfNm1yc4u8oWCf9A2c4D3QjCrks3zmoVKVxpQRzmPNar1hUJcBG2RQHvEVGDN+Jm81ZheVLAQMK6+w=="], "file-entry-cache": ["file-entry-cache@6.0.1", "", { "dependencies": { "flat-cache": "^3.0.4" } }, "sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg=="], @@ -1906,7 +1909,7 @@ "socket.io-parser": ["socket.io-parser@4.2.4", "", { "dependencies": { "@socket.io/component-emitter": "~3.1.0", "debug": "~4.3.1" } }, "sha512-/GbIKmo8ioc+NIWIhwdecY0ge+qVBSMdgxGygevmdHj24bsfgtCmcUUcQ5ZzcylGFHsN3k4HB4Cgkl96KVnuew=="], - "socks": ["socks@2.8.4", "", { "dependencies": { "ip-address": "^9.0.5", "smart-buffer": "^4.2.0" } }, "sha512-D3YaD0aRxR3mEcqnidIs7ReYJFVzWdd6fXJYUM8ixcQcJRGTka/b3saV0KflYhyVJXKhb947GndU35SxYNResQ=="], + "socks": ["socks@2.8.5", "", { "dependencies": { "ip-address": "^9.0.5", "smart-buffer": "^4.2.0" } }, "sha512-iF+tNDQla22geJdTyJB1wM/qrX9DMRwWrciEPwWLPRWAUEM8sQiyxgckLxWT1f7+9VabJS0jTGGr4QgBuvi6Ww=="], "socks-proxy-agent": ["socks-proxy-agent@8.0.5", "", { "dependencies": { "agent-base": "^7.1.2", "debug": "^4.3.4", "socks": "^2.8.3" } }, "sha512-HehCEsotFqbPW9sJ8WVYB6UbmIMv7kUUORIF2Nncq4VQvBfNBLibW9YZR5dlYCSUhwcD628pRllm7n+E+YTzJw=="], @@ -2134,6 +2137,8 @@ "@inquirer/core/wrap-ansi": ["wrap-ansi@6.2.0", "", { "dependencies": { "ansi-styles": "^4.0.0", "string-width": "^4.1.0", "strip-ansi": "^6.0.0" } }, "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA=="], + "@inquirer/prompts/@inquirer/confirm": ["@inquirer/confirm@5.1.12", "", { "dependencies": { "@inquirer/core": "^10.1.13", "@inquirer/type": "^3.0.7" }, "peerDependencies": { "@types/node": ">=18" }, "optionalPeers": ["@types/node"] }, "sha512-dpq+ielV9/bqgXRUbNH//KsY6WEw9DrGPmipkpmgC1Y46cwuBTNx7PXFWTjc3MQ+urcc0QxoVHcMI0FW4Ok0hg=="], + "@isaacs/cliui/string-width": ["string-width@5.1.2", "", { "dependencies": { "eastasianwidth": "^0.2.0", "emoji-regex": "^9.2.2", "strip-ansi": "^7.0.1" } }, "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA=="], "@isaacs/cliui/strip-ansi": ["strip-ansi@7.1.0", "", { "dependencies": { "ansi-regex": "^6.0.1" } }, "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ=="], diff --git a/package.json b/package.json index bdef4f1..b10f52d 100644 --- a/package.json +++ b/package.json @@ -6,10 +6,14 @@ "type": "module", "scripts": { "dev": "turbo run dev", - "build": "powershell ./scripts/build-all.ps1", - "build:all:clean": "powershell ./scripts/build-all.ps1 -Clean", - "build:all:verbose": "powershell ./scripts/build-all.ps1 -Verbose", - "build:libs": "powershell ./scripts/build-libs.ps1", + "build": "./scripts/build-all.sh", + "build:all:clean": "./scripts/build-all.sh --clean", + "build:all:verbose": "./scripts/build-all.sh --verbose", + "build:libs": "./scripts/build-libs.sh", + "build:win": "powershell ./scripts/build-all.ps1", + "build:win:clean": "powershell ./scripts/build-all.ps1 -Clean", + "build:win:verbose": "powershell ./scripts/build-all.ps1 -Verbose", + "build:libs:win": "powershell ./scripts/build-libs.ps1", "test": "turbo run test", "test:watch": "bun test --watch", "test:coverage": "bun test --coverage", @@ -21,22 +25,39 @@ "lint": "turbo run lint", "start": "turbo run start", "clean": "turbo run clean", - "clean:cache": "powershell ./scripts/clean.ps1 -cache", - "clean:dist": "powershell ./scripts/clean.ps1 -dist", - "clean:modules": "powershell ./scripts/clean.ps1 -modules", - "clean:all": "powershell ./scripts/clean.ps1 -all", - "clean:all:force": "powershell ./scripts/clean.ps1 -all -force", - "clean:fresh": "powershell ./scripts/clean.ps1 -fresh", - "clean:fresh:force": "powershell ./scripts/clean.ps1 -fresh -force", + "clean:cache": "./scripts/clean.sh --cache", + "clean:dist": "./scripts/clean.sh --dist", + "clean:modules": "./scripts/clean.sh --modules", + "clean:all": "./scripts/clean.sh --all", + "clean:all:force": "./scripts/clean.sh --all --force", + "clean:fresh": "./scripts/clean.sh --fresh", + "clean:fresh:force": "./scripts/clean.sh --fresh --force", + "clean:cache:win": "powershell ./scripts/clean.ps1 -cache", + "clean:dist:win": "powershell ./scripts/clean.ps1 -dist", + "clean:modules:win": "powershell ./scripts/clean.ps1 -modules", + "clean:all:win": "powershell ./scripts/clean.ps1 -all", + "clean:all:force:win": "powershell ./scripts/clean.ps1 -all -force", + "clean:fresh:win": "powershell ./scripts/clean.ps1 -fresh", + "clean:fresh:force:win": "powershell ./scripts/clean.ps1 -fresh -force", "backtest": "turbo run backtest", - "docker:start": "powershell ./scripts/docker.ps1 start", - "docker:stop": "powershell ./scripts/docker.ps1 stop", - "docker:restart": "powershell ./scripts/docker.ps1 restart", - "docker:status": "powershell ./scripts/docker.ps1 status", - "docker:logs": "powershell ./scripts/docker.ps1 logs", - "docker:reset": "powershell ./scripts/docker.ps1 reset", - "docker:admin": "powershell ./scripts/docker.ps1 admin", - "docker:monitoring": "powershell ./scripts/docker.ps1 monitoring", + "docker:start": "./scripts/docker.sh start", + "docker:stop": "./scripts/docker.sh stop", + "docker:restart": "./scripts/docker.sh restart", + "docker:status": "./scripts/docker.sh status", + "docker:logs": "./scripts/docker.sh logs", + "docker:reset": "./scripts/docker.sh reset", + "docker:admin": "./scripts/docker.sh admin", + "docker:monitoring": "./scripts/docker.sh monitoring", + "docker:start:win": "powershell ./scripts/docker.ps1 start", + "docker:stop:win": "powershell ./scripts/docker.ps1 stop", + "docker:restart:win": "powershell ./scripts/docker.ps1 restart", + "docker:status:win": "powershell ./scripts/docker.ps1 status", + "docker:logs:win": "powershell ./scripts/docker.ps1 logs", + "docker:reset:win": "powershell ./scripts/docker.ps1 reset", + "docker:admin:win": "powershell ./scripts/docker.ps1 admin", + "docker:monitoring:win": "powershell ./scripts/docker.ps1 monitoring", + "verify:build": "./scripts/verify-build.sh", + "verify:build:win": "powershell ./scripts/verify-build.ps1", "infra:up": "docker-compose up -d dragonfly postgres questdb mongodb", "infra:down": "docker-compose down", "infra:reset": "docker-compose down -v && docker-compose up -d dragonfly postgres questdb mongodb", @@ -72,5 +93,5 @@ "bullmq": "^5.53.2", "ioredis": "^5.6.1" }, - "trustedDependencies": ["mongodb"] + "trustedDependencies": ["@tailwindcss/oxide", "esbuild", "mongodb", "mongodb-memory-server"] } diff --git a/scripts/build-all.bat b/scripts/build-all.bat deleted file mode 100644 index 0a1f89b..0000000 --- a/scripts/build-all.bat +++ /dev/null @@ -1,85 +0,0 @@ -@echo off -REM Build All Script for Stock Bot (Batch version) -REM Builds libraries first, then apps with Turbo, then dashboard with Angular CLI - -echo ๐Ÿš€ Starting complete build process... - -REM Store original directory -set "ORIGINAL_DIR=%CD%" -cd /d "g:\repos\stock-bot" - -REM Step 1: Build libraries first -echo ๐Ÿ“š Building libraries... -call powershell ./scripts/build-libs.ps1 -if %ERRORLEVEL% NEQ 0 ( - echo โŒ Library build failed - cd /d "%ORIGINAL_DIR%" - exit /b 1 -) - -REM Step 2: Build apps with Turbo (excluding dashboard) -echo ๐Ÿ—๏ธ Building applications with Turbo... - -REM Check if each app exists and build individually -if exist "apps\data-service" ( - echo Building data-service... - call turbo run build --filter="./apps/data-service" - if %ERRORLEVEL% NEQ 0 ( - echo โŒ data-service build failed - cd /d "%ORIGINAL_DIR%" - exit /b 1 - ) -) - -if exist "apps\execution-service" ( - echo Building execution-service... - call turbo run build --filter="./apps/execution-service" - if %ERRORLEVEL% NEQ 0 ( - echo โŒ execution-service build failed - cd /d "%ORIGINAL_DIR%" - exit /b 1 - ) -) - -if exist "apps\portfolio-service" ( - echo Building portfolio-service... - call turbo run build --filter="./apps/portfolio-service" - if %ERRORLEVEL% NEQ 0 ( - echo โŒ portfolio-service build failed - cd /d "%ORIGINAL_DIR%" - exit /b 1 - ) -) - -if exist "apps\processing-service" ( - echo Building processing-service... - call turbo run build --filter="./apps/processing-service" - if %ERRORLEVEL% NEQ 0 ( - echo โŒ processing-service build failed - cd /d "%ORIGINAL_DIR%" - exit /b 1 - ) -) - -if exist "apps\strategy-service" ( - echo Building strategy-service... - call turbo run build --filter="./apps/strategy-service" - if %ERRORLEVEL% NEQ 0 ( - echo โŒ strategy-service build failed - cd /d "%ORIGINAL_DIR%" - exit /b 1 - ) -) - -REM Step 3: Build dashboard with Angular CLI -echo ๐ŸŽจ Building Angular dashboard... -cd apps\dashboard -call ng build --configuration production -if %ERRORLEVEL% NEQ 0 ( - echo โŒ Dashboard build failed - cd /d "%ORIGINAL_DIR%" - exit /b 1 -) - -cd /d "%ORIGINAL_DIR%" -echo ๐ŸŽ‰ Complete build finished successfully! diff --git a/scripts/build-all.sh b/scripts/build-all.sh new file mode 100755 index 0000000..4d05992 --- /dev/null +++ b/scripts/build-all.sh @@ -0,0 +1,150 @@ +#!/bin/bash + +# Build All Script for Stock Bot +# Builds libraries first, then apps with Turbo, then dashboard with Angular CLI + +set -e + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +CYAN='\033[0;36m' +GRAY='\033[0;37m' +NC='\033[0m' # No Color + +# Default options +CLEAN=false +VERBOSE=false + +# Parse command line arguments +while [[ $# -gt 0 ]]; do + case $1 in + --clean|-c) + CLEAN=true + shift + ;; + --verbose|-v) + VERBOSE=true + shift + ;; + --help|-h) + echo "Usage: $0 [--clean] [--verbose]" + echo " --clean, -c Clean previous builds before building" + echo " --verbose, -v Show verbose output" + echo " --help, -h Show this help message" + exit 0 + ;; + *) + echo "Unknown option: $1" + echo "Use --help for usage information" + exit 1 + ;; + esac +done + +echo -e "${CYAN}๐Ÿš€ Starting complete build process...${NC}" + +# Store original location +ORIGINAL_DIR=$(pwd) +cd "/home/boki/stock-bot" + +cleanup() { + cd "$ORIGINAL_DIR" +} + +# Set up cleanup on exit +trap cleanup EXIT + +# Step 1: Clean if requested +if [ "$CLEAN" = true ]; then + echo -e "${YELLOW}๐Ÿงน Cleaning previous builds...${NC}" + ./scripts/clean.sh --dist + if [ $? -ne 0 ]; then + echo -e "${RED}โŒ Clean failed${NC}" + exit 1 + fi +fi + +# Step 2: Build libraries first +echo -e "${GREEN}๐Ÿ“š Building libraries...${NC}" +./scripts/build-libs.sh +if [ $? -ne 0 ]; then + echo -e "${RED}โŒ Library build failed${NC}" + exit 1 +fi + +# Step 3: Build apps with Turbo (excluding dashboard) +echo -e "${GREEN}๐Ÿ—๏ธ Building applications with Turbo...${NC}" + +# Get list of apps excluding dashboard +if [ -d "apps" ]; then + app_dirs=$(find apps -maxdepth 1 -type d -name "*" ! -name "dashboard" ! -name "apps" | sort) + + if [ -n "$app_dirs" ]; then + # Build each app individually to avoid filter syntax issues + for app_dir in $app_dirs; do + app_name=$(basename "$app_dir") + app_path="./apps/$app_name" + echo -e "${CYAN} Building $app_name...${NC}" + + turbo_cmd="turbo run build --filter=$app_path" + + if [ "$VERBOSE" = true ]; then + echo -e "${GRAY} Running: $turbo_cmd${NC}" + fi + + eval $turbo_cmd + if [ $? -ne 0 ]; then + echo -e "${RED}โŒ Failed to build app: $app_name${NC}" + exit 1 + fi + done + + app_names=$(echo "$app_dirs" | xargs -n1 basename | tr '\n' ', ' | sed 's/,$//') + echo -e "${GREEN}โœ… Apps built successfully: $app_names${NC}" + else + echo -e "${YELLOW}โ„น๏ธ No non-dashboard apps found to build with Turbo${NC}" + fi +fi + +# Step 4: Build dashboard with Angular CLI +dashboard_path="apps/dashboard" +if [ -d "$dashboard_path" ]; then + echo -e "${GREEN}๐ŸŽจ Building Angular dashboard...${NC}" + + cd "$dashboard_path" + + # Check if ng is available + if ! command -v ng &> /dev/null; then + echo -e "${RED}โŒ Angular CLI not found. Installing...${NC}" + npm install -g @angular/cli + if [ $? -ne 0 ]; then + echo -e "${RED}โŒ Failed to install Angular CLI${NC}" + exit 1 + fi + fi + + # Build dashboard + ng build --configuration production + if [ $? -ne 0 ]; then + echo -e "${RED}โŒ Dashboard build failed${NC}" + exit 1 + fi + + echo -e "${GREEN}โœ… Dashboard built successfully${NC}" + cd "$ORIGINAL_DIR" +else + echo -e "${YELLOW}โš ๏ธ Dashboard not found at $dashboard_path${NC}" +fi + +echo -e "${GREEN}๐ŸŽ‰ Complete build finished successfully!${NC}" +echo "" +echo -e "${CYAN}Build Summary:${NC}" +echo -e "${GREEN} โœ… Libraries built${NC}" +if [ -n "$app_dirs" ]; then + echo -e "${GREEN} โœ… Apps built: $app_names${NC}" +fi +if [ -d "apps/dashboard" ]; then + echo -e "${GREEN} โœ… Dashboard built${NC}" +fi diff --git a/scripts/build-libs.sh b/scripts/build-libs.sh new file mode 100755 index 0000000..2702a43 --- /dev/null +++ b/scripts/build-libs.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +# Build and install the new libraries + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +CYAN='\033[0;36m' +NC='\033[0m' # No Color + +echo -e "${CYAN}Building and installing new libraries...${NC}" + +# Store original location +ORIGINAL_DIR=$(pwd) +cd "/home/boki/stock-bot" + +cleanup() { + cd "$ORIGINAL_DIR" +} + +# Set up cleanup on exit +trap cleanup EXIT + +# Build order is important due to dependencies +libs=( + "types" # Base types - no dependencies + "config" # Configuration - depends on types + "logger" # Logging utilities - depends on types + "utils" # Utilities - depends on types and config + # Database clients + "postgres-client" # PostgreSQL client - depends on types, config, logger + # "mongodb-client" # MongoDB client - depends on types, config, logger (temporarily disabled - needs zod->yup conversion) + "questdb-client" # QuestDB client - depends on types, config, logger + + # Service libraries + "cache" # Cache - depends on types and logger + "http" # HTTP client - depends on types, config, logger + "event-bus" # Event bus - depends on types, logger + "shutdown" # Shutdown - depends on types, logger + + # Engine libraries + "data-frame" # Data frame - depends on types, utils + "vector-engine" # Vector engine - depends on types, utils, data-frame + "strategy-engine" # Strategy engine - depends on types, utils, event-bus +) + +# Build each library in order +for lib in "${libs[@]}"; do + lib_path="/home/boki/stock-bot/libs/$lib" + + echo -e "${GREEN}Building $lib...${NC}" + cd "$lib_path" + bun run build + + if [ $? -ne 0 ]; then + echo -e "${RED}Failed to build $lib. Exiting.${NC}" + exit 1 + fi +done + +echo -e "${GREEN}All libraries built successfully!${NC}" +cd "/home/boki/stock-bot" diff --git a/scripts/clean.sh b/scripts/clean.sh new file mode 100755 index 0000000..60ccf22 --- /dev/null +++ b/scripts/clean.sh @@ -0,0 +1,254 @@ +#!/bin/bash + +# Clean script for Stock Bot Trading Platform + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +CYAN='\033[0;36m' +GRAY='\033[0;37m' +NC='\033[0m' # No Color + +# Default options +MODULES=false +DIST=false +CACHE=false +TSBUILDINFO=false +ALL=false +FRESH=false +FORCE=false + +# Parse command line arguments +while [[ $# -gt 0 ]]; do + case $1 in + --modules|-m) + MODULES=true + shift + ;; + --dist|-d) + DIST=true + shift + ;; + --cache|-c) + CACHE=true + shift + ;; + --tsbuildinfo|-t) + TSBUILDINFO=true + shift + ;; + --all|-a) + ALL=true + shift + ;; + --fresh|-f) + FRESH=true + shift + ;; + --force) + FORCE=true + shift + ;; + --help|-h) + echo "Usage: $0 [options]" + echo " --modules, -m Remove node_modules directories" + echo " --dist, -d Remove dist directories and build caches" + echo " --cache, -c Remove cache directories" + echo " --tsbuildinfo, -t Remove TypeScript build info files" + echo " --all, -a Remove everything (destructive)" + echo " --fresh, -f Remove everything and reinstall dependencies" + echo " --force Skip confirmation prompts" + echo " --help, -h Show this help message" + exit 0 + ;; + *) + echo "Unknown option: $1" + echo "Use --help for usage information" + exit 1 + ;; + esac +done + +remove_directories_by_name() { + local name="$1" + local description="$2" + + echo -e "${BLUE}Removing $description...${NC}" + + # Find and remove directories + found_dirs=$(find . -name "$name" -type d 2>/dev/null) + + if [ -n "$found_dirs" ]; then + count=$(echo "$found_dirs" | wc -l) + echo -e "${GRAY}Found $count $description to remove${NC}" + echo "$found_dirs" | while read -r dir; do + if [ -d "$dir" ]; then + rm -rf "$dir" 2>/dev/null + echo -e "${GRAY} Removed: $dir${NC}" + fi + done + else + echo -e "${GRAY}No $description found${NC}" + fi +} + +remove_files_by_pattern() { + local pattern="$1" + local description="$2" + + echo -e "${BLUE}Removing $description...${NC}" + + # Find and remove files + found_files=$(find . -name "$pattern" -type f 2>/dev/null) + + if [ -n "$found_files" ]; then + count=$(echo "$found_files" | wc -l) + echo -e "${GRAY}Found $count $description to remove${NC}" + echo "$found_files" | while read -r file; do + if [ -f "$file" ]; then + rm -f "$file" 2>/dev/null + echo -e "${GRAY} Removed: $file${NC}" + fi + done + else + echo -e "${GRAY}No $description found${NC}" + fi +} + +echo -e "${YELLOW}Starting cleanup...${NC}" + +if [ "$ALL" = true ] || [ "$FRESH" = true ]; then + if [ "$FORCE" != true ]; then + echo -e "${RED}WARNING: This will remove ALL build artifacts, caches, dependencies, and temporary files!${NC}" + echo -e "${YELLOW}This includes: node_modules, dist, all caches, logs, databases, and lock files${NC}" + read -p "Are you sure you want to continue? (y/N): " confirmation + + if [[ "$confirmation" != "y" && "$confirmation" != "Y" ]]; then + echo -e "${YELLOW}Operation cancelled.${NC}" + exit 0 + fi + fi + + echo -e "${RED}=== NUCLEAR CLEAN: Removing EVERYTHING ===${NC}" + + # Dependencies and packages + remove_directories_by_name "node_modules" "node_modules directories" + + # Build outputs + remove_directories_by_name "dist" "dist directories" + remove_directories_by_name "build" "build directories" + remove_directories_by_name "lib" "lib directories" + remove_directories_by_name "out" "out directories" + remove_directories_by_name ".out" "build output directories" + + # Cache directories + remove_directories_by_name ".turbo" "Turborepo cache directories" + remove_directories_by_name ".next" "Next.js cache directories" + remove_directories_by_name ".parcel-cache" "Parcel cache directories" + remove_directories_by_name ".angular" "Angular CLI cache directories" + remove_directories_by_name ".nuxt" "Nuxt.js cache directories" + remove_directories_by_name ".vite" "Vite cache directories" + remove_directories_by_name ".webpack" "Webpack cache directories" + remove_directories_by_name ".rollup.cache" "Rollup cache directories" + + # Test and coverage + remove_directories_by_name "coverage" "test coverage directories" + remove_directories_by_name ".nyc_output" "NYC coverage directories" + remove_directories_by_name ".jest" "Jest cache directories" + remove_directories_by_name ".vitest" "Vitest cache directories" + + # Storybook + remove_directories_by_name ".storybook-out" "Storybook build directories" + remove_directories_by_name "storybook-static" "Storybook static directories" + + # Temporary and log directories + remove_directories_by_name "tmp" "temporary directories" + remove_directories_by_name "temp" "temp directories" + remove_directories_by_name ".tmp" "hidden temp directories" + remove_directories_by_name "logs" "log directories" + remove_directories_by_name ".logs" "hidden log directories" + + # Project specific (from .gitignore) + remove_directories_by_name ".data" "data directories" + remove_directories_by_name ".backtest-results" "backtest result directories" + remove_directories_by_name ".old" "old backup directories" + remove_directories_by_name ".mongo" "MongoDB data directories" + remove_directories_by_name ".chat" "chat directories" + + echo -e "${BLUE}Removing lock files...${NC}" + rm -f bun.lockb package-lock.json yarn.lock pnpm-lock.yaml 2>/dev/null + find . -name "bun.lockb" -type f -delete 2>/dev/null + find . -name "package-lock.json" -type f -delete 2>/dev/null + find . -name "yarn.lock" -type f -delete 2>/dev/null + find . -name "pnpm-lock.yaml" -type f -delete 2>/dev/null + + # TypeScript and build files + remove_files_by_pattern "*.tsbuildinfo" "TypeScript build info files" + remove_files_by_pattern ".eslintcache" "ESLint cache files" + remove_files_by_pattern ".stylelintcache" "Stylelint cache files" + remove_files_by_pattern ".prettiercache" "Prettier cache files" + + # Database files + remove_files_by_pattern "*.db" "database files" + remove_files_by_pattern "*.sqlite" "SQLite database files" + remove_files_by_pattern "*.sqlite3" "SQLite3 database files" + + # Log files + remove_files_by_pattern "*.log" "log files" + remove_files_by_pattern "npm-debug.log*" "npm debug logs" + remove_files_by_pattern "yarn-debug.log*" "yarn debug logs" + remove_files_by_pattern "yarn-error.log*" "yarn error logs" + remove_files_by_pattern "lerna-debug.log*" "lerna debug logs" + + # OS generated files + remove_files_by_pattern ".DS_Store" "macOS .DS_Store files" + remove_files_by_pattern "Thumbs.db" "Windows thumbnail files" + remove_files_by_pattern "ehthumbs.db" "Windows thumbnail cache files" + remove_files_by_pattern "Desktop.ini" "Windows desktop files" + + echo -e "${RED}=== NUCLEAR CLEAN COMPLETE ===${NC}" + echo -e "${BLUE}Cleanup complete - no need for turbo clean${NC}" + +elif [ "$MODULES" = true ]; then + remove_directories_by_name "node_modules" "node_modules directories" + + echo -e "${BLUE}Removing lock files...${NC}" + rm -f bun.lockb 2>/dev/null + find . -name "bun.lockb" -type f -delete 2>/dev/null + +elif [ "$DIST" = true ]; then + remove_directories_by_name "dist" "dist directories" + remove_directories_by_name ".turbo" "Turborepo cache directories" + remove_directories_by_name ".next" "Next.js cache directories" + remove_directories_by_name ".parcel-cache" "Parcel cache directories" + remove_directories_by_name ".angular" "Angular CLI cache directories" + + remove_files_by_pattern "*.tsbuildinfo" "TypeScript build info files" + remove_files_by_pattern ".eslintcache" "ESLint cache files" + +elif [ "$CACHE" = true ]; then + remove_directories_by_name ".turbo" "Turborepo cache directories" + remove_directories_by_name ".next" "Next.js cache directories" + remove_directories_by_name ".parcel-cache" "Parcel cache directories" + remove_directories_by_name ".angular" "Angular CLI cache directories" + remove_directories_by_name "coverage" "test coverage directories" + remove_directories_by_name ".nyc_output" "NYC coverage directories" + remove_files_by_pattern ".eslintcache" "ESLint cache files" + +elif [ "$TSBUILDINFO" = true ]; then + remove_files_by_pattern "*.tsbuildinfo" "TypeScript build info files" + +else + echo -e "${BLUE}Running turbo clean...${NC}" + # Only run turbo clean for the default case + turbo run clean +fi + +if [ "$FRESH" = true ]; then + echo -e "${GREEN}Installing dependencies...${NC}" + bun install +fi + +echo -e "${GREEN}Cleanup complete!${NC}" diff --git a/scripts/docker.sh b/scripts/docker.sh new file mode 100755 index 0000000..bf94498 --- /dev/null +++ b/scripts/docker.sh @@ -0,0 +1,190 @@ +#!/bin/bash + +# Trading Bot Docker Management Script + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +CYAN='\033[0;36m' +GRAY='\033[0;37m' +NC='\033[0m' # No Color + +# Default options +ACTION="" +SERVICE="" +DEV=false + +show_help() { + echo "" + echo -e "${GREEN}๐Ÿค– Trading Bot Docker Management${NC}" + echo "" + echo -e "${CYAN}Usage: $0 [options]${NC}" + echo "" + echo -e "${YELLOW}Actions:${NC}" + echo " start Start infrastructure services" + echo " stop Stop infrastructure services" + echo " restart Restart infrastructure services" + echo " status Show service status" + echo " logs Show service logs" + echo " reset Reset all data (destructive)" + echo " admin Start admin interfaces" + echo " monitoring Start monitoring stack" + echo " help Show this help" + echo "" + echo -e "${YELLOW}Options:${NC}" + echo " --service Specify a specific service" + echo " --dev Use development configuration" + echo "" + echo -e "${CYAN}Examples:${NC}" + echo " $0 start" + echo " $0 start --dev" + echo " $0 logs --service dragonfly" + echo " $0 admin" +} + +# Parse command line arguments +while [[ $# -gt 0 ]]; do + case $1 in + start|stop|restart|status|logs|reset|admin|monitoring|help) + ACTION="$1" + shift + ;; + --service|-s) + SERVICE="$2" + shift 2 + ;; + --dev|-d) + DEV=true + shift + ;; + --help|-h) + show_help + exit 0 + ;; + *) + echo "Unknown option: $1" + echo "Use --help for usage information" + exit 1 + ;; + esac +done + +if [ -z "$ACTION" ]; then + echo "Error: Action is required" + show_help + exit 1 +fi + +# Set up compose files +if [ "$DEV" = true ]; then + COMPOSE_FILES="-f docker-compose.yml -f docker-compose.dev.yml" +else + COMPOSE_FILES="-f docker-compose.yml" +fi + +case "$ACTION" in + "start") + echo -e "${GREEN}๐Ÿš€ Starting Trading Bot infrastructure...${NC}" + if [ -n "$SERVICE" ]; then + docker-compose $COMPOSE_FILES up -d "$SERVICE" + else + docker-compose $COMPOSE_FILES up -d dragonfly postgres questdb + fi + echo -e "${GREEN}โœ… Infrastructure started!${NC}" + echo "" + echo -e "${CYAN}๐Ÿ”— Access Points:${NC}" + echo " Dragonfly: localhost:6379" + echo " PostgreSQL: localhost:5432" + echo " QuestDB Console: http://localhost:9000" + echo "" + echo -e "${BLUE}๐Ÿ’ก Use '$0 admin' to start admin interfaces${NC}" + ;; + + "stop") + echo -e "${YELLOW}๐Ÿ›‘ Stopping Trading Bot infrastructure...${NC}" + if [ -n "$SERVICE" ]; then + docker-compose $COMPOSE_FILES stop "$SERVICE" + else + docker-compose $COMPOSE_FILES down + fi + echo -e "${GREEN}โœ… Infrastructure stopped!${NC}" + ;; + + "restart") + echo -e "${YELLOW}๐Ÿ”„ Restarting Trading Bot infrastructure...${NC}" + if [ -n "$SERVICE" ]; then + docker-compose $COMPOSE_FILES restart "$SERVICE" + else + docker-compose $COMPOSE_FILES restart + fi + echo -e "${GREEN}โœ… Infrastructure restarted!${NC}" + ;; + + "status") + echo -e "${CYAN}๐Ÿ“Š Trading Bot Infrastructure Status:${NC}" + docker-compose $COMPOSE_FILES ps + echo "" + echo -e "${CYAN}๐Ÿ” Health Checks:${NC}" + docker ps --filter "name=trading-bot" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" + ;; + + "logs") + if [ -n "$SERVICE" ]; then + echo -e "${CYAN}๐Ÿ“‹ Logs for $SERVICE:${NC}" + docker-compose $COMPOSE_FILES logs -f "$SERVICE" + else + echo -e "${CYAN}๐Ÿ“‹ All service logs:${NC}" + docker-compose $COMPOSE_FILES logs -f + fi + ;; + + "reset") + echo -e "${RED}โš ๏ธ Resetting Trading Bot infrastructure (will delete all data)...${NC}" + read -p "Are you sure? Type 'yes' to confirm: " confirm + if [ "$confirm" = "yes" ]; then + docker-compose $COMPOSE_FILES down -v + echo -e "${YELLOW}๐Ÿ—‘๏ธ Volumes removed${NC}" + docker-compose $COMPOSE_FILES up -d dragonfly postgres questdb + echo -e "${GREEN}โœ… Infrastructure reset complete!${NC}" + else + echo -e "${YELLOW}โŒ Reset cancelled${NC}" + fi + ;; + + "admin") + echo -e "${GREEN}๐Ÿ”ง Starting admin interfaces...${NC}" + docker-compose $COMPOSE_FILES up -d redis-insight pgadmin + echo -e "${GREEN}โœ… Admin interfaces started!${NC}" + echo "" + echo -e "${CYAN}๐Ÿ”— Admin Access:${NC}" + echo " Redis Insight: http://localhost:8001" + echo " PgAdmin: http://localhost:8080" + echo " Email: admin@tradingbot.local" + echo " Password: admin123" + ;; + + "monitoring") + echo -e "${GREEN}๐Ÿ“Š Starting monitoring stack...${NC}" + docker-compose $COMPOSE_FILES up -d prometheus grafana loki + echo -e "${GREEN}โœ… Monitoring started!${NC}" + echo "" + echo -e "${CYAN}๐Ÿ”— Monitoring Access:${NC}" + echo " Prometheus: http://localhost:9090" + echo " Grafana: http://localhost:3000" + echo " Username: admin" + echo " Password: admin" + echo " Loki: http://localhost:3100" + ;; + + "help") + show_help + ;; + + *) + echo "Unknown action: $ACTION" + show_help + exit 1 + ;; +esac diff --git a/scripts/verify-build.sh b/scripts/verify-build.sh new file mode 100755 index 0000000..aa7bd1f --- /dev/null +++ b/scripts/verify-build.sh @@ -0,0 +1,160 @@ +#!/bin/bash + +# Build verification script for Stock Bot Trading Platform + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +CYAN='\033[0;36m' +GRAY='\033[0;37m' +NC='\033[0m' # No Color + +# Default options +VERBOSE=false + +# Parse command line arguments +while [[ $# -gt 0 ]]; do + case $1 in + --verbose|-v) + VERBOSE=true + shift + ;; + --help|-h) + echo "Usage: $0 [--verbose]" + echo " --verbose, -v Show verbose output" + echo " --help, -h Show this help message" + exit 0 + ;; + *) + echo "Unknown option: $1" + echo "Use --help for usage information" + exit 1 + ;; + esac +done + +echo -e "${GREEN}=== Verifying Build Health ===${NC}" + +errors=() +warnings=() + +# Check for common build issues +echo -e "${YELLOW}Checking for common build issues...${NC}" + +# Check for mismatched .d.ts files in source directories +echo -e "${BLUE}Checking for .d.ts files in source directories...${NC}" +source_dts_files=$(find ./libs/*/src -name "*.d.ts" -type f 2>/dev/null) +if [ -n "$source_dts_files" ]; then + warnings+=("Found .d.ts files in source directories:") + while IFS= read -r file; do + warnings+=(" - $file") + done <<< "$source_dts_files" +fi + +# Check for missing dist directories after build +echo -e "${BLUE}Checking for missing dist directories...${NC}" +libraries=("types" "config" "logger" "utils" "cache" "http") +for lib in "${libraries[@]}"; do + dist_path="libs/$lib/dist" + if [ ! -d "$dist_path" ]; then + errors+=("Missing dist directory for $lib") + else + index_file="$dist_path/index.js" + if [ ! -f "$index_file" ]; then + errors+=("Missing index.js in dist for $lib") + fi + fi +done + +# Check for TypeScript compilation errors +echo -e "${BLUE}Checking for TypeScript compilation errors...${NC}" +tsc_errors=$(find . -name "*.tsbuildinfo" -exec grep -l "error" {} \; 2>/dev/null) +if [ -n "$tsc_errors" ]; then + errors+=("TypeScript compilation errors found in build info files") + if [ "$VERBOSE" = true ]; then + while IFS= read -r file; do + errors+=(" - $file") + done <<< "$tsc_errors" + fi +fi + +# Check for large build files (potential issues) +echo -e "${BLUE}Checking for unusually large build files...${NC}" +large_files=$(find ./libs/*/dist -name "*.js" -size +1M 2>/dev/null) +if [ -n "$large_files" ]; then + warnings+=("Found unusually large build files (>1MB):") + while IFS= read -r file; do + size=$(stat -c%s "$file" 2>/dev/null || stat -f%z "$file" 2>/dev/null) + size_mb=$(echo "scale=2; $size / 1024 / 1024" | bc 2>/dev/null || echo "unknown") + warnings+=(" - $file (${size_mb}MB)") + done <<< "$large_files" +fi + +# Check for circular dependencies (basic check) +echo -e "${BLUE}Checking for potential circular dependencies...${NC}" +package_json_files=$(find ./libs -name "package.json" -type f) +while IFS= read -r pkg_file; do + lib_name=$(basename "$(dirname "$pkg_file")") + if [ -f "$pkg_file" ]; then + # Check if library depends on itself (basic check) + self_dep=$(grep -o "@stock-bot/$lib_name" "$pkg_file" 2>/dev/null) + if [ -n "$self_dep" ]; then + warnings+=("Potential circular dependency in $lib_name") + fi + fi +done <<< "$package_json_files" + +# Check for missing package.json files +echo -e "${BLUE}Checking for missing package.json files...${NC}" +lib_dirs=$(find ./libs -maxdepth 1 -type d -name "*" ! -name "libs") +while IFS= read -r lib_dir; do + if [ -d "$lib_dir" ] && [ ! -f "$lib_dir/package.json" ]; then + lib_name=$(basename "$lib_dir") + errors+=("Missing package.json in $lib_name") + fi +done <<< "$lib_dirs" + +# Check for environment variable dependencies +echo -e "${BLUE}Checking for hardcoded paths...${NC}" +hardcoded_paths=$(grep -r "g:\\repos\\stock-bot" ./libs 2>/dev/null || true) +if [ -n "$hardcoded_paths" ]; then + warnings+=("Found hardcoded Windows paths:") + while IFS= read -r line; do + warnings+=(" - $line") + done <<< "$hardcoded_paths" +fi + +# Summary +echo "" +echo -e "${CYAN}=== Build Verification Summary ===${NC}" + +if [ ${#errors[@]} -eq 0 ] && [ ${#warnings[@]} -eq 0 ]; then + echo -e "${GREEN}โœ… Build verification passed - no issues found!${NC}" + exit 0 +fi + +if [ ${#errors[@]} -gt 0 ]; then + echo -e "${RED}โŒ Errors found (${#errors[@]}):${NC}" + for error in "${errors[@]}"; do + echo -e "${RED} $error${NC}" + done +fi + +if [ ${#warnings[@]} -gt 0 ]; then + echo -e "${YELLOW}โš ๏ธ Warnings found (${#warnings[@]}):${NC}" + for warning in "${warnings[@]}"; do + echo -e "${YELLOW} $warning${NC}" + done +fi + +if [ ${#errors[@]} -gt 0 ]; then + echo "" + echo -e "${RED}Build verification failed due to errors.${NC}" + exit 1 +else + echo "" + echo -e "${YELLOW}Build verification completed with warnings.${NC}" + exit 0 +fi