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