63 lines
1.8 KiB
JavaScript
63 lines
1.8 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
/**
|
|
* Copy Assets Script for SerpentRace Backend
|
|
* Copies non-TypeScript files to the dist directory
|
|
*/
|
|
|
|
const srcDir = path.join(__dirname, '..', 'src');
|
|
const distDir = path.join(__dirname, '..', 'dist');
|
|
|
|
// File extensions to copy
|
|
const assetExtensions = ['.json', '.html', '.css', '.png', '.jpg', '.jpeg', '.gif', '.svg', '.ico', '.woff', '.woff2', '.ttf', '.eot'];
|
|
|
|
// Directories to exclude from copying
|
|
const excludeDirs = ['node_modules', '.git', 'tests', '__tests__'];
|
|
|
|
function copyAssets(srcPath, distPath) {
|
|
if (!fs.existsSync(srcPath)) {
|
|
console.log(`Source directory ${srcPath} does not exist`);
|
|
return;
|
|
}
|
|
|
|
if (!fs.existsSync(distPath)) {
|
|
fs.mkdirSync(distPath, { recursive: true });
|
|
}
|
|
|
|
const items = fs.readdirSync(srcPath);
|
|
|
|
items.forEach(item => {
|
|
const srcItemPath = path.join(srcPath, item);
|
|
const distItemPath = path.join(distPath, item);
|
|
const stat = fs.statSync(srcItemPath);
|
|
|
|
if (stat.isDirectory()) {
|
|
// Skip excluded directories
|
|
if (excludeDirs.includes(item)) {
|
|
return;
|
|
}
|
|
|
|
// Recursively copy subdirectories
|
|
copyAssets(srcItemPath, distItemPath);
|
|
} else {
|
|
const ext = path.extname(item).toLowerCase();
|
|
|
|
// Copy asset files
|
|
if (assetExtensions.includes(ext)) {
|
|
console.log(`Copying asset: ${srcItemPath} -> ${distItemPath}`);
|
|
fs.copyFileSync(srcItemPath, distItemPath);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
try {
|
|
console.log('Copying assets from src to dist...');
|
|
copyAssets(srcDir, distDir);
|
|
console.log('Asset copying completed successfully!');
|
|
} catch (error) {
|
|
console.error('Error copying assets:', error);
|
|
process.exit(1);
|
|
}
|