@sgx4u/ui 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +69 -0
- package/LICENSE +7 -0
- package/README.md +161 -0
- package/SECURITY.md +5 -0
- package/SUPPORT.md +5 -0
- package/dist/bin.cjs +1218 -0
- package/dist/bin.d.cts +1 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +4 -0
- package/dist/chunk-SWLJZFBL.js +890 -0
- package/dist/cli-UJKWK2HV.js +200 -0
- package/dist/index.cjs +924 -0
- package/dist/index.d.cts +20 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +10 -0
- package/logo.svg +18 -0
- package/package.json +88 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,924 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
addComponent: () => addComponent,
|
|
34
|
+
initConfig: () => initConfig,
|
|
35
|
+
listComponents: () => listComponents
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(index_exports);
|
|
38
|
+
|
|
39
|
+
// src/commands/init.ts
|
|
40
|
+
var import_inquirer2 = __toESM(require("inquirer"), 1);
|
|
41
|
+
var import_ora = __toESM(require("ora"), 1);
|
|
42
|
+
|
|
43
|
+
// src/commands/utils/config.util.ts
|
|
44
|
+
var import_fs_extra2 = __toESM(require("fs-extra"), 1);
|
|
45
|
+
var import_inquirer = __toESM(require("inquirer"), 1);
|
|
46
|
+
var import_path2 = __toESM(require("path"), 1);
|
|
47
|
+
|
|
48
|
+
// src/commands/utils/alias.util.ts
|
|
49
|
+
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
50
|
+
var import_path = __toESM(require("path"), 1);
|
|
51
|
+
async function detectAlias(cwd) {
|
|
52
|
+
const configFiles = ["tsconfig.json", "jsconfig.json"];
|
|
53
|
+
for (const file of configFiles) {
|
|
54
|
+
const configPath = import_path.default.join(cwd, file);
|
|
55
|
+
if (!import_fs_extra.default.existsSync(configPath)) continue;
|
|
56
|
+
const config = await import_fs_extra.default.readJson(configPath);
|
|
57
|
+
const paths = config?.compilerOptions?.paths;
|
|
58
|
+
if (!paths || typeof paths !== "object") continue;
|
|
59
|
+
for (const [alias, targets] of Object.entries(paths)) {
|
|
60
|
+
if (!alias.endsWith("/*")) continue;
|
|
61
|
+
if (!Array.isArray(targets) || !targets[0]) continue;
|
|
62
|
+
const prefix = alias.replace("/*", "");
|
|
63
|
+
const baseDir = targets[0].replace("/*", "");
|
|
64
|
+
return { enabled: true, prefix, baseDir };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/commands/utils/config.util.ts
|
|
71
|
+
async function getConfig(cwd) {
|
|
72
|
+
try {
|
|
73
|
+
const configPath = import_path2.default.resolve(cwd, "ui.config.json");
|
|
74
|
+
const configExists = await import_fs_extra2.default.pathExists(configPath);
|
|
75
|
+
if (configExists) return await import_fs_extra2.default.readJson(configPath);
|
|
76
|
+
return null;
|
|
77
|
+
} catch {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async function createConfig({
|
|
82
|
+
cwd,
|
|
83
|
+
projectInfo
|
|
84
|
+
}) {
|
|
85
|
+
try {
|
|
86
|
+
const detectedDir = await detectUIDirectory(cwd);
|
|
87
|
+
const { uiDir, environment, typescript } = await import_inquirer.default.prompt([
|
|
88
|
+
{
|
|
89
|
+
type: "input",
|
|
90
|
+
name: "uiDir",
|
|
91
|
+
message: "Where would you like to add UI components?",
|
|
92
|
+
default: detectedDir,
|
|
93
|
+
validate: (input) => {
|
|
94
|
+
if (!input.trim()) return "Please enter a valid directory path.";
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
type: "list",
|
|
100
|
+
name: "environment",
|
|
101
|
+
message: "Which environment are you using?",
|
|
102
|
+
choices: [
|
|
103
|
+
{ name: "React", value: "react" },
|
|
104
|
+
{ name: "Next.js", value: "next" }
|
|
105
|
+
],
|
|
106
|
+
default: projectInfo.project
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
type: "confirm",
|
|
110
|
+
name: "typescript",
|
|
111
|
+
message: "Do you want to use TypeScript?",
|
|
112
|
+
default: projectInfo.hasTypeScript
|
|
113
|
+
}
|
|
114
|
+
]);
|
|
115
|
+
const finalUiPath = uiDir.startsWith("/") ? uiDir : `./${uiDir}`;
|
|
116
|
+
const aliasInfo = await detectAlias(cwd);
|
|
117
|
+
const aliases = aliasInfo ? {
|
|
118
|
+
[aliasInfo.prefix]: aliasInfo.baseDir,
|
|
119
|
+
[`${aliasInfo.prefix}/ui`]: finalUiPath,
|
|
120
|
+
[`${aliasInfo.prefix}/elements`]: `${finalUiPath}/elements`,
|
|
121
|
+
[`${aliasInfo.prefix}/modules`]: `${finalUiPath}/modules`,
|
|
122
|
+
[`${aliasInfo.prefix}/helpers`]: `${finalUiPath}/helpers`,
|
|
123
|
+
[`${aliasInfo.prefix}/hooks`]: `${finalUiPath}/hooks`,
|
|
124
|
+
[`${aliasInfo.prefix}/utils`]: `${finalUiPath}/utils`
|
|
125
|
+
} : {
|
|
126
|
+
ui: finalUiPath,
|
|
127
|
+
elements: `${finalUiPath}/elements`,
|
|
128
|
+
modules: `${finalUiPath}/modules`,
|
|
129
|
+
helpers: `${finalUiPath}/helpers`,
|
|
130
|
+
hooks: `${finalUiPath}/hooks`,
|
|
131
|
+
utils: `${finalUiPath}/utils`
|
|
132
|
+
};
|
|
133
|
+
const config = {
|
|
134
|
+
uiDir: finalUiPath,
|
|
135
|
+
environment,
|
|
136
|
+
typescript,
|
|
137
|
+
aliases,
|
|
138
|
+
registry: "https://registry.npmjs.org"
|
|
139
|
+
};
|
|
140
|
+
const configPath = import_path2.default.join(cwd, "ui.config.json");
|
|
141
|
+
await import_fs_extra2.default.writeJson(configPath, config, { spaces: 4 });
|
|
142
|
+
return config;
|
|
143
|
+
} catch {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
async function detectUIDirectory(cwd) {
|
|
148
|
+
const srcUiPath = import_path2.default.join(cwd, "src");
|
|
149
|
+
if (await import_fs_extra2.default.pathExists(srcUiPath)) return "src/ui";
|
|
150
|
+
return "ui";
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// src/commands/utils/css.util.ts
|
|
154
|
+
var import_fs_extra3 = __toESM(require("fs-extra"), 1);
|
|
155
|
+
var import_path3 = __toESM(require("path"), 1);
|
|
156
|
+
|
|
157
|
+
// src/commands/data/theme-tailwind-v4.data.ts
|
|
158
|
+
var themeVariablesV4 = `@import 'tailwindcss';
|
|
159
|
+
|
|
160
|
+
@custom-variant dark (&:is(.dark *));
|
|
161
|
+
|
|
162
|
+
:root {
|
|
163
|
+
--background: oklch(100% 0 0); /* #ffffff */
|
|
164
|
+
--background-light: oklch(97% 0 0); /* #f5f5f5 */
|
|
165
|
+
--foreground: oklch(26.9% 0 0); /* #262626 */
|
|
166
|
+
|
|
167
|
+
--primary: oklch(26.9% 0 0); /* #262626 */
|
|
168
|
+
--primary-dark: oklch(14.5% 0 0); /* #0a0a0a */
|
|
169
|
+
--primary-light: oklch(70.8% 0 0); /* #a1a1a1 */
|
|
170
|
+
--primary-foreground: var(--background);
|
|
171
|
+
|
|
172
|
+
--secondary: oklch(51.1% 0.262 276.966); /* #4f39f6 */
|
|
173
|
+
--secondary-dark: oklch(45.7% 0.24 277.023); /* #432dd7 */
|
|
174
|
+
--secondary-light: oklch(93% 0.034 272.788); /* #e0e7ff */
|
|
175
|
+
--secondary-foreground: var(--background);
|
|
176
|
+
|
|
177
|
+
--success: oklch(72.3% 0.219 149.579); /* #00c950 */
|
|
178
|
+
--success-dark: oklch(62.7% 0.194 149.214); /* #00a63e */
|
|
179
|
+
--success-light: oklch(96.2% 0.044 156.743); /* #dcfce7 */
|
|
180
|
+
--success-foreground: var(--background);
|
|
181
|
+
|
|
182
|
+
--warn: oklch(82.8% 0.189 84.429); /* #ffb900 */
|
|
183
|
+
--warn-dark: oklch(76.9% 0.188 70.08); /* #fe9a00 */
|
|
184
|
+
--warn-light: oklch(96.2% 0.059 95.617); /* #fef3c6 */
|
|
185
|
+
--warn-foreground: var(--background);
|
|
186
|
+
|
|
187
|
+
--danger: oklch(63.7% 0.237 25.331); /* #fb2c36 */
|
|
188
|
+
--danger-dark: oklch(57.7% 0.245 27.325); /* #e7000b */
|
|
189
|
+
--danger-light: oklch(93.6% 0.032 17.717); /* #ffe2e2 */
|
|
190
|
+
--danger-foreground: var(--background);
|
|
191
|
+
|
|
192
|
+
--muted: oklch(87% 0 0); /* #d4d4d4 */
|
|
193
|
+
--muted-dark: oklch(70.8% 0 0); /* #a1a1a1 */
|
|
194
|
+
--muted-light: oklch(95.514% 0.00011 271.152); /* #f0f0f0 */
|
|
195
|
+
--muted-foreground: oklch(43.9% 0 0); /* #525252 */
|
|
196
|
+
|
|
197
|
+
--card: var(--background);
|
|
198
|
+
|
|
199
|
+
--light: var(--background);
|
|
200
|
+
--dark: var(--foreground);
|
|
201
|
+
--border: var(--muted-light);
|
|
202
|
+
--input-placeholder: oklch(70.8% 0 0); /* #a1a1a1 */
|
|
203
|
+
|
|
204
|
+
--radius: 0.5rem;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.dark {
|
|
208
|
+
--background: oklch(23.929% 0.00003 271.152); /* #1f1f1f */
|
|
209
|
+
--background-light: oklch(26.9% 0 0); /* #262626 */
|
|
210
|
+
--foreground: oklch(98.5% 0 0); /* #fafafa */
|
|
211
|
+
|
|
212
|
+
--primary: oklch(97% 0 0); /* #f5f5f5 */
|
|
213
|
+
--primary-dark: oklch(92.2% 0 0); /* #e5e5e5 */
|
|
214
|
+
--primary-light: oklch(98.5% 0 0); /* #fafafa */
|
|
215
|
+
--primary-foreground: var(--background);
|
|
216
|
+
|
|
217
|
+
--secondary: oklch(0.6009 0.1957 277.79); /* #696cf2 */
|
|
218
|
+
--secondary-dark: oklch(0.5348 0.2183 278.55); /* #5951e6 */
|
|
219
|
+
--secondary-light: oklch(93% 0.034 272.788); /* #e0e7ff */
|
|
220
|
+
--secondary-foreground: var(--foreground);
|
|
221
|
+
|
|
222
|
+
--success: oklch(0.8152 0.1685 152.67); /* #5be18c */
|
|
223
|
+
--success-dark: oklch(0.7665 0.2043 149.52); /* #25d566 */
|
|
224
|
+
--success-light: oklch(96.2% 0.044 156.743); /* #dcfce7 */
|
|
225
|
+
--success-foreground: var(--foreground);
|
|
226
|
+
|
|
227
|
+
--warn: oklch(82.8% 0.189 84.429); /* #ffb900 */
|
|
228
|
+
--warn-dark: oklch(76.9% 0.188 70.08); /* #fe9a00 */
|
|
229
|
+
--warn-light: oklch(96.2% 0.059 95.617); /* #fef3c6 */
|
|
230
|
+
--warn-foreground: var(--foreground);
|
|
231
|
+
|
|
232
|
+
--danger: oklch(0.7287 0.1531 21.55); /* #f97c7c */
|
|
233
|
+
--danger-dark: oklch(0.6605 0.190501 23.9375); /* #f15656 */
|
|
234
|
+
--danger-light: oklch(93.6% 0.032 17.717); /* #ffe2e2 */
|
|
235
|
+
--danger-foreground: var(--foreground);
|
|
236
|
+
|
|
237
|
+
--muted: oklch(43.9% 0 0); /* #525252 */
|
|
238
|
+
--muted-dark: oklch(37.1% 0 0); /* #404040 */
|
|
239
|
+
--muted-light: oklch(55.6% 0 0); /* #737373 */
|
|
240
|
+
--muted-foreground: oklch(97% 0.001 106.424); /* #f5f5f5 */
|
|
241
|
+
|
|
242
|
+
--card: var(--background);
|
|
243
|
+
|
|
244
|
+
--light: var(--foreground);
|
|
245
|
+
--dark: var(--background);
|
|
246
|
+
--border: var(--muted-light);
|
|
247
|
+
--input-placeholder: oklch(70.8% 0 0); /* #a1a1a1 */
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
@theme {
|
|
251
|
+
--breakpoint-mobile: 36rem;
|
|
252
|
+
--breakpoint-tablet: 48rem;
|
|
253
|
+
--breakpoint-laptop: 64rem;
|
|
254
|
+
--breakpoint-desktop: 80rem;
|
|
255
|
+
--breakpoint-wide: 90rem;
|
|
256
|
+
|
|
257
|
+
--container-mobile: 36rem;
|
|
258
|
+
--container-tablet: 48rem;
|
|
259
|
+
--container-laptop: 64rem;
|
|
260
|
+
--container-desktop: 80rem;
|
|
261
|
+
--container-wide: 90rem;
|
|
262
|
+
|
|
263
|
+
--text-xxs: 0.625rem;
|
|
264
|
+
|
|
265
|
+
@keyframes animate-gradient {
|
|
266
|
+
0% {
|
|
267
|
+
background-position: 100% 50%;
|
|
268
|
+
}
|
|
269
|
+
to {
|
|
270
|
+
background-position: 0 50%;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
@keyframes animate-heart-beat {
|
|
275
|
+
0% {
|
|
276
|
+
box-shadow: 0 0 0 0px hsl(239, 83%, 68%);
|
|
277
|
+
}
|
|
278
|
+
100% {
|
|
279
|
+
box-shadow: 0 0 0 10px hsl(239, 83%, 68%, 0);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
@theme inline {
|
|
285
|
+
--color-background: var(--background);
|
|
286
|
+
--color-background-light: var(--background-light);
|
|
287
|
+
--color-foreground: var(--foreground);
|
|
288
|
+
|
|
289
|
+
--color-primary: var(--primary);
|
|
290
|
+
--color-primary-dark: var(--primary-dark);
|
|
291
|
+
--color-primary-light: var(--primary-light);
|
|
292
|
+
--color-primary-foreground: var(--primary-foreground);
|
|
293
|
+
|
|
294
|
+
--color-secondary: var(--secondary);
|
|
295
|
+
--color-secondary-dark: var(--secondary-dark);
|
|
296
|
+
--color-secondary-light: var(--secondary-light);
|
|
297
|
+
--color-secondary-foreground: var(--secondary-foreground);
|
|
298
|
+
|
|
299
|
+
--color-success: var(--success);
|
|
300
|
+
--color-success-dark: var(--success-dark);
|
|
301
|
+
--color-success-light: var(--success-light);
|
|
302
|
+
--color-success-foreground: var(--success-foreground);
|
|
303
|
+
|
|
304
|
+
--color-warn: var(--warn);
|
|
305
|
+
--color-warn-dark: var(--warn-dark);
|
|
306
|
+
--color-warn-light: var(--warn-light);
|
|
307
|
+
--color-warn-foreground: var(--warn-foreground);
|
|
308
|
+
|
|
309
|
+
--color-danger: var(--danger);
|
|
310
|
+
--color-danger-dark: var(--danger-dark);
|
|
311
|
+
--color-danger-light: var(--danger-light);
|
|
312
|
+
--color-danger-foreground: var(--danger-foreground);
|
|
313
|
+
|
|
314
|
+
--color-muted: var(--muted);
|
|
315
|
+
--color-muted-dark: var(--muted-dark);
|
|
316
|
+
--color-muted-light: var(--muted-light);
|
|
317
|
+
--color-muted-foreground: var(--muted-foreground);
|
|
318
|
+
|
|
319
|
+
--color-card: var(--card);
|
|
320
|
+
|
|
321
|
+
--color-light: var(--light);
|
|
322
|
+
--color-dark: var(--dark);
|
|
323
|
+
--color-border: var(--border);
|
|
324
|
+
--color-input-placeholder: var(--input-placeholder);
|
|
325
|
+
|
|
326
|
+
--radius-sm: calc(var(--radius) - 4px);
|
|
327
|
+
--radius-md: calc(var(--radius) - 2px);
|
|
328
|
+
--radius-lg: var(--radius);
|
|
329
|
+
--radius-xl: calc(var(--radius) + 4px);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
@layer base {
|
|
333
|
+
* {
|
|
334
|
+
@apply scroll-m-24 border-border;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
body {
|
|
338
|
+
@apply bg-background text-foreground;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
::-webkit-scrollbar {
|
|
342
|
+
@apply size-1;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
::-webkit-scrollbar-track {
|
|
346
|
+
@apply bg-muted-light;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
::-webkit-scrollbar-thumb {
|
|
350
|
+
@apply bg-muted-dark;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
::-webkit-scrollbar-thumb:hover {
|
|
354
|
+
@apply bg-muted-foreground/75;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/* Selection */
|
|
358
|
+
::selection {
|
|
359
|
+
-webkit-text-fill-color: var(--background);
|
|
360
|
+
@apply bg-primary text-primary-foreground;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
@layer utilities {
|
|
365
|
+
/* Animate wave background */
|
|
366
|
+
.animate-wave-bg {
|
|
367
|
+
background-image: linear-gradient(
|
|
368
|
+
90deg,
|
|
369
|
+
rgb(238, 238, 238) 35%,
|
|
370
|
+
rgb(245, 245, 245) 50%,
|
|
371
|
+
rgb(238, 238, 238) 65%
|
|
372
|
+
);
|
|
373
|
+
background-size: 300%;
|
|
374
|
+
animation: animate-gradient 2.5s ease infinite;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/* Elevated card */
|
|
378
|
+
.elevated-card {
|
|
379
|
+
box-shadow: 0 0 20px var(--muted-light);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/* Glass card */
|
|
383
|
+
.glass-card {
|
|
384
|
+
background: hsla(0, 0%, 100%, 0.2) !important;
|
|
385
|
+
border: 1px solid hsla(0, 0%, 100%, 0.3) !important;
|
|
386
|
+
box-shadow: 0 4px 30px hsla(0, 0%, 0%, 0.1) !important;
|
|
387
|
+
backdrop-filter: blur(5px);
|
|
388
|
+
-webkit-backdrop-filter: blur(5px);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/* Hide scrollbar */
|
|
392
|
+
.hide-scrollbar {
|
|
393
|
+
scrollbar-width: none;
|
|
394
|
+
-ms-overflow-style: none;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
.animate-changelog-timeline {
|
|
398
|
+
animation: animate-heart-beat 1.5s ease infinite;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
`;
|
|
402
|
+
|
|
403
|
+
// src/commands/utils/css.util.ts
|
|
404
|
+
async function createThemeFile({
|
|
405
|
+
cwd,
|
|
406
|
+
version
|
|
407
|
+
}) {
|
|
408
|
+
if (version === "none") return null;
|
|
409
|
+
const existingGlobalCssPath = await locateGlobalsCSS(cwd);
|
|
410
|
+
if (existingGlobalCssPath) {
|
|
411
|
+
const updated = await updateGlobalsCSS({
|
|
412
|
+
filePath: existingGlobalCssPath,
|
|
413
|
+
content: themeVariablesV4
|
|
414
|
+
});
|
|
415
|
+
if (!updated) return null;
|
|
416
|
+
return existingGlobalCssPath;
|
|
417
|
+
}
|
|
418
|
+
const srcAppDir = import_path3.default.join(cwd, "src", "app");
|
|
419
|
+
const appDir = import_path3.default.join(cwd, "app");
|
|
420
|
+
let newGlobalCssPath;
|
|
421
|
+
if (await import_fs_extra3.default.pathExists(srcAppDir)) {
|
|
422
|
+
newGlobalCssPath = import_path3.default.join(srcAppDir, "globals.css");
|
|
423
|
+
} else if (await import_fs_extra3.default.pathExists(appDir)) {
|
|
424
|
+
newGlobalCssPath = import_path3.default.join(appDir, "globals.css");
|
|
425
|
+
} else {
|
|
426
|
+
newGlobalCssPath = import_path3.default.join(cwd, "src", "app", "globals.css");
|
|
427
|
+
}
|
|
428
|
+
await import_fs_extra3.default.ensureDir(import_path3.default.dirname(newGlobalCssPath));
|
|
429
|
+
const fileUpdated = await writeCSSFile({
|
|
430
|
+
filePath: newGlobalCssPath,
|
|
431
|
+
content: themeVariablesV4
|
|
432
|
+
});
|
|
433
|
+
if (!fileUpdated) return null;
|
|
434
|
+
return newGlobalCssPath;
|
|
435
|
+
}
|
|
436
|
+
async function locateGlobalsCSS(cwd) {
|
|
437
|
+
const commonPaths = [import_path3.default.join(cwd, "src", "app", "globals.css"), import_path3.default.join(cwd, "app", "globals.css")];
|
|
438
|
+
for (const cssPath of commonPaths) {
|
|
439
|
+
if (await import_fs_extra3.default.pathExists(cssPath)) return cssPath;
|
|
440
|
+
}
|
|
441
|
+
return null;
|
|
442
|
+
}
|
|
443
|
+
async function writeCSSFile({ filePath, content }) {
|
|
444
|
+
try {
|
|
445
|
+
await import_fs_extra3.default.writeFile(filePath, content, "utf8");
|
|
446
|
+
return true;
|
|
447
|
+
} catch {
|
|
448
|
+
return false;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
async function updateGlobalsCSS({ filePath, content }) {
|
|
452
|
+
try {
|
|
453
|
+
await import_fs_extra3.default.writeFile(filePath, content, "utf8");
|
|
454
|
+
return true;
|
|
455
|
+
} catch {
|
|
456
|
+
return false;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// src/commands/utils/package.util.ts
|
|
461
|
+
var import_fs_extra4 = __toESM(require("fs-extra"), 1);
|
|
462
|
+
var import_child_process = require("child_process");
|
|
463
|
+
var import_path4 = __toESM(require("path"), 1);
|
|
464
|
+
async function getProjectInfo(cwd) {
|
|
465
|
+
const hasReact = await isPackageInstalled({ packageName: "react", cwd });
|
|
466
|
+
const hasNextJS = await isPackageInstalled({ packageName: "next", cwd });
|
|
467
|
+
const hasTypeScript = await isPackageInstalled({ packageName: "typescript", cwd });
|
|
468
|
+
const tailwindVersion = await getTailwindVersion(cwd);
|
|
469
|
+
const lucideVersion = await getPackageVersion({ packageName: "lucide-react", cwd });
|
|
470
|
+
const packageManager = await detectPackageManager(cwd);
|
|
471
|
+
const project = hasNextJS ? "next" : hasReact ? "react" : "none";
|
|
472
|
+
return { project, hasTypeScript, tailwindVersion, lucideVersion, packageManager };
|
|
473
|
+
}
|
|
474
|
+
async function isPackageInstalled({ packageName, cwd }) {
|
|
475
|
+
try {
|
|
476
|
+
const packageJsonPath = import_path4.default.join(cwd, "package.json");
|
|
477
|
+
if (!await import_fs_extra4.default.pathExists(packageJsonPath)) return false;
|
|
478
|
+
const packageJson = await import_fs_extra4.default.readJson(packageJsonPath);
|
|
479
|
+
const allDeps = {
|
|
480
|
+
...packageJson.dependencies,
|
|
481
|
+
...packageJson.devDependencies,
|
|
482
|
+
...packageJson.peerDependencies
|
|
483
|
+
};
|
|
484
|
+
return Object.keys(allDeps).some((dependency) => dependency === packageName);
|
|
485
|
+
} catch {
|
|
486
|
+
return false;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
async function installDependencies({
|
|
490
|
+
cwd,
|
|
491
|
+
packageManager,
|
|
492
|
+
dependencies
|
|
493
|
+
}) {
|
|
494
|
+
try {
|
|
495
|
+
const installCommand = getInstallCommand({ packageManager, packages: dependencies, isDev: false });
|
|
496
|
+
(0, import_child_process.execSync)(installCommand, { cwd, stdio: "pipe", encoding: "utf8" });
|
|
497
|
+
return true;
|
|
498
|
+
} catch {
|
|
499
|
+
return false;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
async function getPackageVersion({ packageName, cwd }) {
|
|
503
|
+
const packageJsonPath = import_path4.default.join(cwd, "package.json");
|
|
504
|
+
if (!await import_fs_extra4.default.pathExists(packageJsonPath)) return null;
|
|
505
|
+
const packageJson = await import_fs_extra4.default.readJson(packageJsonPath);
|
|
506
|
+
const allDeps = {
|
|
507
|
+
...packageJson.dependencies,
|
|
508
|
+
...packageJson.devDependencies,
|
|
509
|
+
...packageJson.peerDependencies
|
|
510
|
+
};
|
|
511
|
+
const rawVersion = allDeps[packageName];
|
|
512
|
+
if (rawVersion == null || typeof rawVersion !== "string") return null;
|
|
513
|
+
const packageVersion = rawVersion.replace(/^[\^~>=]+/, "").split(".");
|
|
514
|
+
if (packageVersion.length === 0 || packageVersion[0] === "") return null;
|
|
515
|
+
const version = packageVersion[1] != null ? `${packageVersion[0]}.${packageVersion[1]}` : packageVersion[0];
|
|
516
|
+
const parsed = Number.parseFloat(version);
|
|
517
|
+
return Number.isNaN(parsed) ? null : parsed;
|
|
518
|
+
}
|
|
519
|
+
async function detectPackageManager(cwd) {
|
|
520
|
+
try {
|
|
521
|
+
const pnpmLockPath = import_path4.default.join(cwd, "pnpm-lock.yaml");
|
|
522
|
+
if (await import_fs_extra4.default.pathExists(pnpmLockPath)) return "pnpm";
|
|
523
|
+
const yarnLockPath = import_path4.default.join(cwd, "yarn.lock");
|
|
524
|
+
if (await import_fs_extra4.default.pathExists(yarnLockPath)) return "yarn";
|
|
525
|
+
const bunLockPath = import_path4.default.join(cwd, "bun.lockb");
|
|
526
|
+
if (await import_fs_extra4.default.pathExists(bunLockPath)) return "bun";
|
|
527
|
+
const npmLockPath = import_path4.default.join(cwd, "package-lock.json");
|
|
528
|
+
if (await import_fs_extra4.default.pathExists(npmLockPath)) return "npm";
|
|
529
|
+
const packageJsonPath = import_path4.default.join(cwd, "package.json");
|
|
530
|
+
if (await import_fs_extra4.default.pathExists(packageJsonPath)) {
|
|
531
|
+
try {
|
|
532
|
+
const packageJson = await import_fs_extra4.default.readJson(packageJsonPath);
|
|
533
|
+
if (packageJson.packageManager) {
|
|
534
|
+
const packageManager = packageJson.packageManager;
|
|
535
|
+
if (packageManager.includes("pnpm")) return "pnpm";
|
|
536
|
+
if (packageManager.includes("yarn")) return "yarn";
|
|
537
|
+
if (packageManager.includes("bun")) return "bun";
|
|
538
|
+
if (packageManager.includes("npm")) return "npm";
|
|
539
|
+
}
|
|
540
|
+
} catch {
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
try {
|
|
544
|
+
(0, import_child_process.execSync)("pnpm --version", { stdio: "pipe", cwd });
|
|
545
|
+
return "pnpm";
|
|
546
|
+
} catch {
|
|
547
|
+
try {
|
|
548
|
+
(0, import_child_process.execSync)("yarn --version", { stdio: "pipe", cwd });
|
|
549
|
+
return "yarn";
|
|
550
|
+
} catch {
|
|
551
|
+
try {
|
|
552
|
+
(0, import_child_process.execSync)("bun --version", { stdio: "pipe", cwd });
|
|
553
|
+
return "bun";
|
|
554
|
+
} catch {
|
|
555
|
+
return "npm";
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
} catch {
|
|
560
|
+
return "npm";
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
function getInstallCommand({
|
|
564
|
+
packageManager,
|
|
565
|
+
packages,
|
|
566
|
+
isDev
|
|
567
|
+
}) {
|
|
568
|
+
const packagesStr = packages.join(" ");
|
|
569
|
+
switch (packageManager) {
|
|
570
|
+
case "pnpm":
|
|
571
|
+
return isDev ? `pnpm add -D ${packagesStr}` : `pnpm add ${packagesStr}`;
|
|
572
|
+
case "yarn":
|
|
573
|
+
return isDev ? `yarn add -D ${packagesStr}` : `yarn add ${packagesStr}`;
|
|
574
|
+
case "bun":
|
|
575
|
+
return isDev ? `bun add -d ${packagesStr}` : `bun add ${packagesStr}`;
|
|
576
|
+
default:
|
|
577
|
+
return isDev ? `npm install --save-dev ${packagesStr}` : `npm install ${packagesStr}`;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
async function getTailwindVersion(cwd) {
|
|
581
|
+
const packageJsonPath = import_path4.default.join(cwd, "package.json");
|
|
582
|
+
if (!await import_fs_extra4.default.pathExists(packageJsonPath)) return "none";
|
|
583
|
+
const packageJson = await import_fs_extra4.default.readJson(packageJsonPath);
|
|
584
|
+
const allDeps = {
|
|
585
|
+
...packageJson.dependencies,
|
|
586
|
+
...packageJson.devDependencies,
|
|
587
|
+
...packageJson.peerDependencies
|
|
588
|
+
};
|
|
589
|
+
if (allDeps["tailwindcss"] && (allDeps["tailwindcss"].startsWith("4") || allDeps["tailwindcss"].startsWith("^4"))) {
|
|
590
|
+
return "v4";
|
|
591
|
+
}
|
|
592
|
+
return "none";
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
// src/commands/init.ts
|
|
596
|
+
async function initConfig() {
|
|
597
|
+
try {
|
|
598
|
+
console.log("\u2699\uFE0F Initializing configuration...");
|
|
599
|
+
const cwd = process.cwd();
|
|
600
|
+
const existingConfig = await getConfig(cwd);
|
|
601
|
+
if (existingConfig) {
|
|
602
|
+
console.log("\u2714 ui.config.json already exists in this project.");
|
|
603
|
+
const { overwrite } = await import_inquirer2.default.prompt([
|
|
604
|
+
{
|
|
605
|
+
type: "confirm",
|
|
606
|
+
name: "overwrite",
|
|
607
|
+
message: "Do you want to overwrite the existing configuration?",
|
|
608
|
+
default: false
|
|
609
|
+
}
|
|
610
|
+
]);
|
|
611
|
+
if (!overwrite) {
|
|
612
|
+
console.log("\u274C Configuration initialization cancelled!");
|
|
613
|
+
process.exit(1);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
const projectInfo = await getProjectInfo(cwd);
|
|
617
|
+
if (projectInfo.project === "none") {
|
|
618
|
+
console.log("\u274C No supported project detected!");
|
|
619
|
+
process.exit(1);
|
|
620
|
+
}
|
|
621
|
+
if (projectInfo.tailwindVersion === "none") {
|
|
622
|
+
console.log("\u{1F4E6} No supported Tailwind version detected!");
|
|
623
|
+
const { installTailwind } = await import_inquirer2.default.prompt([
|
|
624
|
+
{
|
|
625
|
+
type: "confirm",
|
|
626
|
+
name: "installTailwind",
|
|
627
|
+
message: "Would you like to install Tailwind CSS?",
|
|
628
|
+
default: true
|
|
629
|
+
}
|
|
630
|
+
]);
|
|
631
|
+
if (!installTailwind) {
|
|
632
|
+
console.log("\u274C Tailwind CSS is required for the UI components to work properly!");
|
|
633
|
+
process.exit(1);
|
|
634
|
+
}
|
|
635
|
+
const installTailwindSpinner = (0, import_ora.default)(" Installing Tailwind CSS...").start();
|
|
636
|
+
const tailwindInstalled = await installDependencies({
|
|
637
|
+
cwd,
|
|
638
|
+
packageManager: projectInfo.packageManager,
|
|
639
|
+
dependencies: ["tailwindcss"]
|
|
640
|
+
});
|
|
641
|
+
if (tailwindInstalled) installTailwindSpinner.succeed();
|
|
642
|
+
else {
|
|
643
|
+
installTailwindSpinner.fail();
|
|
644
|
+
console.log("\u274C Failed to install Tailwind CSS. Please install it manually!");
|
|
645
|
+
process.exit(1);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
const config = await createConfig({ cwd, projectInfo });
|
|
649
|
+
if (!config) {
|
|
650
|
+
console.log("\u274C Failed to create configuration file!");
|
|
651
|
+
process.exit(1);
|
|
652
|
+
} else console.log("\u2714 Configuration file created successfully!");
|
|
653
|
+
const isCorrectLucideVersion = projectInfo.lucideVersion && projectInfo.lucideVersion >= 0.563 ? true : false;
|
|
654
|
+
if (!isCorrectLucideVersion) {
|
|
655
|
+
const lucideInstalled = await installDependencies({
|
|
656
|
+
cwd,
|
|
657
|
+
packageManager: projectInfo.packageManager,
|
|
658
|
+
dependencies: ["clsx", "lucide-react", "tailwind-merge"]
|
|
659
|
+
});
|
|
660
|
+
if (!lucideInstalled) {
|
|
661
|
+
console.log("\u274C Failed to install Lucide Icons. Please install it manually!");
|
|
662
|
+
process.exit(1);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
const themeSpinner = (0, import_ora.default)(" Setting up theme variables...").start();
|
|
666
|
+
const createdThemeFile = await createThemeFile({ cwd, version: projectInfo.tailwindVersion });
|
|
667
|
+
if (!createdThemeFile) {
|
|
668
|
+
themeSpinner.fail();
|
|
669
|
+
console.log("\u274C Failed to setup theme variables!");
|
|
670
|
+
process.exit(1);
|
|
671
|
+
}
|
|
672
|
+
themeSpinner.succeed();
|
|
673
|
+
console.log("\u{1F389} Project initialization completed successfully!");
|
|
674
|
+
console.log("\u{1F4A1} Feel free to update the values in the configuration file to your needs!");
|
|
675
|
+
process.exit(1);
|
|
676
|
+
} catch (error) {
|
|
677
|
+
console.error(`\u274C Error: ${error}`);
|
|
678
|
+
process.exit(1);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
// src/commands/add.ts
|
|
683
|
+
var import_fs_extra5 = __toESM(require("fs-extra"), 1);
|
|
684
|
+
var import_inquirer3 = __toESM(require("inquirer"), 1);
|
|
685
|
+
var import_ora2 = __toESM(require("ora"), 1);
|
|
686
|
+
var import_path5 = __toESM(require("path"), 1);
|
|
687
|
+
|
|
688
|
+
// src/commands/utils/registry.util.ts
|
|
689
|
+
var GITHUB_REPO = "sgx4u/sgx4u-ui";
|
|
690
|
+
var GITHUB_BRANCH = "production";
|
|
691
|
+
var GITHUB_RAW_BASE = `https://raw.githubusercontent.com/${GITHUB_REPO}/${GITHUB_BRANCH}`;
|
|
692
|
+
async function fetchRegistry(projectType) {
|
|
693
|
+
try {
|
|
694
|
+
let registryEnvironment;
|
|
695
|
+
if (projectType === "next" || projectType === "react") registryEnvironment = "react";
|
|
696
|
+
else return null;
|
|
697
|
+
const registryFile = `registry.${registryEnvironment}.json`;
|
|
698
|
+
const registryUrl = `${GITHUB_RAW_BASE}/src/content/${registryFile}`;
|
|
699
|
+
const response = await fetch(registryUrl);
|
|
700
|
+
if (!response.ok) return null;
|
|
701
|
+
const registry = await response.json();
|
|
702
|
+
return registry;
|
|
703
|
+
} catch {
|
|
704
|
+
return null;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
async function fetchComponent({
|
|
708
|
+
componentName,
|
|
709
|
+
projectType
|
|
710
|
+
}) {
|
|
711
|
+
try {
|
|
712
|
+
if (projectType === "none") return null;
|
|
713
|
+
const registry = await fetchRegistry(projectType);
|
|
714
|
+
if (!registry) return null;
|
|
715
|
+
for (const [registryKey, component] of Object.entries(registry.components)) {
|
|
716
|
+
if (registryKey === componentName) {
|
|
717
|
+
return {
|
|
718
|
+
...component,
|
|
719
|
+
name: registryKey
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
return null;
|
|
724
|
+
} catch {
|
|
725
|
+
return null;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
async function fetchComponentFile(filePath) {
|
|
729
|
+
try {
|
|
730
|
+
const fileUrl = `${GITHUB_RAW_BASE}/${filePath}`;
|
|
731
|
+
const response = await fetch(fileUrl);
|
|
732
|
+
if (!response.ok) return null;
|
|
733
|
+
return await response.text();
|
|
734
|
+
} catch {
|
|
735
|
+
console.log(`\u26A0\uFE0F Failed to fetch file from GitHub: ${filePath}`);
|
|
736
|
+
return null;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
// src/commands/validation/data.validate.ts
|
|
741
|
+
function validateComponentName(name) {
|
|
742
|
+
if (!name || name.trim().length < 1 || typeof name !== "string") return false;
|
|
743
|
+
if (!/^[a-zA-Z0-9-_.]+$/.test(name)) return false;
|
|
744
|
+
return true;
|
|
745
|
+
}
|
|
746
|
+
function validateDirectory(directory) {
|
|
747
|
+
if (!directory || directory.trim().length < 1 || typeof directory !== "string") return false;
|
|
748
|
+
if (directory.includes("..")) return false;
|
|
749
|
+
if (directory.includes("\\") || directory.includes("//")) return false;
|
|
750
|
+
return true;
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
// src/commands/add.ts
|
|
754
|
+
async function addComponent(componentName) {
|
|
755
|
+
try {
|
|
756
|
+
const cwd = process.cwd();
|
|
757
|
+
const validationSpinner = (0, import_ora2.default)(" Validating...").start();
|
|
758
|
+
if (!validateComponentName(componentName)) {
|
|
759
|
+
validationSpinner.fail();
|
|
760
|
+
console.log("\u274C Component name is invalid!");
|
|
761
|
+
process.exit(1);
|
|
762
|
+
}
|
|
763
|
+
const config = await getConfig(cwd);
|
|
764
|
+
if (!config) {
|
|
765
|
+
validationSpinner.fail();
|
|
766
|
+
console.log("\u274C Failed to get configuration! Please initialize SGX4U UI first!");
|
|
767
|
+
process.exit(1);
|
|
768
|
+
}
|
|
769
|
+
const projectInfo = await getProjectInfo(cwd);
|
|
770
|
+
if (projectInfo.project === "none") {
|
|
771
|
+
console.log("\u274C No supported project detected!");
|
|
772
|
+
process.exit(1);
|
|
773
|
+
}
|
|
774
|
+
validationSpinner.succeed();
|
|
775
|
+
const installingSpinner = (0, import_ora2.default)(` Installing ${componentName}`).start();
|
|
776
|
+
const component = await fetchComponent({ componentName, projectType: config.environment });
|
|
777
|
+
if (!component) {
|
|
778
|
+
installingSpinner.fail();
|
|
779
|
+
console.log("\u274C Failed to fetch component!");
|
|
780
|
+
process.exit(1);
|
|
781
|
+
}
|
|
782
|
+
const uiDirectory = config.uiDir;
|
|
783
|
+
const normalizedUiDirectory = uiDirectory.replace(/^[./\\]+/, "");
|
|
784
|
+
if (!normalizedUiDirectory || !validateDirectory(normalizedUiDirectory)) {
|
|
785
|
+
installingSpinner.fail();
|
|
786
|
+
console.log("\u274C Invalid directory!");
|
|
787
|
+
process.exit(1);
|
|
788
|
+
}
|
|
789
|
+
const baseDirectory = import_path5.default.join(cwd, normalizedUiDirectory);
|
|
790
|
+
const allFilesToInstall = /* @__PURE__ */ new Map();
|
|
791
|
+
const existingFiles = [];
|
|
792
|
+
const filesToProcess = component.files;
|
|
793
|
+
for (const file of filesToProcess) {
|
|
794
|
+
const normalizedOutputPath = file.outputPath.replace(/^ui[\\/]/, "");
|
|
795
|
+
const targetPath = import_path5.default.join(baseDirectory, normalizedOutputPath);
|
|
796
|
+
if (await import_fs_extra5.default.pathExists(targetPath)) {
|
|
797
|
+
existingFiles.push(file.outputPath);
|
|
798
|
+
} else {
|
|
799
|
+
allFilesToInstall.set(file.outputPath, {
|
|
800
|
+
filePath: file.path,
|
|
801
|
+
targetPath
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
if (existingFiles.length > 0) {
|
|
806
|
+
installingSpinner.stop();
|
|
807
|
+
console.log(`\u26A0\uFE0F Skipping existing files:`);
|
|
808
|
+
existingFiles.forEach((file) => console.log(` \u2022 ${file}`));
|
|
809
|
+
}
|
|
810
|
+
const installedFiles = [];
|
|
811
|
+
for (const [relativePath, { filePath, targetPath }] of allFilesToInstall) {
|
|
812
|
+
try {
|
|
813
|
+
const content = await fetchComponentFile(filePath);
|
|
814
|
+
if (!content) {
|
|
815
|
+
installingSpinner.fail();
|
|
816
|
+
console.log(`\u26A0\uFE0F Failed to fetch ${relativePath}`);
|
|
817
|
+
process.exit(1);
|
|
818
|
+
}
|
|
819
|
+
await import_fs_extra5.default.ensureDir(import_path5.default.dirname(targetPath));
|
|
820
|
+
await import_fs_extra5.default.writeFile(targetPath, content, "utf8");
|
|
821
|
+
installedFiles.push(relativePath);
|
|
822
|
+
} catch (error) {
|
|
823
|
+
installingSpinner.fail();
|
|
824
|
+
console.log(`\u26A0\uFE0F Failed to install ${relativePath}: ${error}`);
|
|
825
|
+
process.exit(1);
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
if (installedFiles.length === 0) {
|
|
829
|
+
installingSpinner.succeed();
|
|
830
|
+
console.log(`\u2714 ${componentName} is already up to date!`);
|
|
831
|
+
process.exit(1);
|
|
832
|
+
}
|
|
833
|
+
installingSpinner.succeed();
|
|
834
|
+
console.log("\u{1F4C1} Added files:");
|
|
835
|
+
installedFiles.forEach((file) => console.log(` \u2022 ${file}`));
|
|
836
|
+
const allPackageDependencies = new Set(component.dependencies);
|
|
837
|
+
if (allPackageDependencies.size > 0) {
|
|
838
|
+
console.log("\u{1F4E6} Dependencies detected:");
|
|
839
|
+
const installedDependencies = [];
|
|
840
|
+
const missingDependencies = [];
|
|
841
|
+
for (const dependency of Array.from(allPackageDependencies)) {
|
|
842
|
+
if (await isPackageInstalled({ packageName: dependency, cwd })) installedDependencies.push(dependency);
|
|
843
|
+
else missingDependencies.push(dependency);
|
|
844
|
+
}
|
|
845
|
+
if (installedDependencies.length > 0) {
|
|
846
|
+
console.log("\u2714 Already installed dependencies:");
|
|
847
|
+
installedDependencies.forEach((dep) => console.log(` \u2022 ${dep}`));
|
|
848
|
+
}
|
|
849
|
+
if (missingDependencies.length > 0) {
|
|
850
|
+
console.log("\u274C Missing dependencies:");
|
|
851
|
+
missingDependencies.forEach((dep) => console.log(` \u2022 ${dep}`));
|
|
852
|
+
const { installDeps } = await import_inquirer3.default.prompt([
|
|
853
|
+
{
|
|
854
|
+
type: "confirm",
|
|
855
|
+
name: "installDeps",
|
|
856
|
+
message: `Auto install missing dependencies using ${projectInfo.packageManager}?`,
|
|
857
|
+
default: true
|
|
858
|
+
}
|
|
859
|
+
]);
|
|
860
|
+
if (installDeps) {
|
|
861
|
+
console.log(`\u{1F4E6} Installing missing dependencies using ${projectInfo.packageManager}...`);
|
|
862
|
+
const dependencyInstalled = await installDependencies({
|
|
863
|
+
cwd,
|
|
864
|
+
packageManager: projectInfo.packageManager,
|
|
865
|
+
dependencies: missingDependencies
|
|
866
|
+
});
|
|
867
|
+
if (dependencyInstalled) console.log("\u2714 Missing dependencies installed successfully!");
|
|
868
|
+
else console.log("\u274C Failed to install missing dependencies!");
|
|
869
|
+
} else {
|
|
870
|
+
console.log("\u26A0\uFE0F Please install missing dependencies manually:");
|
|
871
|
+
missingDependencies.forEach((dep) => console.log(` \u2022 ${dep}`));
|
|
872
|
+
}
|
|
873
|
+
} else {
|
|
874
|
+
console.log("\u2714 All dependencies are already installed!");
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
process.exit(1);
|
|
878
|
+
} catch (error) {
|
|
879
|
+
console.error(`\u274C Error: ${error}`);
|
|
880
|
+
process.exit(1);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
// src/commands/list.ts
|
|
885
|
+
var import_ora3 = __toESM(require("ora"), 1);
|
|
886
|
+
async function listComponents() {
|
|
887
|
+
const configSpinner = (0, import_ora3.default)(" Checking...").start();
|
|
888
|
+
try {
|
|
889
|
+
const cwd = process.cwd();
|
|
890
|
+
const config = await getConfig(cwd);
|
|
891
|
+
if (!config) {
|
|
892
|
+
configSpinner.fail();
|
|
893
|
+
console.log('\u274C No configuration found! Please run "sgx4u-ui init" first.');
|
|
894
|
+
process.exit(1);
|
|
895
|
+
}
|
|
896
|
+
configSpinner.succeed();
|
|
897
|
+
const fetchSpinner = (0, import_ora3.default)(" Fetching available components...").start();
|
|
898
|
+
const registry = await fetchRegistry(config.environment);
|
|
899
|
+
if (!registry) {
|
|
900
|
+
fetchSpinner.fail();
|
|
901
|
+
console.log("\u26A0\uFE0F Failed to fetch registry from GitHub!");
|
|
902
|
+
process.exit(1);
|
|
903
|
+
}
|
|
904
|
+
fetchSpinner.succeed();
|
|
905
|
+
console.log("\u{1F4CB} Available Components:");
|
|
906
|
+
Object.entries(registry.components).forEach(([registryKey, component]) => {
|
|
907
|
+
const componentName = component.name ?? registryKey;
|
|
908
|
+
console.log(`${componentName}: ${component.description}`);
|
|
909
|
+
console.log(` Install: sgx4u-ui add ${componentName}`);
|
|
910
|
+
console.log();
|
|
911
|
+
});
|
|
912
|
+
process.exit(1);
|
|
913
|
+
} catch (error) {
|
|
914
|
+
configSpinner.fail();
|
|
915
|
+
console.error(`\u274C Error: ${error}`);
|
|
916
|
+
process.exit(1);
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
920
|
+
0 && (module.exports = {
|
|
921
|
+
addComponent,
|
|
922
|
+
initConfig,
|
|
923
|
+
listComponents
|
|
924
|
+
});
|