basuicn 0.1.6 → 0.1.8

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.
@@ -0,0 +1,849 @@
1
+ #!/usr/bin/env node
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 __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+
25
+ // scripts/ui-cli.ts
26
+ var import_fs = __toESM(require("fs"), 1);
27
+ var import_path = __toESM(require("path"), 1);
28
+ var import_child_process = require("child_process");
29
+ var import_readline = __toESM(require("readline"), 1);
30
+ var VERSION = "0.1.7";
31
+ var REGISTRY_LOCAL = "./registry.json";
32
+ var REGISTRY_REMOTE = "https://raw.githubusercontent.com/Basuicn/basuicn-core/main/registry.json";
33
+ var c = {
34
+ reset: "\x1B[0m",
35
+ bold: "\x1B[1m",
36
+ dim: "\x1B[2m",
37
+ green: "\x1B[32m",
38
+ yellow: "\x1B[33m",
39
+ red: "\x1B[31m",
40
+ cyan: "\x1B[36m",
41
+ magenta: "\x1B[35m",
42
+ blue: "\x1B[34m",
43
+ gray: "\x1B[90m"
44
+ };
45
+ var log = (msg) => console.log(`${c.cyan}\u25B8${c.reset} ${msg}`);
46
+ var ok = (msg) => console.log(`${c.green}\u2714${c.reset} ${msg}`);
47
+ var warn = (msg) => console.warn(`${c.yellow}\u26A0${c.reset} ${msg}`);
48
+ var error = (msg) => console.error(`${c.red}\u2716${c.reset} ${msg}`);
49
+ var getTargetProjectDir = () => process.cwd();
50
+ var ask = (question) => {
51
+ const rl = import_readline.default.createInterface({ input: process.stdin, output: process.stdout });
52
+ return new Promise((resolve) => {
53
+ rl.question(`${c.cyan}?${c.reset} ${question} `, (answer) => {
54
+ rl.close();
55
+ resolve(answer.trim());
56
+ });
57
+ });
58
+ };
59
+ var confirm = async (question, defaultYes = true) => {
60
+ const hint = defaultYes ? "Y/n" : "y/N";
61
+ const answer = await ask(`${question} ${c.dim}(${hint})${c.reset}`);
62
+ if (!answer) return defaultYes;
63
+ return answer.toLowerCase().startsWith("y");
64
+ };
65
+ var validateRegistry = (data) => {
66
+ if (!data || typeof data !== "object") return false;
67
+ const reg = data;
68
+ return "components" in reg && typeof reg.components === "object" && reg.components !== null;
69
+ };
70
+ var getRegistry = async (isLocal) => {
71
+ if (isLocal && import_fs.default.existsSync(REGISTRY_LOCAL)) {
72
+ log("Using local registry...");
73
+ try {
74
+ const data = JSON.parse(import_fs.default.readFileSync(REGISTRY_LOCAL, "utf-8"));
75
+ if (!validateRegistry(data)) {
76
+ error('Invalid local registry format \u2014 missing "components" field.');
77
+ process.exit(1);
78
+ }
79
+ return data;
80
+ } catch (err) {
81
+ error(`Failed to parse local registry: ${err instanceof Error ? err.message : err}`);
82
+ process.exit(1);
83
+ }
84
+ }
85
+ log("Fetching registry from remote...");
86
+ try {
87
+ const response = await fetch(REGISTRY_REMOTE);
88
+ if (!response.ok) throw new Error(`HTTP ${response.status}`);
89
+ const data = await response.json();
90
+ if (!validateRegistry(data)) {
91
+ error('Invalid remote registry format \u2014 missing "components" field.');
92
+ process.exit(1);
93
+ }
94
+ return data;
95
+ } catch (err) {
96
+ const message = err instanceof Error ? err.message : String(err);
97
+ error(`Cannot fetch registry: ${message}`);
98
+ process.exit(1);
99
+ }
100
+ };
101
+ var installNpmPackages = (packages, cwd, dev = false) => {
102
+ if (packages.length === 0) return;
103
+ const pkgJsonPath = import_path.default.join(cwd, "package.json");
104
+ let toInstall = packages;
105
+ if (import_fs.default.existsSync(pkgJsonPath)) {
106
+ const pkg = JSON.parse(import_fs.default.readFileSync(pkgJsonPath, "utf-8"));
107
+ const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
108
+ toInstall = packages.filter((p) => !allDeps[p]);
109
+ }
110
+ if (toInstall.length === 0) return;
111
+ log(`Installing: ${c.bold}${toInstall.join(", ")}${c.reset}...`);
112
+ const flag = dev ? "--save-dev" : "--save";
113
+ try {
114
+ (0, import_child_process.execSync)(`npm install ${toInstall.join(" ")} ${flag}`, { stdio: "inherit", cwd });
115
+ } catch (err) {
116
+ error(`Failed to install packages: ${toInstall.join(", ")}. ${err instanceof Error ? err.message : ""}`);
117
+ }
118
+ };
119
+ var VITE_DEV_PACKAGES = [
120
+ "tailwindcss",
121
+ "@tailwindcss/vite",
122
+ "@vitejs/plugin-react",
123
+ "@types/node"
124
+ ];
125
+ var RUNTIME_PACKAGES = [
126
+ "@base-ui/react",
127
+ "tailwind-variants",
128
+ "clsx",
129
+ "tailwind-merge",
130
+ "tailwindcss-animate",
131
+ "lucide-react"
132
+ ];
133
+ var VITE_CONFIG_TEMPLATE = `import { defineConfig } from 'vite';
134
+ import tailwindcss from '@tailwindcss/vite';
135
+ import react from '@vitejs/plugin-react';
136
+ import path from 'path';
137
+
138
+ export default defineConfig({
139
+ plugins: [tailwindcss(), react()],
140
+ resolve: {
141
+ alias: {
142
+ '@': path.resolve(__dirname, './src'),
143
+ '@lib': path.resolve(__dirname, './src/lib'),
144
+ '@components': path.resolve(__dirname, './src/components'),
145
+ '@assets': path.resolve(__dirname, './src/assets'),
146
+ '@pages': path.resolve(__dirname, './src/pages'),
147
+ '@styles': path.resolve(__dirname, './src/styles'),
148
+ },
149
+ },
150
+ });
151
+ `;
152
+ var TSCONFIG_PATHS = {
153
+ "@/*": ["./src/*"],
154
+ "@lib/*": ["./src/lib/*"],
155
+ "@components/*": ["./src/components/*"],
156
+ "@assets/*": ["./src/assets/*"],
157
+ "@pages/*": ["./src/pages/*"],
158
+ "@styles/*": ["./src/styles/*"]
159
+ };
160
+ var setupViteConfig = (cwd) => {
161
+ installNpmPackages(VITE_DEV_PACKAGES, cwd, true);
162
+ const configTs = import_path.default.join(cwd, "vite.config.ts");
163
+ const configJs = import_path.default.join(cwd, "vite.config.js");
164
+ if (!import_fs.default.existsSync(configTs) && !import_fs.default.existsSync(configJs)) {
165
+ import_fs.default.writeFileSync(configTs, VITE_CONFIG_TEMPLATE);
166
+ ok("Created vite.config.ts.");
167
+ return;
168
+ }
169
+ const existingPath = import_fs.default.existsSync(configTs) ? configTs : configJs;
170
+ let content = import_fs.default.readFileSync(existingPath, "utf-8");
171
+ const missingImports = [];
172
+ if (!content.includes("@tailwindcss/vite")) missingImports.push("import tailwindcss from '@tailwindcss/vite';");
173
+ if (!content.includes("@vitejs/plugin-react")) missingImports.push("import react from '@vitejs/plugin-react';");
174
+ if (!content.includes("from 'path'") && !content.includes('from "path"')) missingImports.push("import path from 'path';");
175
+ const missingPlugins = [];
176
+ if (!content.includes("tailwindcss()")) missingPlugins.push("tailwindcss()");
177
+ if (!content.includes("react()") && !content.includes("react({")) missingPlugins.push("react()");
178
+ const hasAlias = content.includes("alias:") || content.includes("'@'") || content.includes('"@"');
179
+ if (missingImports.length === 0 && missingPlugins.length === 0 && hasAlias) {
180
+ ok("vite.config already configured \u2014 skipping.");
181
+ return;
182
+ }
183
+ if (missingImports.length > 0) {
184
+ const importBlock = missingImports.join("\n");
185
+ const allImports = [...content.matchAll(/^import\s.+$/gm)];
186
+ if (allImports.length > 0) {
187
+ const last = allImports[allImports.length - 1];
188
+ const pos = last.index + last[0].length;
189
+ content = content.slice(0, pos) + "\n" + importBlock + content.slice(pos);
190
+ } else {
191
+ content = importBlock + "\n" + content;
192
+ }
193
+ }
194
+ if (missingPlugins.length > 0) {
195
+ const match = content.match(/plugins:\s*\[/);
196
+ if (match && match.index !== void 0) {
197
+ const pos = match.index + match[0].length;
198
+ const after = content.slice(pos);
199
+ const pluginLines = missingPlugins.map((p) => `
200
+ ${p},`).join("");
201
+ const needsNewline = after.length > 0 && after[0] !== "\n" && after[0] !== "\r";
202
+ content = content.slice(0, pos) + pluginLines + (needsNewline ? "\n " : "") + after;
203
+ }
204
+ }
205
+ if (!hasAlias) {
206
+ const aliasBlock = [
207
+ " resolve: {",
208
+ " alias: {",
209
+ " '@': path.resolve(__dirname, './src'),",
210
+ " '@lib': path.resolve(__dirname, './src/lib'),",
211
+ " '@components': path.resolve(__dirname, './src/components'),",
212
+ " '@assets': path.resolve(__dirname, './src/assets'),",
213
+ " '@pages': path.resolve(__dirname, './src/pages'),",
214
+ " '@styles': path.resolve(__dirname, './src/styles'),",
215
+ " },",
216
+ " },"
217
+ ].join("\n");
218
+ const pluginsStart = content.search(/plugins:\s*\[/);
219
+ if (pluginsStart !== -1) {
220
+ let depth = 0;
221
+ let foundStart = false;
222
+ for (let i = pluginsStart; i < content.length; i++) {
223
+ if (content[i] === "[") {
224
+ depth++;
225
+ foundStart = true;
226
+ }
227
+ if (content[i] === "]") depth--;
228
+ if (foundStart && depth === 0) {
229
+ let lineEnd = content.indexOf("\n", i);
230
+ if (lineEnd === -1) lineEnd = content.length;
231
+ content = content.slice(0, lineEnd + 1) + aliasBlock + "\n" + content.slice(lineEnd + 1);
232
+ break;
233
+ }
234
+ }
235
+ }
236
+ }
237
+ import_fs.default.writeFileSync(existingPath, content);
238
+ ok(`Updated ${import_path.default.basename(existingPath)} with Tailwind + path aliases.`);
239
+ };
240
+ var setupTsConfig = (cwd) => {
241
+ const candidates = ["tsconfig.app.json", "tsconfig.json"];
242
+ for (const candidate of candidates) {
243
+ const configPath = import_path.default.join(cwd, candidate);
244
+ if (!import_fs.default.existsSync(configPath)) continue;
245
+ const raw = import_fs.default.readFileSync(configPath, "utf-8");
246
+ if (raw.includes('"@/*"') || raw.includes("'@/*'")) {
247
+ ok(`${candidate} already has path aliases \u2014 skipping.`);
248
+ return;
249
+ }
250
+ try {
251
+ const stripped = raw.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[\s,{[\]])\/\/[^\n]*/g, "$1");
252
+ const parsed = JSON.parse(stripped);
253
+ if (!parsed.compilerOptions) parsed.compilerOptions = {};
254
+ parsed.compilerOptions.baseUrl = ".";
255
+ parsed.compilerOptions.paths = TSCONFIG_PATHS;
256
+ import_fs.default.writeFileSync(configPath, JSON.stringify(parsed, null, 2));
257
+ ok(`Added path aliases to ${candidate}.`);
258
+ } catch (err) {
259
+ warn(`Could not auto-patch ${candidate}: ${err instanceof Error ? err.message : err}`);
260
+ warn("Add these to compilerOptions manually:");
261
+ console.log('\n "baseUrl": ".",');
262
+ console.log(' "paths": {');
263
+ for (const [alias, targets] of Object.entries(TSCONFIG_PATHS)) {
264
+ console.log(` "${alias}": ["${targets[0]}"],`);
265
+ }
266
+ console.log(" }");
267
+ console.log("");
268
+ }
269
+ return;
270
+ }
271
+ const newConfig = { compilerOptions: { baseUrl: ".", paths: TSCONFIG_PATHS } };
272
+ import_fs.default.writeFileSync(import_path.default.join(cwd, "tsconfig.json"), JSON.stringify(newConfig, null, 2));
273
+ ok("Created tsconfig.json with path aliases.");
274
+ };
275
+ var ensureCore = (registry, cwd, options = {}) => {
276
+ const core = registry.core;
277
+ if (!core) return;
278
+ installNpmPackages(core.dependencies, cwd);
279
+ for (const file of core.files) {
280
+ const targetPath = import_path.default.join(cwd, file.path);
281
+ const targetDir = import_path.default.dirname(targetPath);
282
+ if (!import_fs.default.existsSync(targetDir)) import_fs.default.mkdirSync(targetDir, { recursive: true });
283
+ if (import_fs.default.existsSync(targetPath) && !options.force) {
284
+ log(`Core file exists (skipping): ${c.dim}${file.path}${c.reset}`);
285
+ continue;
286
+ }
287
+ import_fs.default.writeFileSync(targetPath, file.content);
288
+ ok(`${import_fs.default.existsSync(targetPath) ? "Updated" : "Created"} core file: ${file.path}`);
289
+ }
290
+ };
291
+ var MAIN_PATCH_COMPONENTS = {
292
+ toast: {
293
+ import: "import { Toaster } from '@/components/ui/toast/Toaster';",
294
+ jsx: '<Toaster position="top-center" expand={true} richColors />'
295
+ }
296
+ };
297
+ var MAIN_CANDIDATES = ["src/main.tsx", "src/main.jsx", "src/index.tsx", "src/index.jsx"];
298
+ var findMainFile = (cwd) => {
299
+ for (const c2 of MAIN_CANDIDATES) {
300
+ const p = import_path.default.join(cwd, c2);
301
+ if (import_fs.default.existsSync(p)) return p;
302
+ }
303
+ return null;
304
+ };
305
+ var insertImport = (content, importLine) => {
306
+ if (content.includes(importLine)) return content;
307
+ const allImports = [...content.matchAll(/^import\s.+$/gm)];
308
+ if (allImports.length > 0) {
309
+ const last = allImports[allImports.length - 1];
310
+ const pos = last.index + last[0].length;
311
+ return content.slice(0, pos) + "\n" + importLine + content.slice(pos);
312
+ }
313
+ return importLine + "\n" + content;
314
+ };
315
+ var patchMainTsx = (cwd) => {
316
+ const mainPath = findMainFile(cwd);
317
+ if (!mainPath) {
318
+ warn("Could not find entry file (src/main.tsx). Skipping main entry setup.");
319
+ return;
320
+ }
321
+ let content = import_fs.default.readFileSync(mainPath, "utf-8");
322
+ let changed = false;
323
+ const cssImportLine = "import './styles/index.css';";
324
+ const hasCssImport = content.includes("styles/index.css") || content.includes("index.css");
325
+ if (!hasCssImport) {
326
+ const firstImport = content.match(/^import\s/m);
327
+ if (firstImport?.index !== void 0) {
328
+ content = content.slice(0, firstImport.index) + cssImportLine + "\n" + content.slice(firstImport.index);
329
+ } else {
330
+ content = cssImportLine + "\n" + content;
331
+ }
332
+ changed = true;
333
+ } else if (!content.includes("styles/index.css")) {
334
+ content = insertImport(content, cssImportLine);
335
+ changed = true;
336
+ }
337
+ if (!content.includes("ThemeProvider")) {
338
+ content = insertImport(content, "import { ThemeProvider } from '@/lib/theme/ThemeProvider';");
339
+ const wrapped = content.replace(/(<App\s*\/>)/g, "<ThemeProvider>\n $1\n </ThemeProvider>");
340
+ if (wrapped === content) {
341
+ warn("Could not locate <App /> in entry file \u2014 add <ThemeProvider> wrapper manually.");
342
+ } else {
343
+ content = wrapped;
344
+ }
345
+ changed = true;
346
+ }
347
+ if (changed) {
348
+ import_fs.default.writeFileSync(mainPath, content);
349
+ ok(`Patched ${import_path.default.relative(cwd, mainPath)}.`);
350
+ } else {
351
+ ok(`${import_path.default.relative(cwd, mainPath)} already configured \u2014 skipping.`);
352
+ }
353
+ };
354
+ var patchMainTsxComponent = (cwd, componentName) => {
355
+ const patch = MAIN_PATCH_COMPONENTS[componentName];
356
+ if (!patch) return;
357
+ const mainPath = findMainFile(cwd);
358
+ if (!mainPath) return;
359
+ let content = import_fs.default.readFileSync(mainPath, "utf-8");
360
+ const tagName = patch.jsx.match(/<(\w+)/)?.[1];
361
+ if (tagName && content.includes(`<${tagName}`)) return;
362
+ content = insertImport(content, patch.import);
363
+ const withProvider = content.replace(
364
+ /(<App\s*\/>)(\s*\n\s*<\/ThemeProvider>)/,
365
+ `$1
366
+ ${patch.jsx}$2`
367
+ );
368
+ if (withProvider !== content) {
369
+ import_fs.default.writeFileSync(mainPath, withProvider);
370
+ } else {
371
+ const fallback = content.replace(/(<App\s*\/>)/, `$1
372
+ ${patch.jsx}`);
373
+ if (fallback !== content) import_fs.default.writeFileSync(mainPath, fallback);
374
+ }
375
+ ok(`Added <${tagName}> to ${import_path.default.relative(cwd, mainPath)}.`);
376
+ };
377
+ var addComponent = (name, registry, cwd, options, added = /* @__PURE__ */ new Set()) => {
378
+ if (added.has(name)) return;
379
+ added.add(name);
380
+ const component = registry.components[name];
381
+ if (!component) {
382
+ error(`Component "${name}" not found. Run '${c.cyan}basuicn list${c.reset}' to see available components.`);
383
+ return;
384
+ }
385
+ log(`Adding: ${c.bold}${name}${c.reset}...`);
386
+ ensureCore(registry, cwd);
387
+ installNpmPackages(component.dependencies, cwd);
388
+ if (component.internalDependencies) {
389
+ for (const dep of component.internalDependencies) {
390
+ if (registry.components[dep]) {
391
+ addComponent(dep, registry, cwd, options, added);
392
+ }
393
+ }
394
+ }
395
+ for (const file of component.files) {
396
+ const targetPath = import_path.default.join(cwd, file.path);
397
+ const targetDir = import_path.default.dirname(targetPath);
398
+ if (!import_fs.default.existsSync(targetDir)) import_fs.default.mkdirSync(targetDir, { recursive: true });
399
+ if (import_fs.default.existsSync(targetPath) && !options.force) {
400
+ warn(`Skipped (exists): ${file.path} \u2014 use ${c.cyan}--force${c.reset} to overwrite`);
401
+ continue;
402
+ }
403
+ import_fs.default.writeFileSync(targetPath, file.content);
404
+ ok(`Created: ${file.path}`);
405
+ }
406
+ };
407
+ var removeComponent = (name, registry, cwd) => {
408
+ const component = registry.components[name];
409
+ if (!component) {
410
+ error(`Component "${name}" not found.`);
411
+ return;
412
+ }
413
+ log(`Removing: ${c.bold}${name}${c.reset}...`);
414
+ for (const file of component.files) {
415
+ const targetPath = import_path.default.join(cwd, file.path);
416
+ if (import_fs.default.existsSync(targetPath)) {
417
+ import_fs.default.unlinkSync(targetPath);
418
+ ok(`Deleted: ${file.path}`);
419
+ }
420
+ }
421
+ for (const file of component.files) {
422
+ const targetDir = import_path.default.dirname(import_path.default.join(cwd, file.path));
423
+ try {
424
+ if (import_fs.default.existsSync(targetDir) && import_fs.default.readdirSync(targetDir).length === 0) {
425
+ import_fs.default.rmdirSync(targetDir);
426
+ ok(`Removed empty dir: ${import_path.default.relative(cwd, targetDir)}`);
427
+ }
428
+ } catch (err) {
429
+ warn(`Could not remove directory: ${err instanceof Error ? err.message : err}`);
430
+ }
431
+ }
432
+ };
433
+ var HELP_MAIN = `
434
+ ${c.bold}${c.cyan}basuicn${c.reset} ${c.dim}v${VERSION}${c.reset} \u2014 Modern React UI Component CLI
435
+
436
+ ${c.bold}USAGE${c.reset}
437
+ ${c.cyan}npx basuicn${c.reset} ${c.green}<command>${c.reset} ${c.dim}[options]${c.reset}
438
+
439
+ ${c.bold}COMMANDS${c.reset}
440
+ ${c.green}init${c.reset} Initialize project: install deps, copy core files, patch entry
441
+ ${c.green}add${c.reset} ${c.dim}<name...>${c.reset} Add component(s) to your project
442
+ ${c.green}update${c.reset} ${c.dim}<name...>${c.reset} Update component(s) to latest registry version
443
+ ${c.green}diff${c.reset} ${c.dim}<name...>${c.reset} Show diff between local and registry version
444
+ ${c.green}remove${c.reset} ${c.dim}<name...>${c.reset} Remove component(s) from your project
445
+ ${c.green}list${c.reset} List all available components
446
+ ${c.green}doctor${c.reset} Check project health and configuration
447
+
448
+ ${c.bold}OPTIONS${c.reset}
449
+ ${c.cyan}--force${c.reset} Overwrite existing files when adding/updating
450
+ ${c.cyan}--local${c.reset} Use local registry.json instead of remote
451
+ ${c.cyan}--help, -h${c.reset} Show help (use with a command for detailed help)
452
+ ${c.cyan}--version, -v${c.reset} Show version
453
+
454
+ ${c.bold}QUICK START${c.reset}
455
+ ${c.dim}$${c.reset} npx basuicn init
456
+ ${c.dim}$${c.reset} npx basuicn add button input card
457
+ ${c.dim}$${c.reset} npx basuicn add toast
458
+
459
+ ${c.bold}EXAMPLES${c.reset}
460
+ ${c.dim}$${c.reset} npx basuicn add dialog --force ${c.dim}# Overwrite existing dialog${c.reset}
461
+ ${c.dim}$${c.reset} npx basuicn diff button ${c.dim}# See what changed since last update${c.reset}
462
+ ${c.dim}$${c.reset} npx basuicn doctor ${c.dim}# Diagnose missing deps/config${c.reset}
463
+
464
+ ${c.dim}Documentation: https://github.com/Basuicn/basuicn-core${c.reset}
465
+ `;
466
+ var HELP_COMMANDS = {
467
+ init: `
468
+ ${c.bold}basuicn init${c.reset}
469
+
470
+ Initialize your project for basuicn components.
471
+
472
+ ${c.bold}What it does:${c.reset}
473
+ 1. Installs runtime dependencies (@base-ui/react, tailwind-variants, etc.)
474
+ 2. Sets up vite.config.ts with Tailwind CSS + path aliases
475
+ 3. Patches tsconfig.json with path aliases (@/*, @lib/*, etc.)
476
+ 4. Copies core files (cn.ts, themes.ts, ThemeProvider.tsx, index.css)
477
+ 5. Wraps your <App /> with <ThemeProvider> in the main entry
478
+
479
+ ${c.bold}Usage:${c.reset}
480
+ ${c.dim}$${c.reset} npx basuicn init
481
+ ${c.dim}$${c.reset} npx basuicn init --local ${c.dim}# Use local registry${c.reset}
482
+ `,
483
+ add: `
484
+ ${c.bold}basuicn add${c.reset} ${c.dim}<name...>${c.reset}
485
+
486
+ Add one or more components to your project.
487
+
488
+ ${c.bold}Options:${c.reset}
489
+ ${c.cyan}--force${c.reset} Overwrite existing component files
490
+
491
+ ${c.bold}Features:${c.reset}
492
+ \u2022 Auto-runs init if project hasn't been set up
493
+ \u2022 Resolves internal dependencies (e.g., dialog depends on button)
494
+ \u2022 Installs required npm packages automatically
495
+ \u2022 Patches main entry for components that need it (e.g., toast)
496
+
497
+ ${c.bold}Usage:${c.reset}
498
+ ${c.dim}$${c.reset} npx basuicn add button
499
+ ${c.dim}$${c.reset} npx basuicn add button input card dialog
500
+ ${c.dim}$${c.reset} npx basuicn add toast --force
501
+
502
+ ${c.bold}Interactive:${c.reset}
503
+ ${c.dim}$${c.reset} npx basuicn add ${c.dim}# Prompts to select components${c.reset}
504
+ `,
505
+ update: `
506
+ ${c.bold}basuicn update${c.reset} ${c.dim}<name...>${c.reset}
507
+
508
+ Update component(s) to the latest registry version.
509
+ Equivalent to ${c.cyan}add --force${c.reset}.
510
+
511
+ ${c.bold}Usage:${c.reset}
512
+ ${c.dim}$${c.reset} npx basuicn update button
513
+ ${c.dim}$${c.reset} npx basuicn update button card dialog
514
+ `,
515
+ remove: `
516
+ ${c.bold}basuicn remove${c.reset} ${c.dim}<name...>${c.reset}
517
+
518
+ Remove component(s) from your project.
519
+ Deletes component files and cleans up empty directories.
520
+
521
+ ${c.bold}Usage:${c.reset}
522
+ ${c.dim}$${c.reset} npx basuicn remove button
523
+ ${c.dim}$${c.reset} npx basuicn remove dialog drawer sheet
524
+ `,
525
+ diff: `
526
+ ${c.bold}basuicn diff${c.reset} ${c.dim}<name...>${c.reset}
527
+
528
+ Show differences between your local component files and the registry version.
529
+ Useful to see what has changed before running update.
530
+
531
+ ${c.bold}Usage:${c.reset}
532
+ ${c.dim}$${c.reset} npx basuicn diff button
533
+ ${c.dim}$${c.reset} npx basuicn diff button card
534
+ `,
535
+ list: `
536
+ ${c.bold}basuicn list${c.reset}
537
+
538
+ Show all available components in the registry.
539
+ Displays internal dependencies for each component.
540
+
541
+ ${c.bold}Usage:${c.reset}
542
+ ${c.dim}$${c.reset} npx basuicn list
543
+ `,
544
+ doctor: `
545
+ ${c.bold}basuicn doctor${c.reset}
546
+
547
+ Run a health check on your project configuration.
548
+
549
+ ${c.bold}Checks:${c.reset}
550
+ \u2022 Core files exist (cn.ts, themes.ts, ThemeProvider.tsx, index.css)
551
+ \u2022 ThemeProvider + CSS import in main entry
552
+ \u2022 Runtime packages installed
553
+ \u2022 Dev packages installed
554
+ \u2022 Tailwind CSS configured
555
+ \u2022 TypeScript path aliases
556
+ \u2022 Vite config present
557
+
558
+ ${c.bold}Usage:${c.reset}
559
+ ${c.dim}$${c.reset} npx basuicn doctor
560
+ `
561
+ };
562
+ var main = async () => {
563
+ const args = process.argv.slice(2);
564
+ if (args.includes("--version") || args.includes("-v")) {
565
+ console.log(`basuicn v${VERSION}`);
566
+ return;
567
+ }
568
+ const isLocal = args.includes("--local");
569
+ const isForce = args.includes("--force");
570
+ const isHelp = args.includes("--help") || args.includes("-h");
571
+ const filteredArgs = args.filter((a) => !a.startsWith("--") && a !== "-h" && a !== "-v");
572
+ const command = filteredArgs[0];
573
+ const componentNames = filteredArgs.slice(1);
574
+ if (isHelp && command && HELP_COMMANDS[command]) {
575
+ console.log(HELP_COMMANDS[command]);
576
+ return;
577
+ }
578
+ if (isHelp || !command) {
579
+ console.log(HELP_MAIN);
580
+ return;
581
+ }
582
+ const cwd = getTargetProjectDir();
583
+ const registry = await getRegistry(isLocal);
584
+ switch (command) {
585
+ case "init": {
586
+ log("Initializing project...");
587
+ setupViteConfig(cwd);
588
+ setupTsConfig(cwd);
589
+ installNpmPackages(RUNTIME_PACKAGES, cwd);
590
+ ensureCore(registry, cwd, { force: true });
591
+ patchMainTsx(cwd);
592
+ console.log("");
593
+ ok(`${c.bold}Initialization complete!${c.reset} Run ${c.cyan}npx basuicn add <component>${c.reset} to get started.`);
594
+ break;
595
+ }
596
+ case "add": {
597
+ let names = componentNames;
598
+ if (names.length === 0) {
599
+ const all = Object.keys(registry.components).sort();
600
+ console.log(`
601
+ ${c.bold}Available components (${all.length}):${c.reset}`);
602
+ const categories = {};
603
+ for (const name of all) {
604
+ const prefix = name.includes("-") ? name.split("-")[0] : "general";
605
+ if (!categories[prefix]) categories[prefix] = [];
606
+ categories[prefix].push(name);
607
+ }
608
+ const cols = 4;
609
+ for (let i = 0; i < all.length; i += cols) {
610
+ const row = all.slice(i, i + cols).map((n) => n.padEnd(20)).join("");
611
+ console.log(` ${c.dim}${row}${c.reset}`);
612
+ }
613
+ console.log("");
614
+ const answer = await ask(`Which components to add? ${c.dim}(space-separated, or "all")${c.reset}`);
615
+ if (!answer) {
616
+ log("No components selected.");
617
+ return;
618
+ }
619
+ names = answer === "all" ? all : answer.split(/[\s,]+/).filter(Boolean);
620
+ }
621
+ const cnPath = import_path.default.join(cwd, "src/lib/utils/cn.ts");
622
+ if (!import_fs.default.existsSync(cnPath)) {
623
+ log("Project not initialized \u2014 running init first...");
624
+ setupViteConfig(cwd);
625
+ setupTsConfig(cwd);
626
+ installNpmPackages(RUNTIME_PACKAGES, cwd);
627
+ ensureCore(registry, cwd, { force: true });
628
+ patchMainTsx(cwd);
629
+ console.log("");
630
+ }
631
+ for (const name of names) {
632
+ addComponent(name, registry, cwd, { force: isForce });
633
+ patchMainTsxComponent(cwd, name);
634
+ }
635
+ console.log("");
636
+ ok(`${c.bold}Done!${c.reset} Added ${names.length} component(s).`);
637
+ break;
638
+ }
639
+ case "update": {
640
+ if (componentNames.length === 0) {
641
+ error(`Usage: ${c.cyan}npx basuicn update <component-name> [...]${c.reset}`);
642
+ console.log(` Run ${c.cyan}npx basuicn update --help${c.reset} for details.`);
643
+ return;
644
+ }
645
+ for (const name of componentNames) {
646
+ log(`Updating: ${c.bold}${name}${c.reset}...`);
647
+ addComponent(name, registry, cwd, { force: true });
648
+ }
649
+ console.log("");
650
+ ok(`${c.bold}Update complete.${c.reset}`);
651
+ break;
652
+ }
653
+ case "remove": {
654
+ if (componentNames.length === 0) {
655
+ error(`Usage: ${c.cyan}npx basuicn remove <component-name>${c.reset}`);
656
+ return;
657
+ }
658
+ if (!isForce) {
659
+ const yes = await confirm(`Remove ${componentNames.join(", ")}?`);
660
+ if (!yes) {
661
+ log("Cancelled.");
662
+ return;
663
+ }
664
+ }
665
+ for (const name of componentNames) {
666
+ removeComponent(name, registry, cwd);
667
+ }
668
+ console.log("");
669
+ ok(`${c.bold}Done!${c.reset}`);
670
+ break;
671
+ }
672
+ case "list": {
673
+ const components = Object.keys(registry.components).sort();
674
+ console.log(`
675
+ ${c.bold}Available components (${components.length}):${c.reset}
676
+ `);
677
+ const installed = [];
678
+ const available = [];
679
+ for (const k of components) {
680
+ const comp = registry.components[k];
681
+ const firstFile = comp.files[0];
682
+ const isInstalled = firstFile && import_fs.default.existsSync(import_path.default.join(cwd, firstFile.path));
683
+ if (isInstalled) installed.push(k);
684
+ else available.push(k);
685
+ }
686
+ if (installed.length > 0) {
687
+ console.log(` ${c.green}Installed (${installed.length}):${c.reset}`);
688
+ for (const k of installed) {
689
+ const deps = registry.components[k].internalDependencies?.filter(Boolean);
690
+ const depStr = deps?.length ? ` ${c.dim}\u2192 ${deps.join(", ")}${c.reset}` : "";
691
+ console.log(` ${c.green}\u25CF${c.reset} ${k}${depStr}`);
692
+ }
693
+ console.log("");
694
+ }
695
+ if (available.length > 0) {
696
+ console.log(` ${c.dim}Available (${available.length}):${c.reset}`);
697
+ for (const k of available) {
698
+ const deps = registry.components[k].internalDependencies?.filter(Boolean);
699
+ const depStr = deps?.length ? ` ${c.dim}\u2192 ${deps.join(", ")}${c.reset}` : "";
700
+ console.log(` ${c.dim}\u25CB${c.reset} ${k}${depStr}`);
701
+ }
702
+ }
703
+ console.log("");
704
+ break;
705
+ }
706
+ case "diff": {
707
+ if (componentNames.length === 0) {
708
+ error(`Usage: ${c.cyan}npx basuicn diff <component-name>${c.reset}`);
709
+ return;
710
+ }
711
+ for (const name of componentNames) {
712
+ const component = registry.components[name];
713
+ if (!component) {
714
+ error(`Component "${name}" not found.`);
715
+ continue;
716
+ }
717
+ let hasDiff = false;
718
+ console.log(`
719
+ ${c.bold}[diff] ${name}${c.reset}`);
720
+ for (const file of component.files) {
721
+ const targetPath = import_path.default.join(cwd, file.path);
722
+ if (!import_fs.default.existsSync(targetPath)) {
723
+ console.log(` ${c.green}+ [new file]${c.reset} ${file.path}`);
724
+ hasDiff = true;
725
+ continue;
726
+ }
727
+ const localContent = import_fs.default.readFileSync(targetPath, "utf-8");
728
+ if (localContent === file.content) continue;
729
+ hasDiff = true;
730
+ console.log(`
731
+ ${c.yellow}~${c.reset} ${file.path}`);
732
+ const localLines = localContent.split("\n");
733
+ const remoteLines = file.content.split("\n");
734
+ const maxLen = Math.max(localLines.length, remoteLines.length);
735
+ let shownLines = 0;
736
+ for (let i = 0; i < maxLen; i++) {
737
+ if (localLines[i] !== remoteLines[i]) {
738
+ if (localLines[i] !== void 0) console.log(` ${c.red}- ${localLines[i]}${c.reset}`);
739
+ if (remoteLines[i] !== void 0) console.log(` ${c.green}+ ${remoteLines[i]}${c.reset}`);
740
+ shownLines++;
741
+ if (shownLines >= 20) {
742
+ const remaining = maxLen - i - 1;
743
+ if (remaining > 0) console.log(` ${c.dim}... and ${remaining} more lines${c.reset}`);
744
+ break;
745
+ }
746
+ }
747
+ }
748
+ }
749
+ if (!hasDiff) ok(`${name}: already up to date.`);
750
+ }
751
+ break;
752
+ }
753
+ case "doctor": {
754
+ console.log(`
755
+ ${c.bold}Project Health Check${c.reset}
756
+ `);
757
+ let issues = 0;
758
+ const check = (passed, msg, fix) => {
759
+ console.log(` ${passed ? `${c.green}\u2714${c.reset}` : `${c.red}\u2716${c.reset}`} ${msg}`);
760
+ if (!passed) {
761
+ if (fix) console.log(` ${c.dim}\u2192 ${fix}${c.reset}`);
762
+ issues++;
763
+ }
764
+ };
765
+ check(
766
+ import_fs.default.existsSync(import_path.default.join(cwd, "src/lib/utils/cn.ts")),
767
+ "src/lib/utils/cn.ts",
768
+ "run: npx basuicn init"
769
+ );
770
+ check(
771
+ import_fs.default.existsSync(import_path.default.join(cwd, "src/lib/theme/themes.ts")),
772
+ "src/lib/theme/themes.ts",
773
+ "run: npx basuicn init"
774
+ );
775
+ check(
776
+ import_fs.default.existsSync(import_path.default.join(cwd, "src/lib/theme/ThemeProvider.tsx")),
777
+ "src/lib/theme/ThemeProvider.tsx",
778
+ "run: npx basuicn init"
779
+ );
780
+ check(
781
+ import_fs.default.existsSync(import_path.default.join(cwd, "src/styles/index.css")),
782
+ "src/styles/index.css (theme variables)",
783
+ "run: npx basuicn init"
784
+ );
785
+ const mainPath = findMainFile(cwd);
786
+ if (mainPath) {
787
+ const mainContent = import_fs.default.readFileSync(mainPath, "utf-8");
788
+ check(
789
+ mainContent.includes("ThemeProvider"),
790
+ "ThemeProvider in main entry",
791
+ "run: npx basuicn init"
792
+ );
793
+ check(
794
+ mainContent.includes("styles/index.css") || mainContent.includes("index.css"),
795
+ "CSS import in main entry",
796
+ "run: npx basuicn init"
797
+ );
798
+ } else {
799
+ check(false, "main entry file (src/main.tsx)", "create src/main.tsx");
800
+ }
801
+ const pkgPath = import_path.default.join(cwd, "package.json");
802
+ if (import_fs.default.existsSync(pkgPath)) {
803
+ const pkg = JSON.parse(import_fs.default.readFileSync(pkgPath, "utf-8"));
804
+ const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
805
+ for (const dep of RUNTIME_PACKAGES) {
806
+ check(!!allDeps[dep], `package: ${dep}`, `run: npm install ${dep}`);
807
+ }
808
+ for (const dep of VITE_DEV_PACKAGES) {
809
+ check(!!allDeps[dep], `package (dev): ${dep}`, `run: npm install -D ${dep}`);
810
+ }
811
+ } else {
812
+ check(false, "package.json found", "run: npm init -y");
813
+ }
814
+ const hasTailwindInCss = (() => {
815
+ const candidates = ["src/styles/index.css", "src/index.css", "src/App.css"];
816
+ return candidates.some((f) => {
817
+ const p = import_path.default.join(cwd, f);
818
+ if (!import_fs.default.existsSync(p)) return false;
819
+ const content = import_fs.default.readFileSync(p, "utf-8");
820
+ return content.includes('@import "tailwindcss"') || content.includes("@import 'tailwindcss'");
821
+ });
822
+ })();
823
+ check(hasTailwindInCss, '@import "tailwindcss" in CSS', "run: npx basuicn init");
824
+ const tsCandidates = ["tsconfig.app.json", "tsconfig.json"];
825
+ const hasAlias = tsCandidates.some((f) => {
826
+ const p = import_path.default.join(cwd, f);
827
+ if (!import_fs.default.existsSync(p)) return false;
828
+ const content = import_fs.default.readFileSync(p, "utf-8");
829
+ return content.includes('"@/*"') || content.includes("'@/*'");
830
+ });
831
+ check(hasAlias, "TypeScript path aliases (@/*)", "run: npx basuicn init");
832
+ const hasViteConfig = import_fs.default.existsSync(import_path.default.join(cwd, "vite.config.ts")) || import_fs.default.existsSync(import_path.default.join(cwd, "vite.config.js"));
833
+ check(hasViteConfig, "vite.config.ts / vite.config.js", "run: npx basuicn init");
834
+ console.log("");
835
+ if (issues === 0) {
836
+ ok(`${c.bold}All checks passed!${c.reset} Project is healthy.`);
837
+ } else {
838
+ warn(`${c.bold}${issues} issue(s) found.${c.reset} Run ${c.cyan}npx basuicn init${c.reset} to fix most issues.`);
839
+ }
840
+ break;
841
+ }
842
+ default: {
843
+ error(`Unknown command: "${command}"`);
844
+ console.log(` Run ${c.cyan}npx basuicn --help${c.reset} to see available commands.
845
+ `);
846
+ }
847
+ }
848
+ };
849
+ main();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "basuicn",
3
3
  "private": false,
4
- "version": "0.1.6",
4
+ "version": "0.1.8",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "basuicn": "./dist/ui-cli.cjs"
@@ -15,7 +15,7 @@
15
15
  "scripts": {
16
16
  "dev": "vite",
17
17
  "build": "tsc -b && vite build",
18
- "build:cli": "npx -y esbuild scripts/ui-cli.ts --bundle --platform=node --outfile=dist/ui-cli.cjs --format=cjs --packages=external",
18
+ "build:cli": "node scripts/build-cli.mjs",
19
19
  "lint": "eslint .",
20
20
  "preview": "vite preview",
21
21
  "test": "vitest",
@@ -0,0 +1,12 @@
1
+ import { build } from 'esbuild';
2
+
3
+ await build({
4
+ entryPoints: ['scripts/ui-cli.ts'],
5
+ bundle: true,
6
+ platform: 'node',
7
+ outfile: 'dist/ui-cli.cjs',
8
+ format: 'cjs',
9
+ packages: 'external',
10
+ });
11
+
12
+ console.log('✔ CLI built → dist/ui-cli.cjs');
package/scripts/ui-cli.ts CHANGED
@@ -6,7 +6,7 @@ import readline from 'readline';
6
6
 
7
7
  // ─── Constants ────────────────────────────────────────────────────────────────
8
8
 
9
- const VERSION = '0.1.6';
9
+ const VERSION = '0.1.8';
10
10
  const REGISTRY_LOCAL = './registry.json';
11
11
  const REGISTRY_REMOTE = 'https://raw.githubusercontent.com/Basuicn/basuicn-core/main/registry.json';
12
12