|
| 1 | +import fs from 'fs'; |
| 2 | +import path from 'path'; |
| 3 | +import { fileURLToPath } from 'url'; |
| 4 | + |
| 5 | +// Get current directory |
| 6 | +const __filename = fileURLToPath(import.meta.url); |
| 7 | +const __dirname = path.dirname(__filename); |
| 8 | + |
| 9 | +// Function to recursively create directories |
| 10 | +function ensureDirectoryExists(dirPath: string) { |
| 11 | + if (!fs.existsSync(dirPath)) { |
| 12 | + fs.mkdirSync(dirPath, { recursive: true }); |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | +// Function to recursively copy JSON files from source to destination |
| 17 | +function copyJsonFiles(sourceDir: string, targetDir: string) { |
| 18 | + // Read all files and directories in the source directory |
| 19 | + const items = fs.readdirSync(sourceDir); |
| 20 | + |
| 21 | + for (const item of items) { |
| 22 | + const sourcePath = path.join(sourceDir, item); |
| 23 | + const targetPath = path.join(targetDir, item); |
| 24 | + |
| 25 | + const stats = fs.statSync(sourcePath); |
| 26 | + |
| 27 | + if (stats.isDirectory()) { |
| 28 | + // Recursively copy JSON files from subdirectories |
| 29 | + copyJsonFiles(sourcePath, targetPath); |
| 30 | + } else if (stats.isFile() && path.extname(item).toLowerCase() === '.json') { |
| 31 | + // Copy JSON files |
| 32 | + ensureDirectoryExists(path.dirname(targetPath)); |
| 33 | + fs.copyFileSync(sourcePath, targetPath); |
| 34 | + console.log(`Copied: ${sourcePath} -> ${targetPath}`); |
| 35 | + } |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +// Copy JSON files from src to dist |
| 40 | +const sourceDir = path.resolve(__dirname, '../src'); |
| 41 | +const targetDir = path.resolve(__dirname, '../dist'); |
| 42 | + |
| 43 | +console.log('Copying JSON files from src to dist...'); |
| 44 | +copyJsonFiles(sourceDir, targetDir); |
| 45 | +console.log('JSON files copying completed.'); |
0 commit comments