khy_admin/setup.js
2025-09-19 21:51:10 -07:00

185 lines
5.5 KiB
JavaScript

#!/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"
);