44 lines
1.4 KiB
JavaScript
44 lines
1.4 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
// Manual sync script to copy data from admin dashboard to main website
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
|
|
console.log("🔄 MANUAL SYNC: Admin Dashboard → Main Website");
|
|
|
|
// Paths
|
|
const adminProductsPath = path.join(__dirname, "data", "products.json");
|
|
const mainProductsPath = path.join(__dirname, "..", "data", "products.json");
|
|
|
|
try {
|
|
// Check if admin dashboard has products.json
|
|
if (!fs.existsSync(adminProductsPath)) {
|
|
console.log("❌ Admin dashboard products.json not found");
|
|
console.log(
|
|
"💡 Make sure you have saved changes in the admin dashboard first"
|
|
);
|
|
process.exit(1);
|
|
}
|
|
|
|
// Read admin dashboard data
|
|
const adminData = JSON.parse(fs.readFileSync(adminProductsPath, "utf8"));
|
|
console.log(
|
|
`📦 Found ${adminData.products.length} products in admin dashboard`
|
|
);
|
|
|
|
// Ensure main data directory exists
|
|
const mainDataDir = path.dirname(mainProductsPath);
|
|
if (!fs.existsSync(mainDataDir)) {
|
|
fs.mkdirSync(mainDataDir, { recursive: true });
|
|
console.log("📁 Created main data directory");
|
|
}
|
|
|
|
// Copy to main website
|
|
fs.writeFileSync(mainProductsPath, JSON.stringify(adminData, null, 2));
|
|
console.log("✅ Successfully synced to main website!");
|
|
console.log(`📄 Updated: ${mainProductsPath}`);
|
|
console.log("🔄 Refresh your preview to see changes");
|
|
} catch (error) {
|
|
console.error("❌ Sync failed:", error.message);
|
|
process.exit(1);
|
|
}
|