161 lines
4.5 KiB
JavaScript
161 lines
4.5 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
/**
|
|
* Setup Script for KHY Admin Deploy Configuration
|
|
*
|
|
* This script helps you configure the deploy paths for your specific setup.
|
|
* Run this once to set up the correct paths for your environment.
|
|
*/
|
|
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
const readline = require("readline");
|
|
|
|
const rl = readline.createInterface({
|
|
input: process.stdin,
|
|
output: process.stdout,
|
|
});
|
|
|
|
function question(prompt) {
|
|
return new Promise((resolve) => {
|
|
rl.question(prompt, resolve);
|
|
});
|
|
}
|
|
|
|
async function setupDeploy() {
|
|
console.log("KHY Admin Deploy Setup");
|
|
console.log("======================");
|
|
console.log("");
|
|
console.log("This script will help you configure the deploy paths.");
|
|
console.log("You need to specify where your main KHY website is located.");
|
|
console.log("");
|
|
|
|
// Get current admin directory
|
|
const adminDir = __dirname;
|
|
console.log(`Current admin directory: ${adminDir}`);
|
|
console.log("");
|
|
|
|
// Ask for the main website path
|
|
console.log("Where is your main KHY website located?");
|
|
console.log("Examples:");
|
|
console.log(" - If in same parent directory: ../khy_website");
|
|
console.log(" - If in different location: /path/to/your/khy_website");
|
|
console.log(" - If admin is inside main website: ../");
|
|
console.log("");
|
|
|
|
const mainWebsitePath = await question("Enter path to main KHY website: ");
|
|
|
|
if (!mainWebsitePath.trim()) {
|
|
console.log("No path provided. Exiting.");
|
|
rl.close();
|
|
return;
|
|
}
|
|
|
|
// Resolve the path
|
|
const resolvedPath = path.resolve(adminDir, mainWebsitePath.trim());
|
|
|
|
console.log("");
|
|
console.log(`Resolved path: ${resolvedPath}`);
|
|
|
|
// Check if the path exists
|
|
if (!fs.existsSync(resolvedPath)) {
|
|
console.log("WARNING: The specified path does not exist!");
|
|
const continueAnyway = await question("Continue anyway? (y/N): ");
|
|
if (continueAnyway.toLowerCase() !== "y") {
|
|
console.log("Setup cancelled.");
|
|
rl.close();
|
|
return;
|
|
}
|
|
}
|
|
|
|
// Check for required files
|
|
const requiredFiles = ["index.html", "data/products.json"];
|
|
const missingFiles = requiredFiles.filter(
|
|
(file) => !fs.existsSync(path.join(resolvedPath, file))
|
|
);
|
|
|
|
if (missingFiles.length > 0) {
|
|
console.log(`WARNING: Missing required files: ${missingFiles.join(", ")}`);
|
|
const continueAnyway = await question("Continue anyway? (y/N): ");
|
|
if (continueAnyway.toLowerCase() !== "y") {
|
|
console.log("Setup cancelled.");
|
|
rl.close();
|
|
return;
|
|
}
|
|
}
|
|
|
|
// Update the config file
|
|
const configPath = path.join(adminDir, "deploy-config.js");
|
|
const configContent = `/**
|
|
* Deploy Configuration for KHY Admin Dashboard
|
|
*
|
|
* This file contains configuration for deploying from the admin repository
|
|
* to the main KHY website repository.
|
|
*
|
|
* Generated by setup-deploy.js on ${new Date().toISOString()}
|
|
*/
|
|
|
|
module.exports = {
|
|
// Default target paths (adjust these based on your setup)
|
|
targets: {
|
|
// If admin and main website are in the same parent directory
|
|
sibling: "../khy_website",
|
|
|
|
// If admin is in a subdirectory of the main website
|
|
parent: "../",
|
|
|
|
// Your configured path
|
|
main: "${mainWebsitePath.trim()}",
|
|
|
|
// Absolute path examples (uncomment and modify as needed)
|
|
// absolute: "/path/to/your/khy_website",
|
|
// absolute: "/Users/george/Documents/khy_website/khy_website",
|
|
},
|
|
|
|
// Which target to use by default
|
|
defaultTarget: "main",
|
|
|
|
// Files to copy from admin to main website
|
|
filesToCopy: [
|
|
{
|
|
source: "data/products.json",
|
|
target: "data/products.json",
|
|
description: "Product catalog data",
|
|
},
|
|
{
|
|
source: "assets/images",
|
|
target: "assets/images",
|
|
description: "Product images",
|
|
isDirectory: true,
|
|
},
|
|
],
|
|
|
|
// Required files that must exist in target directory
|
|
requiredTargetFiles: ["index.html", "data/products.json"],
|
|
|
|
// Backup settings
|
|
backup: {
|
|
enabled: true,
|
|
directory: "backups",
|
|
timestampFormat: "YYYY-MM-DD_HH-mm-ss",
|
|
}
|
|
};`;
|
|
|
|
try {
|
|
fs.writeFileSync(configPath, configContent);
|
|
console.log("");
|
|
console.log("Configuration updated successfully!");
|
|
console.log(`Config file: ${configPath}`);
|
|
console.log("");
|
|
console.log("You can now run: npm run deploy");
|
|
console.log("");
|
|
console.log("To test the configuration, run:");
|
|
console.log(` node deploy.js "${mainWebsitePath.trim()}"`);
|
|
} catch (error) {
|
|
console.log(`Error writing config file: ${error.message}`);
|
|
}
|
|
|
|
rl.close();
|
|
}
|
|
|
|
setupDeploy().catch(console.error);
|