import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs"; import { resolve, dirname } from "path"; import { fileURLToPath } from "url"; import { client } from "../src/api/client"; const __dirname = dirname(fileURLToPath(import.meta.url)); const products = async function getProducts() { try { console.log("📡 Загрузка товаров из API..."); const response = await client.get("/productList/"); return response.data; } catch (error) { console.error("❌ Ошибка загрузки из API:", error.message); console.log("📦 Использую тестовые данные..."); } }; const distPath = resolve(__dirname, "../dist"); const indexHtmlPath = resolve(distPath, "index.html"); if (!existsSync(indexHtmlPath)) { console.error("❌ Сначала запустите npm run build"); process.exit(1); } // Читаем исходный HTML let baseHtml = readFileSync(indexHtmlPath, "utf-8"); // Добавляем базовые мета-теги для каждой страницы const pages = [ { path: "/", title: "Магазин труб - Главная", description: "Купить канализационные трубы, фитинги и комплектующие по низким ценам.", }, { path: "/products", title: "Каталог труб и фитингов для канализации", description: "Широкий выбор канализационных труб ПВХ, фитингов, тройников, переходов, колен. Высокое качество, низкие цены.", }, { path: "/about", title: "О магазине труб - Доставка и гарантия", description: "Информация о нашей компании. Как мы работаем, условия доставки, гарантия на все товары.", }, ]; const allRoutes = [...pages]; // Добавляем маршруты товаров for (const product of products) { allRoutes.push({ path: `/product/${product.id}`, description: product.description, title: product.full_name, }); } let successCount = 0; let errorCount = 0; for (const route of allRoutes) { try { // Заменяем мета-теги let html = baseHtml .replace( /