|
| 1 | +const path = require('path'); |
| 2 | +const fs = require('fs'); |
| 3 | + |
| 4 | +const SOURCE_PATH = path.join(__dirname, '../../docs/img'); |
| 5 | +const DEST_PATH = path.join(__dirname, '../public/img/docs'); |
| 6 | + |
| 7 | +/** |
| 8 | + * Recursively copy a directory (cross-platform) |
| 9 | + */ |
| 10 | +function copyDirSync(src, dest) { |
| 11 | + // Create destination directory if it doesn't exist |
| 12 | + if (!fs.existsSync(dest)) { |
| 13 | + fs.mkdirSync(dest, { recursive: true }); |
| 14 | + } |
| 15 | + |
| 16 | + const entries = fs.readdirSync(src, { withFileTypes: true }); |
| 17 | + |
| 18 | + for (const entry of entries) { |
| 19 | + const srcPath = path.join(src, entry.name); |
| 20 | + const destPath = path.join(dest, entry.name); |
| 21 | + |
| 22 | + if (entry.isDirectory()) { |
| 23 | + copyDirSync(srcPath, destPath); |
| 24 | + } else { |
| 25 | + fs.copyFileSync(srcPath, destPath); |
| 26 | + } |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +/** |
| 31 | + * Copy docs images to public folder in a cross-platform way |
| 32 | + */ |
| 33 | +function copyDocsImages() { |
| 34 | + try { |
| 35 | + copyDirSync(SOURCE_PATH, DEST_PATH); |
| 36 | + console.log('Images copied successfully!'); |
| 37 | + } catch (err) { |
| 38 | + console.error('Error copying images:', err); |
| 39 | + process.exit(1); |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +copyDocsImages(); |
0 commit comments