/
GhostLogic
/
SudakOnline
Обзор
Документация
Войти
/
GhostLogic
/
SudakOnline
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
build_code.php
138 строк
6 KB
GhostLogic
Загрузить файлы в «»
28 апр 2026, 18:11
Верифицирован
28 апр 2026, 18:11
3c10f40
Код
Авторство
О чём код?
<?php /** * Скрипт для сборки проекта в один .md файл (без сжатия). * Сохраняет оригинальную структуру и пробелы, чтобы можно было * точно указывать строки для последующего патчинга. * * Собирает: index.html (или указанный главный файл), все файлы из папок pwa/ и api/ * (кроме исключённых расширений и папок). * Результат: project.md */ // Настройки $rootDir = __DIR__; $mainFile = 'pwa/index.html'; // главный файл (относительно корня) $foldersToCollect = ['pwa', 'api']; // папки для рекурсивного сбора $outputFile = 'project.md'; // выходной файл // Исключаемые расширения (бинарные или не текстовые) $excludeExtensions = ['png', 'jpg', 'jpeg', 'gif', 'ico', 'webp', 'bmp', 'woff', 'woff2', 'ttf', 'eot', 'otf', 'svg', 'mp4', 'webm', 'mp3', 'wav', 'zip', 'tar', 'gz', 'db', 'sqlite', 'log']; // Исключаемые подстроки в пути (например, папки libs, vendor) $excludePathParts = ['libs', 'vendor', 'node_modules', '.git', '.idea', '.vscode', 'cache']; // Функция для определения языка синтаксиса по расширению function getLanguage($extension) { $map = [ 'js' => 'javascript', 'mjs' => 'javascript', 'cjs' => 'javascript', 'ts' => 'typescript', 'html' => 'html', 'htm' => 'html', 'css' => 'css', 'scss' => 'scss', 'sass' => 'sass', 'less' => 'less', 'json' => 'json', 'xml' => 'xml', 'txt' => 'text', 'md' => 'markdown', 'php' => 'php', 'py' => 'python', 'rb' => 'ruby', 'go' => 'go', 'java' => 'java', 'c' => 'c', 'cpp' => 'cpp', 'h' => 'c', 'hpp' => 'cpp', 'sql' => 'sql', 'sh' => 'bash', 'bat' => 'batch', 'ps1' => 'powershell', ]; return $map[$extension] ?? 'text'; } // Рекурсивный обход папки для получения всех файлов function getAllFiles($dir, $excludeExtensions, $excludePathParts, &$results = []) { $files = scandir($dir); foreach ($files as $file) { if ($file === '.' || $file === '..') continue; $fullPath = $dir . DIRECTORY_SEPARATOR . $file; $relative = str_replace(__DIR__ . DIRECTORY_SEPARATOR, '', $fullPath); // Проверяем, не содержит ли путь исключённую подстроку $excluded = false; foreach ($excludePathParts as $part) { if (stripos($relative, $part) !== false) { $excluded = true; break; } } if ($excluded) continue; if (is_dir($fullPath)) { getAllFiles($fullPath, $excludeExtensions, $excludePathParts, $results); } else { $ext = pathinfo($file, PATHINFO_EXTENSION); if (in_array(strtolower($ext), $excludeExtensions)) { continue; // пропускаем бинарные файлы } $results[] = $fullPath; } } return $results; } // Начинаем сборку $outputContent = ''; $addedFiles = []; // для предотвращения дублирования // 1. Добавляем главный файл (например, pwa/index.html) $mainPath = $rootDir . DIRECTORY_SEPARATOR . $mainFile; if (file_exists($mainPath)) { $content = file_get_contents($mainPath); $ext = pathinfo($mainPath, PATHINFO_EXTENSION); $lang = getLanguage($ext); $relativePath = str_replace($rootDir . DIRECTORY_SEPARATOR, '', $mainPath); $outputContent .= "=== $relativePath ===\n"; $outputContent .= "```$lang\n$content\n```\n\n"; $addedFiles[$relativePath] = true; echo "Добавлен главный файл: $relativePath\n"; } else { echo "Предупреждение: $mainFile не найден, пропускаем.\n"; } // 2. Обрабатываем каждую из указанных папок (рекурсивно) foreach ($foldersToCollect as $folder) { $folderPath = $rootDir . DIRECTORY_SEPARATOR . $folder; if (!is_dir($folderPath)) { echo "Предупреждение: папка '$folder' не найдена, пропускаем.\n"; continue; } $files = []; getAllFiles($folderPath, $excludeExtensions, $excludePathParts, $files); sort($files); // сортируем для стабильности foreach ($files as $filePath) { $relativePath = str_replace($rootDir . DIRECTORY_SEPARATOR, '', $filePath); // Пропускаем, если уже добавлен (например, index.html мог быть добавлен как mainFile) if (isset($addedFiles[$relativePath])) continue; $content = file_get_contents($filePath); // НЕ сжимаем содержимое! Оставляем как есть. $ext = pathinfo($filePath, PATHINFO_EXTENSION); $lang = getLanguage($ext); $outputContent .= "=== $relativePath ===\n"; $outputContent .= "```$lang\n$content\n```\n\n"; $addedFiles[$relativePath] = true; echo "Добавлен: $relativePath\n"; } } // 3. Записываем результат в файл file_put_contents($outputFile, $outputContent); echo "✅ Готово! Создан файл: $outputFile (размер: " . filesize($outputFile) . " байт)\n"; echo "⚠️ Внимание: файлы добавлены без сжатия, строки соответствуют оригиналам.\n";