89 lines
2.6 KiB
JavaScript
89 lines
2.6 KiB
JavaScript
import fs from "fs";
|
||
import path from "path";
|
||
import { pathToFileURL } from "url";
|
||
|
||
const SRC_DIR = "./src";
|
||
const DIST_DIR = "./dist/ai";
|
||
const SCRIPTS_DIR = "./scripts";
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// Сборка по манифесту
|
||
// ---------------------------------------------------------------------------
|
||
|
||
async function buildForFramework(framework) {
|
||
const manifestPath = path.join(SCRIPTS_DIR, `${framework}.build.js`);
|
||
|
||
if (!fs.existsSync(manifestPath)) {
|
||
console.error(`Манифест не найден: ${manifestPath}`);
|
||
process.exit(1);
|
||
}
|
||
|
||
const manifest = (await import(pathToFileURL(path.resolve(manifestPath)).href)).default;
|
||
const outDir = path.join(DIST_DIR, framework);
|
||
|
||
// Очищаем выходную директорию
|
||
if (fs.existsSync(outDir)) {
|
||
fs.rmSync(outDir, { recursive: true, force: true });
|
||
}
|
||
|
||
console.log(`\nСборка: ${manifest.name} (${framework})`);
|
||
console.log(`Выход: ${outDir}\n`);
|
||
|
||
const errors = [];
|
||
let count = 0;
|
||
|
||
for (const [destRelative, srcRelative] of Object.entries(manifest.files)) {
|
||
const srcPath = path.join(SRC_DIR, srcRelative);
|
||
const destPath = path.join(outDir, destRelative);
|
||
|
||
if (!fs.existsSync(srcPath)) {
|
||
errors.push(` [!] Не найден: ${srcRelative}`);
|
||
continue;
|
||
}
|
||
|
||
fs.mkdirSync(path.dirname(destPath), { recursive: true });
|
||
fs.copyFileSync(srcPath, destPath);
|
||
console.log(` ${destRelative}`);
|
||
count++;
|
||
}
|
||
|
||
if (errors.length > 0) {
|
||
console.log(`\nОшибки:`);
|
||
errors.forEach((e) => console.log(e));
|
||
}
|
||
|
||
console.log(`\nГотово: ${outDir} (${count} файлов)`);
|
||
}
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// Определяем что собирать
|
||
// ---------------------------------------------------------------------------
|
||
|
||
let frameworks = fs
|
||
.readdirSync(SCRIPTS_DIR)
|
||
.filter((f) => f.endsWith(".build.js"))
|
||
.map((f) => f.replace(".build.js", ""));
|
||
|
||
if (frameworks.length === 0) {
|
||
console.error("Не найдено ни одного манифеста *.build.js в scripts/");
|
||
process.exit(1);
|
||
}
|
||
|
||
// --framework=nextjs
|
||
const fwArg = process.argv.find((a) => a.startsWith("--framework="));
|
||
if (fwArg) {
|
||
const fw = fwArg.split("=")[1];
|
||
if (frameworks.includes(fw)) {
|
||
frameworks = [fw];
|
||
} else {
|
||
console.error(`Фреймворк "${fw}" не найден. Доступные: ${frameworks.join(", ")}`);
|
||
process.exit(1);
|
||
}
|
||
}
|
||
|
||
for (const fw of frameworks) {
|
||
await buildForFramework(fw);
|
||
}
|
||
|
||
console.log("\nВсе сборки завершены.");
|