Files
StikeArena_chrt/scripts/copy-standalone.js
T
2026-06-02 22:17:15 +05:00

50 lines
1.8 KiB
JavaScript

// Копирует нужные файлы в .next/standalone/ после билда
const fs = require('fs');
const path = require('path');
function copyDir(src, dest) {
if (!fs.existsSync(src)) return;
fs.mkdirSync(dest, { recursive: true });
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);
if (entry.isDirectory()) {
copyDir(srcPath, destPath);
} else {
fs.copyFileSync(srcPath, destPath);
}
}
}
function copyFile(src, dest) {
if (!fs.existsSync(src)) return;
fs.mkdirSync(path.dirname(dest), { recursive: true });
fs.copyFileSync(src, dest);
console.log(`${path.basename(src)}`);
}
const root = path.join(__dirname, '..');
const standalone = path.join(root, '.next', 'standalone');
console.log('Копирую файлы в .next/standalone/...');
// public/ → .next/standalone/public/
copyDir(path.join(root, 'public'), path.join(standalone, 'public'));
console.log(' ✓ public/');
// .next/static/ → .next/standalone/.next/static/
copyDir(path.join(root, '.next', 'static'), path.join(standalone, '.next', 'static'));
console.log(' ✓ .next/static/');
// init/ → .next/standalone/init/ (нужно для SQLite seed)
copyDir(path.join(root, 'init'), path.join(standalone, 'init'));
console.log(' ✓ init/');
// .env.local → .next/standalone/.env.local (переменные окружения для локального запуска)
copyFile(path.join(root, '.env.local'), path.join(standalone, '.env.local'));
// .env → .next/standalone/.env (если есть)
copyFile(path.join(root, '.env'), path.join(standalone, '.env'));
console.log('✓ standalone готов к запуску');