-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathupdate-shadcn.cjs
More file actions
114 lines (94 loc) · 3.25 KB
/
Copy pathupdate-shadcn.cjs
File metadata and controls
114 lines (94 loc) · 3.25 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env node
const fs = require("fs");
const path = require("path");
const { execFileSync } = require("child_process");
/**
* shadcn 컴포넌트를 자동으로 업데이트하는 스크립트
* components.json 파일의 aliases.components 경로를 읽어서
* 해당 경로의 ui 폴더 안에 있는 모든 컴포넌트를 업데이트합니다.
*/
function main() {
try {
// components.json 파일 읽기
const componentsJsonPath = path.join(process.cwd(), "components.json");
if (!fs.existsSync(componentsJsonPath)) {
console.error("❌ components.json 파일을 찾을 수 없습니다.");
process.exit(1);
}
const componentsConfig = JSON.parse(
fs.readFileSync(componentsJsonPath, "utf8")
);
// aliases.components 경로 가져오기
const componentsPath = componentsConfig.aliases?.components;
if (!componentsPath) {
console.error(
"❌ components.json에서 aliases.components 경로를 찾을 수 없습니다."
);
process.exit(1);
}
// ui 폴더 경로 구성
const uiPath = path.join(
process.cwd(),
"src",
componentsPath.replace("@/", ""),
"ui"
);
if (!fs.existsSync(uiPath)) {
console.error(`❌ UI 컴포넌트 폴더를 찾을 수 없습니다: ${uiPath}`);
process.exit(1);
}
// ui 폴더의 모든 .tsx 파일 찾기
const files = fs
.readdirSync(uiPath)
.filter((file) => file.endsWith(".tsx"))
.map((file) => path.basename(file, ".tsx"));
if (files.length === 0) {
console.log("📁 ui 폴더에서 .tsx 파일을 찾을 수 없습니다.");
return;
}
console.log(`🔍 발견된 shadcn 컴포넌트들 (${files.length}개):`);
files.forEach((file) => console.log(` - ${file}`));
console.log("");
// 각 컴포넌트 업데이트
let successCount = 0;
let failCount = 0;
for (const componentName of files) {
try {
console.log(`🔄 업데이트 중: ${componentName}...`);
if (!/^[a-z0-9_-]+$/i.test(componentName)) {
throw new Error(`invalid component name: ${componentName}`);
}
execFileSync(
"npx",
["shadcn@latest", "add", "-o", "-y", componentName],
{
stdio: "pipe",
encoding: "utf8",
env: { ...process.env, npm_config_legacy_peer_deps: "true" },
}
);
console.log(`✅ ${componentName} 업데이트 완료`);
successCount++;
} catch (error) {
console.error(`❌ ${componentName} 업데이트 실패:`, error.message);
failCount++;
}
}
console.log("");
console.log("📊 업데이트 결과:");
console.log(` ✅ 성공: ${successCount}개`);
console.log(` ❌ 실패: ${failCount}개`);
console.log(` 📁 총 컴포넌트: ${files.length}개`);
if (failCount === 0) {
console.log("🎉 모든 shadcn 컴포넌트가 성공적으로 업데이트되었습니다!");
}
} catch (error) {
console.error("❌ 스크립트 실행 중 오류가 발생했습니다:", error.message);
process.exit(1);
}
}
// 스크립트가 직접 실행될 때만 main 함수 호출
if (require.main === module) {
main();
}
module.exports = { main };