#!/usr/bin/env node const fs = require("fs"); const path = require("path"); const { execSync } = require("child_process"); console.log("šŸš€ Setting up KHY Admin Dashboard...\n"); // Check if we're in the right directory if (!fs.existsSync("src/index.html")) { console.error( "āŒ Error: Please run this script from the admin-dashboard directory" ); process.exit(1); } // Create necessary directories const directories = ["assets/images/products", "logs"]; directories.forEach((dir) => { if (!fs.existsSync(dir)) { fs.mkdirSync(dir, { recursive: true }); console.log(`āœ… Created directory: ${dir}`); } }); // Check if package.json exists and install dependencies if (fs.existsSync("package.json")) { console.log("šŸ“¦ Installing dependencies..."); try { execSync("npm install", { stdio: "inherit" }); console.log("āœ… Dependencies installed successfully"); } catch (error) { console.warn( 'āš ļø Warning: Failed to install dependencies. You may need to run "npm install" manually.' ); } } else { console.log("šŸ“¦ Creating package.json..."); const packageJson = { name: "khy-admin", version: "1.0.0", description: "KHY Product Management Dashboard", main: "src/index.html", scripts: { start: "python3 -m http.server 3000", sync: "node scripts/sync-to-main.js", dev: "python3 -m http.server 3000", }, dependencies: { sharp: "^0.32.0", }, devDependencies: { nodemon: "^3.0.0", }, keywords: ["admin", "dashboard", "product-management"], author: "KHY", license: "MIT", }; fs.writeFileSync("package.json", JSON.stringify(packageJson, null, 2)); console.log("āœ… Created package.json"); } // Create a sample .env file for configuration if (!fs.existsSync(".env")) { console.log("āš™ļø Creating configuration file..."); const envContent = `# KHY Admin Dashboard Configuration # Update these values according to your setup # Main repository URL (update this with your actual repository) MAIN_REPO_URL=https://github.com/your-username/khy-website.git # Admin dashboard port PORT=3000 # Enable/disable features ENABLE_IMAGE_UPLOAD=true ENABLE_SYNC=true ENABLE_PREVIEW=true # Security settings REQUIRE_AUTH=false SESSION_SECRET=your-secret-key-here `; fs.writeFileSync(".env", envContent); console.log("āœ… Created .env configuration file"); } // Create a simple start script if (!fs.existsSync("start.sh")) { console.log("šŸ“ Creating start script..."); const startScript = `#!/bin/bash echo "šŸš€ Starting KHY Admin Dashboard..." echo "šŸ“± Dashboard will be available at: http://localhost:3000" echo "šŸ”§ To stop the server, press Ctrl+C" echo "" python3 -m http.server 3000 `; fs.writeFileSync("start.sh", startScript); fs.chmodSync("start.sh", "755"); console.log("āœ… Created start script (start.sh)"); } // Create a simple start script for Windows if (!fs.existsSync("start.bat")) { console.log("šŸ“ Creating Windows start script..."); const startScript = `@echo off echo šŸš€ Starting KHY Admin Dashboard... echo šŸ“± Dashboard will be available at: http://localhost:3000 echo šŸ”§ To stop the server, press Ctrl+C echo. python -m http.server 3000 `; fs.writeFileSync("start.bat", startScript); console.log("āœ… Created Windows start script (start.bat)"); } // Check if data/products.json exists if (!fs.existsSync("data/products.json")) { console.log("šŸ“„ Creating sample products.json..."); const sampleData = { products: [ { id: 1, name: "Sample Product 1", description: "This is a sample product description", descriptionLong: [ "This is a longer description of the product that provides more detailed information about its features and benefits.", "It can contain multiple paragraphs to give users comprehensive information about the product.", ], category: "task-chairs", image: "assets/images/products/sample1.jpg", images: [ "assets/images/products/sample1.jpg", "assets/images/products/sample1_2.jpg", ], galleryPairs: [ "assets/images/products/sample1.jpg", "assets/images/products/sample1_2.jpg", ], additionalInformation: { Material: "Premium mesh and steel frame", Design: "Ergonomic swivel chair with adjustable features", "Use Cases": "Perfect for office workstations and home offices", }, warranty: "5 years", }, ], categories: [ { id: "task-chairs", name: "Task Chairs", description: "Ergonomic office chairs for daily work", }, { id: "conference-chairs", name: "Conference Chairs", description: "Professional seating for meetings and conferences", }, ], }; fs.writeFileSync("data/products.json", JSON.stringify(sampleData, null, 2)); console.log("āœ… Created sample products.json"); } console.log("\nšŸŽ‰ Setup completed successfully!"); console.log("\nšŸ“‹ Next steps:"); console.log( "1. Update the MAIN_REPO_URL in .env file with your actual repository URL" ); console.log("2. Start the dashboard:"); console.log(" - On Mac/Linux: ./start.sh"); console.log(" - On Windows: start.bat"); console.log(" - Or manually: python3 -m http.server 3000"); console.log("3. Open your browser and go to: http://localhost:3000"); console.log("4. Start managing your products!"); console.log("\nšŸ“š For more information, see README.md"); console.log( "\nšŸ”§ To sync changes to your main site, update the repository URL in scripts/sync-to-main.js" );