-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
58 lines (45 loc) · 1.88 KB
/
script.js
File metadata and controls
58 lines (45 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const fs = require('fs')
const path = require('path')
const baseDir = './'
const maxPadding = 5
const tierMap = [
"UnRated", "Bronze V", "Bronze IV", "Bronze III", "Bronze II", "Bronze I",
"Silver V", "Silver IV", "Silver III", "Silver II", "Silver I",
"Gold V", "Gold IV", "Gold III", "Gold II", "Gold I",
"Platinum V", "Platinum IV", "Platinum III", "Platinum II", "Platinum I",
"Diamond V", "Diamond IV", "Diamond III", "Diamond II", "Diamond I",
"Ruby V", "Ruby IV", "Ruby III", "Ruby II", "Ruby I"
]
const ignoreDirs = [
'.git', '.github', '.vscode'
]
const entries = fs.readdirSync(baseDir, { withFileTypes: true })
entries.forEach((entry) => {
if (!entry.isDirectory()) return
if (tierMap.indexOf(entry.name) !== -1 || ignoreDirs.indexOf(entry.name) !== -1) return
const oldDirName = entry.name;
const fullOldPath = path.join(baseDir, oldDirName)
const readmePath = path.join(fullOldPath, 'README.md')
if (!fs.existsSync(readmePath)) {
console.warn(`⚠️ ${oldDirName} - README.md 없음`)
return;
}
const firstLine = fs.readFileSync(readmePath, 'utf8').split('\n')[0]
// tier number (e.g., tier_small/8.svg)
const tierMatch = firstLine.match(/tier_small\/(\d+)\.svg/)
const tierNum = tierMatch ? parseInt(tierMatch[1], 10) : 0
const tierName = tierMap[tierNum] || 'Unrated'
// 문제 번호 및 제목
const probMatch = firstLine.match(/^# (\d+)번: (.+?) -/)
if (!probMatch) {
console.warn(`⚠️ ${oldDirName} - 문제 정보 파싱 실패`)
return;
}
const probNum = probMatch[1].padStart(maxPadding, '0')
const probTitle = probMatch[2];
const newDirName = `${probNum}_${probTitle}`;
const newFullPath = path.join(baseDir, tierName, newDirName)
fs.mkdirSync(path.dirname(newFullPath), { recursive: true })
console.log(`✅ Moving: ${oldDirName} → ${tierName}/${newDirName}`)
fs.renameSync(fullOldPath, newFullPath);
});