|
| 1 | +const fs = require('fs'); |
| 2 | +const path = require('path'); |
| 3 | + |
| 4 | +// 루트 디렉토리 설정 |
| 5 | +const rootDir = process.cwd(); // 현재 작업 디렉토리 |
| 6 | + |
| 7 | +// 주어진 주별 디렉토리 범위 설정 |
| 8 | +const weekDirs = Array.from({ length: 10 }, (_, i) => `week${i + 1}`); // ["week1", "week2", ..., "week10"] |
| 9 | + |
| 10 | +// /build 디렉토리 생성 |
| 11 | +const buildDir = path.join(rootDir, 'build'); |
| 12 | +if (!fs.existsSync(buildDir)) { |
| 13 | + fs.mkdirSync(buildDir); |
| 14 | +} |
| 15 | + |
| 16 | +// 각 주별 디렉토리 탐색 |
| 17 | +weekDirs.forEach(weekDir => { |
| 18 | + const weekPath = path.join(rootDir, weekDir); |
| 19 | + |
| 20 | + if (fs.existsSync(weekPath) && fs.lstatSync(weekPath).isDirectory()) { |
| 21 | + // 주별 디렉토리 내의 하위 디렉토리 탐색 |
| 22 | + fs.readdirSync(weekPath).forEach(mission => { |
| 23 | + const missionDir = path.join(weekPath, mission); |
| 24 | + |
| 25 | + // 하위 디렉토리가 존재하고 package.json이 없을 경우 |
| 26 | + if (fs.existsSync(missionDir) && fs.lstatSync(missionDir).isDirectory() && !fs.existsSync(path.join(missionDir, 'package.json'))) { |
| 27 | + console.log(`Found directory without package.json: ${missionDir}`); |
| 28 | + |
| 29 | + // 대상 빌드 디렉토리 설정 |
| 30 | + const targetDir = path.join(buildDir, weekDir, mission); |
| 31 | + |
| 32 | + // 디렉토리 및 파일 복사 |
| 33 | + copyDirectory(missionDir, targetDir); |
| 34 | + console.log(`Copied ${missionDir} to ${targetDir}`); |
| 35 | + } |
| 36 | + }); |
| 37 | + } |
| 38 | +}); |
| 39 | + |
| 40 | +// 디렉토리 복사 함수 정의 |
| 41 | +function copyDirectory(src, dest) { |
| 42 | + // 디렉토리 생성 |
| 43 | + if (!fs.existsSync(dest)) { |
| 44 | + fs.mkdirSync(dest, { recursive: true }); |
| 45 | + } |
| 46 | + |
| 47 | + // 디렉토리 내의 파일 및 서브디렉토리 복사 |
| 48 | + fs.readdirSync(src).forEach(item => { |
| 49 | + const srcPath = path.join(src, item); |
| 50 | + const destPath = path.join(dest, item); |
| 51 | + |
| 52 | + if (fs.lstatSync(srcPath).isDirectory()) { |
| 53 | + copyDirectory(srcPath, destPath); |
| 54 | + } else { |
| 55 | + fs.copyFileSync(srcPath, destPath); |
| 56 | + } |
| 57 | + }); |
| 58 | +} |
0 commit comments