@surreal-ui/cli 0.6.0
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/dist/index.js +588 -0
- package/package.json +35 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
import pc5 from "picocolors";
|
|
6
|
+
|
|
7
|
+
// src/commands/add.ts
|
|
8
|
+
import fs3 from "fs";
|
|
9
|
+
import path3 from "path";
|
|
10
|
+
import pc from "picocolors";
|
|
11
|
+
import prompts from "prompts";
|
|
12
|
+
|
|
13
|
+
// src/utils/registry.ts
|
|
14
|
+
import {
|
|
15
|
+
RegistryService
|
|
16
|
+
} from "@surreal-ui/core";
|
|
17
|
+
var DEFAULT_REGISTRY_URL = "https://surreal-ui.com/r";
|
|
18
|
+
async function fetchRegistryItem(options) {
|
|
19
|
+
const { componentId, aestheticId, framework = "svelte", registryUrl } = options;
|
|
20
|
+
if (registryUrl) {
|
|
21
|
+
try {
|
|
22
|
+
const baseUrl = registryUrl.replace(/\/+$/, "");
|
|
23
|
+
const url = aestheticId ? `${baseUrl}/${aestheticId}/${componentId}.json?framework=${framework}` : `${baseUrl}/${componentId}.json?framework=${framework}`;
|
|
24
|
+
const res = await fetch(url, {
|
|
25
|
+
headers: { Accept: "application/json" },
|
|
26
|
+
signal: AbortSignal.timeout(3e3)
|
|
27
|
+
});
|
|
28
|
+
if (res.ok) {
|
|
29
|
+
return await res.json();
|
|
30
|
+
}
|
|
31
|
+
} catch {
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const localItem = await RegistryService.getRegistryItem({
|
|
36
|
+
componentId,
|
|
37
|
+
aestheticId,
|
|
38
|
+
framework
|
|
39
|
+
});
|
|
40
|
+
if (localItem) return localItem;
|
|
41
|
+
} catch {
|
|
42
|
+
}
|
|
43
|
+
if (!registryUrl) {
|
|
44
|
+
try {
|
|
45
|
+
const url = aestheticId ? `${DEFAULT_REGISTRY_URL}/${aestheticId}/${componentId}.json?framework=${framework}` : `${DEFAULT_REGISTRY_URL}/${componentId}.json?framework=${framework}`;
|
|
46
|
+
const res = await fetch(url, {
|
|
47
|
+
headers: { Accept: "application/json" },
|
|
48
|
+
signal: AbortSignal.timeout(1500)
|
|
49
|
+
});
|
|
50
|
+
if (res.ok) {
|
|
51
|
+
return await res.json();
|
|
52
|
+
}
|
|
53
|
+
} catch {
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
async function fetchRegistryIndex(options = {}) {
|
|
59
|
+
const { framework = "svelte", registryUrl } = options;
|
|
60
|
+
if (registryUrl) {
|
|
61
|
+
try {
|
|
62
|
+
const baseUrl = registryUrl.replace(/\/+$/, "");
|
|
63
|
+
const url = `${baseUrl}/index.json?framework=${framework}`;
|
|
64
|
+
const res = await fetch(url, {
|
|
65
|
+
headers: { Accept: "application/json" },
|
|
66
|
+
signal: AbortSignal.timeout(3e3)
|
|
67
|
+
});
|
|
68
|
+
if (res.ok) {
|
|
69
|
+
return await res.json();
|
|
70
|
+
}
|
|
71
|
+
} catch {
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const localIndex = await RegistryService.getRegistryIndex(framework);
|
|
76
|
+
if (localIndex && localIndex.length > 0) return localIndex;
|
|
77
|
+
} catch {
|
|
78
|
+
}
|
|
79
|
+
if (!registryUrl) {
|
|
80
|
+
try {
|
|
81
|
+
const url = `${DEFAULT_REGISTRY_URL}/index.json?framework=${framework}`;
|
|
82
|
+
const res = await fetch(url, {
|
|
83
|
+
headers: { Accept: "application/json" },
|
|
84
|
+
signal: AbortSignal.timeout(1500)
|
|
85
|
+
});
|
|
86
|
+
if (res.ok) {
|
|
87
|
+
return await res.json();
|
|
88
|
+
}
|
|
89
|
+
} catch {
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/utils/project.ts
|
|
96
|
+
import fs from "fs";
|
|
97
|
+
import path from "path";
|
|
98
|
+
function getPackageJson(cwd = process.cwd()) {
|
|
99
|
+
try {
|
|
100
|
+
const pkgPath = path.join(cwd, "package.json");
|
|
101
|
+
if (fs.existsSync(pkgPath)) {
|
|
102
|
+
return JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
103
|
+
}
|
|
104
|
+
} catch {
|
|
105
|
+
}
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
function getProjectConfig(cwd = process.cwd()) {
|
|
109
|
+
const surrealConfigPath = path.join(cwd, "surreal.json");
|
|
110
|
+
if (fs.existsSync(surrealConfigPath)) {
|
|
111
|
+
try {
|
|
112
|
+
return JSON.parse(fs.readFileSync(surrealConfigPath, "utf8"));
|
|
113
|
+
} catch {
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const componentsConfigPath = path.join(cwd, "components.json");
|
|
117
|
+
if (fs.existsSync(componentsConfigPath)) {
|
|
118
|
+
try {
|
|
119
|
+
const data = JSON.parse(fs.readFileSync(componentsConfigPath, "utf8"));
|
|
120
|
+
const isSvelte = Boolean(data.svelte || data.$schema?.includes("shadcn-svelte"));
|
|
121
|
+
return {
|
|
122
|
+
framework: isSvelte ? "svelte" : "react",
|
|
123
|
+
componentsPath: data.aliases?.ui || (isSvelte ? "src/lib/components/ui" : "components/ui"),
|
|
124
|
+
defaultAesthetic: data.style || "shadcn",
|
|
125
|
+
aliases: data.aliases
|
|
126
|
+
};
|
|
127
|
+
} catch {
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
function detectFramework(cwd = process.cwd()) {
|
|
133
|
+
const existingConfig = getProjectConfig(cwd);
|
|
134
|
+
if (existingConfig?.framework) return existingConfig.framework;
|
|
135
|
+
const pkg = getPackageJson(cwd);
|
|
136
|
+
if (pkg) {
|
|
137
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
138
|
+
if (deps["@sveltejs/kit"] || deps["svelte"]) {
|
|
139
|
+
return "svelte";
|
|
140
|
+
}
|
|
141
|
+
if (deps["next"] || deps["react"] || deps["react-dom"]) {
|
|
142
|
+
return "react";
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (fs.existsSync(path.join(cwd, "svelte.config.js")) || fs.existsSync(path.join(cwd, "svelte.config.ts"))) {
|
|
146
|
+
return "svelte";
|
|
147
|
+
}
|
|
148
|
+
if (fs.existsSync(path.join(cwd, "next.config.js")) || fs.existsSync(path.join(cwd, "next.config.mjs")) || fs.existsSync(path.join(cwd, "next.config.ts"))) {
|
|
149
|
+
return "react";
|
|
150
|
+
}
|
|
151
|
+
return "svelte";
|
|
152
|
+
}
|
|
153
|
+
function getDefaultComponentsPath(framework, cwd = process.cwd()) {
|
|
154
|
+
const existingConfig = getProjectConfig(cwd);
|
|
155
|
+
if (existingConfig?.componentsPath) return existingConfig.componentsPath;
|
|
156
|
+
if (framework === "svelte") {
|
|
157
|
+
if (fs.existsSync(path.join(cwd, "src/lib"))) {
|
|
158
|
+
return "src/lib/components/ui";
|
|
159
|
+
}
|
|
160
|
+
return "src/components/ui";
|
|
161
|
+
}
|
|
162
|
+
if (framework === "react") {
|
|
163
|
+
if (fs.existsSync(path.join(cwd, "src"))) {
|
|
164
|
+
return "src/components/ui";
|
|
165
|
+
}
|
|
166
|
+
return "components/ui";
|
|
167
|
+
}
|
|
168
|
+
return "src/components/ui";
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// src/utils/pm.ts
|
|
172
|
+
import fs2 from "fs";
|
|
173
|
+
import path2 from "path";
|
|
174
|
+
import { execSync } from "child_process";
|
|
175
|
+
function detectPackageManager(cwd = process.cwd()) {
|
|
176
|
+
if (fs2.existsSync(path2.join(cwd, "pnpm-lock.yaml"))) return "pnpm";
|
|
177
|
+
if (fs2.existsSync(path2.join(cwd, "bun.lockb")) || fs2.existsSync(path2.join(cwd, "bun.lock")))
|
|
178
|
+
return "bun";
|
|
179
|
+
if (fs2.existsSync(path2.join(cwd, "yarn.lock"))) return "yarn";
|
|
180
|
+
if (fs2.existsSync(path2.join(cwd, "package-lock.json"))) return "npm";
|
|
181
|
+
const userAgent = process.env.npm_config_user_agent;
|
|
182
|
+
if (userAgent) {
|
|
183
|
+
if (userAgent.startsWith("pnpm")) return "pnpm";
|
|
184
|
+
if (userAgent.startsWith("bun")) return "bun";
|
|
185
|
+
if (userAgent.startsWith("yarn")) return "yarn";
|
|
186
|
+
}
|
|
187
|
+
return "npm";
|
|
188
|
+
}
|
|
189
|
+
function installDependencies(dependencies, options = {}) {
|
|
190
|
+
if (!dependencies || dependencies.length === 0) return;
|
|
191
|
+
const cwd = options.cwd || process.cwd();
|
|
192
|
+
const pm = options.pm || detectPackageManager(cwd);
|
|
193
|
+
const isDev = Boolean(options.dev);
|
|
194
|
+
let command;
|
|
195
|
+
const depsString = dependencies.join(" ");
|
|
196
|
+
switch (pm) {
|
|
197
|
+
case "pnpm":
|
|
198
|
+
command = `pnpm add ${isDev ? "-D " : ""}${depsString}`;
|
|
199
|
+
break;
|
|
200
|
+
case "bun":
|
|
201
|
+
command = `bun add ${isDev ? "-d " : ""}${depsString}`;
|
|
202
|
+
break;
|
|
203
|
+
case "yarn":
|
|
204
|
+
command = `yarn add ${isDev ? "-D " : ""}${depsString}`;
|
|
205
|
+
break;
|
|
206
|
+
case "npm":
|
|
207
|
+
default:
|
|
208
|
+
command = `npm install ${isDev ? "--save-dev " : ""}${depsString}`;
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
execSync(command, { cwd, stdio: "inherit" });
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// src/commands/add.ts
|
|
215
|
+
async function addCommand(componentArg, options = {}) {
|
|
216
|
+
const cwd = options.cwd || process.cwd();
|
|
217
|
+
const projectConfig = getProjectConfig(cwd);
|
|
218
|
+
let framework = options.framework || projectConfig?.framework || detectFramework(cwd);
|
|
219
|
+
let componentId = componentArg?.toLowerCase().trim();
|
|
220
|
+
if (!componentId) {
|
|
221
|
+
const index = await fetchRegistryIndex({ framework, registryUrl: options.registry });
|
|
222
|
+
if (!index || index.length === 0) {
|
|
223
|
+
console.error(pc.red("\u2716 No components found in registry."));
|
|
224
|
+
process.exit(1);
|
|
225
|
+
}
|
|
226
|
+
const response = await prompts({
|
|
227
|
+
type: "autocomplete",
|
|
228
|
+
name: "component",
|
|
229
|
+
message: "Select a component to add:",
|
|
230
|
+
choices: index.map((item2) => ({
|
|
231
|
+
title: `${item2.title} (${item2.name})`,
|
|
232
|
+
value: item2.name,
|
|
233
|
+
description: item2.description
|
|
234
|
+
}))
|
|
235
|
+
});
|
|
236
|
+
if (!response.component) {
|
|
237
|
+
console.log(pc.yellow("Operation cancelled."));
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
componentId = response.component;
|
|
241
|
+
}
|
|
242
|
+
let aestheticId = options.aesthetic?.toLowerCase().trim() || projectConfig?.defaultAesthetic;
|
|
243
|
+
if (!aestheticId && !options.yes) {
|
|
244
|
+
const index = await fetchRegistryIndex({ framework, registryUrl: options.registry });
|
|
245
|
+
const currentItem = index.find((item2) => item2.name === componentId);
|
|
246
|
+
const availableAesthetics = currentItem?.aesthetics || [
|
|
247
|
+
"glassmorphism",
|
|
248
|
+
"neubrutalism",
|
|
249
|
+
"minimalist",
|
|
250
|
+
"shadcn"
|
|
251
|
+
];
|
|
252
|
+
if (availableAesthetics.length > 1) {
|
|
253
|
+
const response = await prompts({
|
|
254
|
+
type: "select",
|
|
255
|
+
name: "aesthetic",
|
|
256
|
+
message: `Choose an aesthetic style for ${componentId}:`,
|
|
257
|
+
choices: availableAesthetics.map((a) => ({
|
|
258
|
+
title: a,
|
|
259
|
+
value: a
|
|
260
|
+
})),
|
|
261
|
+
initial: 0
|
|
262
|
+
});
|
|
263
|
+
if (response.aesthetic) {
|
|
264
|
+
aestheticId = response.aesthetic;
|
|
265
|
+
}
|
|
266
|
+
} else {
|
|
267
|
+
aestheticId = availableAesthetics[0];
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
console.log(pc.cyan(`
|
|
271
|
+
Fetching ${pc.bold(componentId)} [${aestheticId || "default"}]...`));
|
|
272
|
+
const item = await fetchRegistryItem({
|
|
273
|
+
componentId,
|
|
274
|
+
aestheticId,
|
|
275
|
+
framework,
|
|
276
|
+
registryUrl: options.registry
|
|
277
|
+
});
|
|
278
|
+
if (!item || !item.files || item.files.length === 0) {
|
|
279
|
+
console.error(
|
|
280
|
+
pc.red(
|
|
281
|
+
`\u2716 Component '${componentId}'${aestheticId ? ` with aesthetic '${aestheticId}'` : ""} not found.`
|
|
282
|
+
)
|
|
283
|
+
);
|
|
284
|
+
process.exit(1);
|
|
285
|
+
}
|
|
286
|
+
const targetDir = options.path || getDefaultComponentsPath(framework, cwd);
|
|
287
|
+
const fullTargetDir = path3.resolve(cwd, targetDir);
|
|
288
|
+
for (const file of item.files) {
|
|
289
|
+
const fileName = path3.basename(file.path);
|
|
290
|
+
const destPath = path3.join(fullTargetDir, fileName);
|
|
291
|
+
const relativeDest = path3.relative(cwd, destPath);
|
|
292
|
+
if (fs3.existsSync(destPath) && !options.overwrite && !options.yes) {
|
|
293
|
+
const { overwrite } = await prompts({
|
|
294
|
+
type: "confirm",
|
|
295
|
+
name: "overwrite",
|
|
296
|
+
message: `File ${pc.yellow(relativeDest)} already exists. Overwrite?`,
|
|
297
|
+
initial: false
|
|
298
|
+
});
|
|
299
|
+
if (!overwrite) {
|
|
300
|
+
console.log(pc.gray(`Skipped ${relativeDest}`));
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
fs3.mkdirSync(path3.dirname(destPath), { recursive: true });
|
|
305
|
+
fs3.writeFileSync(destPath, file.content, "utf8");
|
|
306
|
+
console.log(pc.green(`\u2714 Created ${pc.bold(relativeDest)}`));
|
|
307
|
+
}
|
|
308
|
+
if (item.dependencies && item.dependencies.length > 0) {
|
|
309
|
+
const pkg = getPackageJson(cwd);
|
|
310
|
+
const installed = {
|
|
311
|
+
...pkg?.dependencies || {},
|
|
312
|
+
...pkg?.devDependencies || {}
|
|
313
|
+
};
|
|
314
|
+
const missingDeps = item.dependencies.filter((dep) => !installed[dep]);
|
|
315
|
+
if (missingDeps.length > 0) {
|
|
316
|
+
const pm = detectPackageManager(cwd);
|
|
317
|
+
let install = Boolean(options.yes);
|
|
318
|
+
if (!options.yes) {
|
|
319
|
+
const res = await prompts({
|
|
320
|
+
type: "confirm",
|
|
321
|
+
name: "install",
|
|
322
|
+
message: `Install required peer dependencies (${pc.cyan(missingDeps.join(", "))}) using ${pm}?`,
|
|
323
|
+
initial: true
|
|
324
|
+
});
|
|
325
|
+
install = Boolean(res.install);
|
|
326
|
+
}
|
|
327
|
+
if (install) {
|
|
328
|
+
console.log(pc.cyan(`
|
|
329
|
+
Installing dependencies with ${pm}...`));
|
|
330
|
+
try {
|
|
331
|
+
installDependencies(missingDeps, { cwd, pm });
|
|
332
|
+
console.log(pc.green("\u2714 Dependencies installed successfully."));
|
|
333
|
+
} catch (err) {
|
|
334
|
+
console.error(
|
|
335
|
+
pc.yellow(`\u26A0 Could not install dependencies automatically: ${err.message}`)
|
|
336
|
+
);
|
|
337
|
+
console.log(pc.gray(`Run manually: ${pm} add ${missingDeps.join(" ")}`));
|
|
338
|
+
}
|
|
339
|
+
} else {
|
|
340
|
+
console.log(
|
|
341
|
+
pc.yellow(
|
|
342
|
+
`
|
|
343
|
+
Make sure to install required dependencies: ${pm} add ${missingDeps.join(" ")}`
|
|
344
|
+
)
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
const mainFile = item.files[0];
|
|
350
|
+
const symbolName = item.meta?.symbolName || path3.basename(mainFile.path, path3.extname(mainFile.path));
|
|
351
|
+
const relPath = path3.relative(cwd, path3.join(fullTargetDir, path3.basename(mainFile.path)));
|
|
352
|
+
console.log(pc.bold(pc.green(`
|
|
353
|
+
\u2728 Successfully added ${symbolName}!`)));
|
|
354
|
+
console.log(pc.gray(`Import in your code:`));
|
|
355
|
+
if (framework === "svelte") {
|
|
356
|
+
const aliasPath = relPath.startsWith("src/lib/") ? relPath.replace(/^src\/lib\//, "$lib/") : `./${relPath}`;
|
|
357
|
+
console.log(pc.cyan(` import ${symbolName} from '${aliasPath}';
|
|
358
|
+
`));
|
|
359
|
+
} else {
|
|
360
|
+
console.log(pc.cyan(` import ${symbolName} from './${relPath}';
|
|
361
|
+
`));
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// src/commands/list.ts
|
|
366
|
+
import pc2 from "picocolors";
|
|
367
|
+
async function listCommand(options) {
|
|
368
|
+
const framework = options.framework || "svelte";
|
|
369
|
+
console.log(pc2.cyan(`
|
|
370
|
+
Fetching component catalog from registry...
|
|
371
|
+
`));
|
|
372
|
+
const items = await fetchRegistryIndex({ framework, registryUrl: options.registry });
|
|
373
|
+
if (!items || items.length === 0) {
|
|
374
|
+
console.log(pc2.yellow("No components found in the registry."));
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
console.log(pc2.bold(pc2.white(`Available Components (${items.length}):`)));
|
|
378
|
+
console.log(pc2.gray("\u2500".repeat(70)));
|
|
379
|
+
for (const item of items) {
|
|
380
|
+
const aesthetics = item.aesthetics && item.aesthetics.length > 0 ? pc2.magenta(`[${item.aesthetics.join(", ")}]`) : pc2.gray("[default]");
|
|
381
|
+
console.log(
|
|
382
|
+
`${pc2.bold(pc2.green(item.name.padEnd(16)))} ${pc2.white(item.title.padEnd(20))} ${aesthetics}`
|
|
383
|
+
);
|
|
384
|
+
if (item.description) {
|
|
385
|
+
console.log(` ${pc2.gray(item.description)}`);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
console.log(pc2.gray("\u2500".repeat(70)));
|
|
389
|
+
console.log(
|
|
390
|
+
pc2.gray(`
|
|
391
|
+
Add a component: ${pc2.cyan("npx surreal-ui add <component> --aesthetic <style>")}
|
|
392
|
+
`)
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// src/commands/init.ts
|
|
397
|
+
import fs4 from "fs";
|
|
398
|
+
import path4 from "path";
|
|
399
|
+
import pc3 from "picocolors";
|
|
400
|
+
import prompts2 from "prompts";
|
|
401
|
+
async function initCommand(options = {}) {
|
|
402
|
+
const cwd = options.cwd || process.cwd();
|
|
403
|
+
const configPath = path4.join(cwd, "surreal.json");
|
|
404
|
+
if (fs4.existsSync(configPath) && !options.yes) {
|
|
405
|
+
const { overwrite } = await prompts2({
|
|
406
|
+
type: "confirm",
|
|
407
|
+
name: "overwrite",
|
|
408
|
+
message: "surreal.json already exists in this directory. Overwrite?",
|
|
409
|
+
initial: false
|
|
410
|
+
});
|
|
411
|
+
if (!overwrite) {
|
|
412
|
+
console.log(pc3.yellow("Initialization cancelled."));
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
const detectedFramework = detectFramework(cwd);
|
|
417
|
+
let framework = detectedFramework;
|
|
418
|
+
let aesthetic = "glassmorphism";
|
|
419
|
+
let componentsPath = getDefaultComponentsPath(detectedFramework, cwd);
|
|
420
|
+
if (!options.yes) {
|
|
421
|
+
const response = await prompts2([
|
|
422
|
+
{
|
|
423
|
+
type: "select",
|
|
424
|
+
name: "framework",
|
|
425
|
+
message: "Which framework are you building with?",
|
|
426
|
+
choices: [
|
|
427
|
+
{ title: "Svelte 5 (Runes)", value: "svelte" },
|
|
428
|
+
{ title: "React 19 (TSX)", value: "react" },
|
|
429
|
+
{ title: "WebComponent (Custom Elements)", value: "webcomponent" }
|
|
430
|
+
],
|
|
431
|
+
initial: detectedFramework === "react" ? 1 : 0
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
type: "select",
|
|
435
|
+
name: "aesthetic",
|
|
436
|
+
message: "Default aesthetic style:",
|
|
437
|
+
choices: [
|
|
438
|
+
{ title: "Glassmorphism (Frosted, translucent, glowing)", value: "glassmorphism" },
|
|
439
|
+
{ title: "Neubrutalism (High-contrast, bold outlines, vibrant)", value: "neubrutalism" },
|
|
440
|
+
{ title: "Minimalist (Clean, understated, subtle borders)", value: "minimalist" },
|
|
441
|
+
{ title: "Shadcn (Classic neutral, zinc, modern)", value: "shadcn" }
|
|
442
|
+
],
|
|
443
|
+
initial: 0
|
|
444
|
+
},
|
|
445
|
+
{
|
|
446
|
+
type: "text",
|
|
447
|
+
name: "componentsPath",
|
|
448
|
+
message: "Where would you like to place your UI components?",
|
|
449
|
+
initial: (prev, values) => getDefaultComponentsPath(values.framework, cwd)
|
|
450
|
+
}
|
|
451
|
+
]);
|
|
452
|
+
if (!response.framework) {
|
|
453
|
+
console.log(pc3.yellow("Initialization cancelled."));
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
framework = response.framework;
|
|
457
|
+
aesthetic = response.aesthetic;
|
|
458
|
+
componentsPath = response.componentsPath;
|
|
459
|
+
}
|
|
460
|
+
const config = {
|
|
461
|
+
$schema: "https://surreal-ui.com/schema.json",
|
|
462
|
+
framework,
|
|
463
|
+
defaultAesthetic: aesthetic,
|
|
464
|
+
componentsPath,
|
|
465
|
+
aliases: {
|
|
466
|
+
components: componentsPath,
|
|
467
|
+
ui: componentsPath
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
fs4.writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n", "utf8");
|
|
471
|
+
console.log(pc3.bold(pc3.green(`
|
|
472
|
+
\u2714 Configuration saved to ${pc3.bold("surreal.json")}`)));
|
|
473
|
+
console.log(
|
|
474
|
+
pc3.gray(`You can now add components with: ${pc3.cyan("npx surreal-ui add <component>")}
|
|
475
|
+
`)
|
|
476
|
+
);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// src/commands/diff.ts
|
|
480
|
+
import fs5 from "fs";
|
|
481
|
+
import path5 from "path";
|
|
482
|
+
import pc4 from "picocolors";
|
|
483
|
+
async function diffCommand(componentArg, options = {}) {
|
|
484
|
+
const cwd = options.cwd || process.cwd();
|
|
485
|
+
const componentId = componentArg?.toLowerCase().trim();
|
|
486
|
+
if (!componentId) {
|
|
487
|
+
console.error(
|
|
488
|
+
pc4.red("\u2716 Please specify a component to check diff: surreal-ui diff <component>")
|
|
489
|
+
);
|
|
490
|
+
process.exit(1);
|
|
491
|
+
}
|
|
492
|
+
const projectConfig = getProjectConfig(cwd);
|
|
493
|
+
const framework = options.framework || projectConfig?.framework || detectFramework(cwd);
|
|
494
|
+
const aestheticId = options.aesthetic || projectConfig?.defaultAesthetic;
|
|
495
|
+
const item = await fetchRegistryItem({
|
|
496
|
+
componentId,
|
|
497
|
+
aestheticId,
|
|
498
|
+
framework,
|
|
499
|
+
registryUrl: options.registry
|
|
500
|
+
});
|
|
501
|
+
if (!item || !item.files || item.files.length === 0) {
|
|
502
|
+
console.error(pc4.red(`\u2716 Component '${componentId}' not found in registry.`));
|
|
503
|
+
process.exit(1);
|
|
504
|
+
}
|
|
505
|
+
const targetDir = options.path || getDefaultComponentsPath(framework, cwd);
|
|
506
|
+
const fullTargetDir = path5.resolve(cwd, targetDir);
|
|
507
|
+
for (const file of item.files) {
|
|
508
|
+
const fileName = path5.basename(file.path);
|
|
509
|
+
const destPath = path5.join(fullTargetDir, fileName);
|
|
510
|
+
if (!fs5.existsSync(destPath)) {
|
|
511
|
+
console.log(
|
|
512
|
+
pc4.yellow(`Component file does not exist locally: ${path5.relative(cwd, destPath)}`)
|
|
513
|
+
);
|
|
514
|
+
console.log(pc4.gray(`Run 'npx surreal-ui add ${componentId}' to install it.`));
|
|
515
|
+
continue;
|
|
516
|
+
}
|
|
517
|
+
const localContent = fs5.readFileSync(destPath, "utf8");
|
|
518
|
+
if (localContent.trim() === file.content.trim()) {
|
|
519
|
+
console.log(
|
|
520
|
+
pc4.green(
|
|
521
|
+
`\u2714 ${fileName} is up to date with registry version (${item.meta?.version || "latest"}).`
|
|
522
|
+
)
|
|
523
|
+
);
|
|
524
|
+
} else {
|
|
525
|
+
console.log(
|
|
526
|
+
pc4.yellow(
|
|
527
|
+
`! ${fileName} has local modifications or differs from registry version (${item.meta?.version || "latest"}).`
|
|
528
|
+
)
|
|
529
|
+
);
|
|
530
|
+
console.log(
|
|
531
|
+
pc4.gray(
|
|
532
|
+
`Local size: ${localContent.length} bytes, Registry size: ${file.content.length} bytes`
|
|
533
|
+
)
|
|
534
|
+
);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// src/index.ts
|
|
540
|
+
var program = new Command();
|
|
541
|
+
program.name("surreal-ui").description("Surreal UI CLI - Add multi-platform UI components directly to your codebase").version("0.5.4");
|
|
542
|
+
program.command("add [component]").description("Add a component to your project").option(
|
|
543
|
+
"-a, --aesthetic <style>",
|
|
544
|
+
"Aesthetic style (glassmorphism, neubrutalism, minimalist, shadcn)"
|
|
545
|
+
).option("-f, --framework <framework>", "Target framework (svelte, react, webcomponent)").option("-p, --path <path>", "Destination directory for components").option("-o, --overwrite", "Overwrite existing files without asking").option("-y, --yes", "Skip confirmation prompts").option("-r, --registry <url>", "Custom registry URL").action(async (component, options) => {
|
|
546
|
+
try {
|
|
547
|
+
await addCommand(component, options);
|
|
548
|
+
process.exit(0);
|
|
549
|
+
} catch (err) {
|
|
550
|
+
console.error(pc5.red(`
|
|
551
|
+
\u2716 Error: ${err.message}`));
|
|
552
|
+
process.exit(1);
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
program.command("list").description("List all available components in the registry").option("-f, --framework <framework>", "Framework filter (svelte, react, webcomponent)").option("-r, --registry <url>", "Custom registry URL").action(async (options) => {
|
|
556
|
+
try {
|
|
557
|
+
await listCommand(options);
|
|
558
|
+
process.exit(0);
|
|
559
|
+
} catch (err) {
|
|
560
|
+
console.error(pc5.red(`
|
|
561
|
+
\u2716 Error: ${err.message}`));
|
|
562
|
+
process.exit(1);
|
|
563
|
+
}
|
|
564
|
+
});
|
|
565
|
+
program.command("init").description("Initialize surreal.json configuration in your project").option("-y, --yes", "Use defaults without interactive prompt").action(async (options) => {
|
|
566
|
+
try {
|
|
567
|
+
await initCommand(options);
|
|
568
|
+
process.exit(0);
|
|
569
|
+
} catch (err) {
|
|
570
|
+
console.error(pc5.red(`
|
|
571
|
+
\u2716 Error: ${err.message}`));
|
|
572
|
+
process.exit(1);
|
|
573
|
+
}
|
|
574
|
+
});
|
|
575
|
+
program.command("diff [component]").description("Compare local component file with the latest version in the registry").option("-a, --aesthetic <style>", "Aesthetic style to compare").option("-f, --framework <framework>", "Framework target").option("-p, --path <path>", "Custom components path").option("-r, --registry <url>", "Custom registry URL").action(async (component, options) => {
|
|
576
|
+
try {
|
|
577
|
+
await diffCommand(component, options);
|
|
578
|
+
process.exit(0);
|
|
579
|
+
} catch (err) {
|
|
580
|
+
console.error(pc5.red(`
|
|
581
|
+
\u2716 Error: ${err.message}`));
|
|
582
|
+
process.exit(1);
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
program.parse(process.argv);
|
|
586
|
+
if (!process.argv.slice(2).length) {
|
|
587
|
+
program.outputHelp();
|
|
588
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@surreal-ui/cli",
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "Surreal UI CLI - Add multi-platform UI components directly to your codebase",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"surreal-ui": "./dist/index.js",
|
|
9
|
+
"surreal": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsup",
|
|
19
|
+
"dev": "tsup --watch",
|
|
20
|
+
"test": "tsx --test test/*.test.ts"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@surreal-ui/core": "workspace:*",
|
|
24
|
+
"commander": "^13.1.0",
|
|
25
|
+
"picocolors": "^1.1.1",
|
|
26
|
+
"prompts": "^2.4.2"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/node": "^20.19.43",
|
|
30
|
+
"@types/prompts": "^2.4.9",
|
|
31
|
+
"tsup": "^8.0.2",
|
|
32
|
+
"tsx": "^4.23.12",
|
|
33
|
+
"typescript": "^5.5.0"
|
|
34
|
+
}
|
|
35
|
+
}
|