solidui-cli 0.6.8 → 0.7.1

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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/dist/index.js +910 -475
  3. package/package.json +20 -20
package/dist/index.js CHANGED
@@ -1,15 +1,15 @@
1
1
  #! /usr/bin/env node
2
2
 
3
3
  // src/index.ts
4
- import { Command } from "commander";
4
+ import { Command as Command3 } from "commander";
5
5
 
6
6
  // src/commands/add.ts
7
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
8
- import path from "path";
9
- import { cwd } from "process";
10
- import { log as log2, spinner as spinner2 } from "@clack/prompts";
11
- import chalk from "chalk";
12
- import prompts from "prompts";
7
+ import { existsSync as existsSync2 } from "node:fs";
8
+ import { mkdir, writeFile } from "node:fs/promises";
9
+ import path3 from "node:path";
10
+ import * as p2 from "@clack/prompts";
11
+ import { Command } from "commander";
12
+ import { execa } from "execa";
13
13
 
14
14
  // ../../node_modules/.pnpm/valibot@0.36.0/node_modules/valibot/dist/index.js
15
15
  var store;
@@ -96,6 +96,68 @@ var ValiError = class extends Error {
96
96
  this.issues = issues;
97
97
  }
98
98
  };
99
+ function getDefault(schema, dataset, config2) {
100
+ return typeof schema.default === "function" ? (
101
+ // @ts-expect-error
102
+ schema.default(dataset, config2)
103
+ ) : (
104
+ // @ts-expect-error
105
+ schema.default
106
+ );
107
+ }
108
+ function array(item, message) {
109
+ return {
110
+ kind: "schema",
111
+ type: "array",
112
+ reference: array,
113
+ expects: "Array",
114
+ async: false,
115
+ item,
116
+ message,
117
+ _run(dataset, config2) {
118
+ const input = dataset.value;
119
+ if (Array.isArray(input)) {
120
+ dataset.typed = true;
121
+ dataset.value = [];
122
+ for (let key = 0; key < input.length; key++) {
123
+ const value2 = input[key];
124
+ const itemDataset = this.item._run({ typed: false, value: value2 }, config2);
125
+ if (itemDataset.issues) {
126
+ const pathItem = {
127
+ type: "array",
128
+ origin: "value",
129
+ input,
130
+ key,
131
+ value: value2
132
+ };
133
+ for (const issue of itemDataset.issues) {
134
+ if (issue.path) {
135
+ issue.path.unshift(pathItem);
136
+ } else {
137
+ issue.path = [pathItem];
138
+ }
139
+ dataset.issues?.push(issue);
140
+ }
141
+ if (!dataset.issues) {
142
+ dataset.issues = itemDataset.issues;
143
+ }
144
+ if (config2.abortEarly) {
145
+ dataset.typed = false;
146
+ break;
147
+ }
148
+ }
149
+ if (!itemDataset.typed) {
150
+ dataset.typed = false;
151
+ }
152
+ dataset.value.push(itemDataset.value);
153
+ }
154
+ } else {
155
+ _addIssue(this, "type", dataset, config2);
156
+ }
157
+ return dataset;
158
+ }
159
+ };
160
+ }
99
161
  function boolean(message) {
100
162
  return {
101
163
  kind: "schema",
@@ -172,6 +234,55 @@ function object(entries, message) {
172
234
  }
173
235
  };
174
236
  }
237
+ function optional(wrapped, ...args) {
238
+ const schema = {
239
+ kind: "schema",
240
+ type: "optional",
241
+ reference: optional,
242
+ expects: `${wrapped.expects} | undefined`,
243
+ async: false,
244
+ wrapped,
245
+ _run(dataset, config2) {
246
+ if (dataset.value === void 0) {
247
+ if ("default" in this) {
248
+ dataset.value = getDefault(
249
+ this,
250
+ dataset,
251
+ config2
252
+ );
253
+ }
254
+ if (dataset.value === void 0) {
255
+ dataset.typed = true;
256
+ return dataset;
257
+ }
258
+ }
259
+ return this.wrapped._run(dataset, config2);
260
+ }
261
+ };
262
+ if (0 in args) {
263
+ schema.default = args[0];
264
+ }
265
+ return schema;
266
+ }
267
+ function picklist(options, message) {
268
+ return {
269
+ kind: "schema",
270
+ type: "picklist",
271
+ reference: picklist,
272
+ expects: options.map(_stringify).join(" | ") || "never",
273
+ async: false,
274
+ options,
275
+ message,
276
+ _run(dataset, config2) {
277
+ if (this.options.includes(dataset.value)) {
278
+ dataset.typed = true;
279
+ } else {
280
+ _addIssue(this, "type", dataset, config2);
281
+ }
282
+ return dataset;
283
+ }
284
+ };
285
+ }
175
286
  function string(message) {
176
287
  return {
177
288
  kind: "schema",
@@ -201,244 +312,211 @@ function parse(schema, input, config2) {
201
312
  return dataset.value;
202
313
  }
203
314
 
204
- // src/lib/constants.ts
205
- var PROJECT_DEPS = [
206
- "tailwindcss",
207
- "tailwindcss-animate",
208
- "tailwind-merge",
209
- "class-variance-authority",
210
- "clsx",
211
- "@kobalte/core"
212
- ];
213
- var registryUIUrl = "https://www.solid-ui.com/registry/ui";
214
- var registryIndexUrl = "https://www.solid-ui.com/registry/index.json";
215
- var UTILS = `import type { ClassValue } from "clsx"
216
- import { clsx } from "clsx"
217
- import { twMerge } from "tailwind-merge"
218
-
219
- export function cn(...inputs: ClassValue[]) {
220
- return twMerge(clsx(inputs))
221
- }`;
222
- var ROOT_CSS = `@tailwind base;
223
- @tailwind components;
224
- @tailwind utilities;
225
-
226
- @layer base {
227
- :root {
228
- --background: 0 0% 100%;
229
- --foreground: 240 10% 3.9%;
230
-
231
- --muted: 240 4.8% 95.9%;
232
- --muted-foreground: 240 3.8% 46.1%;
233
-
234
- --popover: 0 0% 100%;
235
- --popover-foreground: 240 10% 3.9%;
236
-
237
- --border: 240 5.9% 90%;
238
- --input: 240 5.9% 90%;
239
-
240
- --card: 0 0% 100%;
241
- --card-foreground: 240 10% 3.9%;
242
-
243
- --primary: 240 5.9% 10%;
244
- --primary-foreground: 0 0% 98%;
245
-
246
- --secondary: 240 4.8% 95.9%;
247
- --secondary-foreground: 240 5.9% 10%;
248
-
249
- --accent: 240 4.8% 95.9%;
250
- --accent-foreground: 240 5.9% 10%;
251
-
252
- --destructive: 0 84.2% 60.2%;
253
- --destructive-foreground: 0 0% 98%;
254
-
255
- --info: 204 94% 94%;
256
- --info-foreground: 199 89% 48%;
257
-
258
- --success: 149 80% 90%;
259
- --success-foreground: 160 84% 39%;
260
-
261
- --warning: 48 96% 89%;
262
- --warning-foreground: 25 95% 53%;
263
-
264
- --error: 0 93% 94%;
265
- --error-foreground: 0 84% 60%;
315
+ // src/utils/config.ts
316
+ import { existsSync, readFileSync } from "node:fs";
317
+ import path from "node:path";
318
+ import { loadConfig } from "tsconfig-paths";
266
319
 
267
- --ring: 240 5.9% 10%;
320
+ // src/utils/resolve-import.ts
321
+ import { createMatchPath } from "tsconfig-paths";
322
+ async function resolveImport(importPath, config) {
323
+ return createMatchPath(config.absoluteBaseUrl, config.paths)(importPath, void 0, () => true, [
324
+ ".ts",
325
+ ".tsx"
326
+ ]);
327
+ }
268
328
 
269
- --radius: 0.5rem;
329
+ // src/utils/config.ts
330
+ var DEFAULT_COMPONENTS = "~/components/ui";
331
+ var DEFAULT_UTILS = "~/lib/utils";
332
+ var DEFAULT_CSS_FILE = "src/app.css";
333
+ var DEFAULT_TAILWIND_CONFIG = "tailwind.config.cjs";
334
+ var DEFAULT_TAILWIND_PREFIX = "";
335
+ var RawConfigSchema = object({
336
+ $schema: optional(string()),
337
+ tsx: boolean(),
338
+ tailwind: object({
339
+ css: string(),
340
+ config: string(),
341
+ prefix: optional(string(), "")
342
+ }),
343
+ aliases: object({
344
+ components: string(),
345
+ utils: string()
346
+ })
347
+ });
348
+ var ConfigSchema = object({
349
+ ...RawConfigSchema.entries,
350
+ resolvedPaths: object({
351
+ tailwindConfig: string(),
352
+ tailwindCss: string(),
353
+ utils: string(),
354
+ components: string()
355
+ })
356
+ });
357
+ async function resolveConfigPaths(cwd, config) {
358
+ const tsConfig = await loadConfig(cwd);
359
+ if (tsConfig.resultType === "failed") {
360
+ throw new Error(
361
+ `Failed to load ${config.tsx ? "tsconfig" : "jsconfig"}.json. ${tsConfig.message ?? ""}`.trim()
362
+ );
270
363
  }
364
+ return parse(ConfigSchema, {
365
+ ...config,
366
+ resolvedPaths: {
367
+ tailwindConfig: path.resolve(cwd, config.tailwind.config),
368
+ tailwindCss: path.resolve(cwd, config.tailwind.css),
369
+ utils: await resolveImport(config.aliases.utils, tsConfig),
370
+ components: await resolveImport(config.aliases.components, tsConfig)
371
+ }
372
+ });
373
+ }
374
+ function getRawConfig(cwd) {
375
+ try {
376
+ const configPath = path.resolve(cwd, "ui.config.json");
377
+ if (!existsSync(configPath)) {
378
+ return null;
379
+ }
380
+ const config = JSON.parse(readFileSync(configPath).toString());
381
+ return parse(RawConfigSchema, config);
382
+ } catch (error) {
383
+ throw new Error(`Invalid configuration found in ${cwd}/ui.config.json.`);
384
+ }
385
+ }
386
+ async function getConfig(cwd) {
387
+ const config = getRawConfig(cwd);
388
+ if (!config) {
389
+ return null;
390
+ }
391
+ return await resolveConfigPaths(cwd, config);
392
+ }
271
393
 
272
- .dark,
273
- [data-kb-theme="dark"] {
274
- --background: 240 10% 3.9%;
275
- --foreground: 0 0% 98%;
276
-
277
- --muted: 240 3.7% 15.9%;
278
- --muted-foreground: 240 5% 64.9%;
279
-
280
- --accent: 240 3.7% 15.9%;
281
- --accent-foreground: 0 0% 98%;
282
-
283
- --popover: 240 10% 3.9%;
284
- --popover-foreground: 0 0% 98%;
285
-
286
- --border: 240 3.7% 15.9%;
287
- --input: 240 3.7% 15.9%;
288
-
289
- --card: 240 10% 3.9%;
290
- --card-foreground: 0 0% 98%;
291
-
292
- --primary: 0 0% 98%;
293
- --primary-foreground: 240 5.9% 10%;
294
-
295
- --secondary: 240 3.7% 15.9%;
296
- --secondary-foreground: 0 0% 98%;
297
-
298
- --destructive: 0 62.8% 30.6%;
299
- --destructive-foreground: 0 0% 98%;
300
-
301
- --info: 204 94% 94%;
302
- --info-foreground: 199 89% 48%;
303
-
304
- --success: 149 80% 90%;
305
- --success-foreground: 160 84% 39%;
306
-
307
- --warning: 48 96% 89%;
308
- --warning-foreground: 25 95% 53%;
309
-
310
- --error: 0 93% 94%;
311
- --error-foreground: 0 84% 60%;
312
-
313
- --ring: 240 4.9% 83.9%;
394
+ // src/utils/get-package-manager.ts
395
+ import { detect } from "@antfu/ni";
396
+ async function getPackageManager(targetDir) {
397
+ const packageManager = await detect({ programmatic: true, cwd: targetDir });
398
+ if (packageManager === "yarn@berry") return "yarn";
399
+ if (packageManager === "pnpm@6") return "pnpm";
400
+ if (packageManager === "bun") return "bun";
401
+ return packageManager ?? "npm";
402
+ }
314
403
 
315
- --radius: 0.5rem;
404
+ // src/utils/logger.ts
405
+ import * as p from "@clack/prompts";
406
+ import chalk from "chalk";
407
+ var headline = (text2) => chalk.bgGreen.bold.black(text2);
408
+ var highlight = (text2) => chalk.bold.green(text2);
409
+ var subtle = (text2) => chalk.grey(text2);
410
+ function handleError(error) {
411
+ p.log.message();
412
+ if (typeof error === "string") {
413
+ p.cancel(error);
414
+ process.exit(1);
415
+ }
416
+ if (error instanceof Error) {
417
+ p.cancel(error.stack);
418
+ process.exit(1);
316
419
  }
420
+ p.cancel("Something went wrong. Please try again.");
421
+ process.exit(1);
317
422
  }
318
423
 
319
- @layer base {
320
- * {
321
- @apply border-border;
424
+ // src/utils/registry.ts
425
+ var BASE_URL = "https://www.solid-ui.com";
426
+ var RegistryIndexSchema = array(
427
+ object({
428
+ name: string(),
429
+ dependencies: optional(array(string())),
430
+ registryDependencies: optional(array(string())),
431
+ files: array(string()),
432
+ type: picklist(["ui", "example"])
433
+ })
434
+ );
435
+ var RegistryItemSchema = object({
436
+ name: string(),
437
+ dependencies: optional(array(string())),
438
+ files: array(
439
+ object({
440
+ name: string(),
441
+ content: string()
442
+ })
443
+ ),
444
+ type: picklist(["ui", "example"])
445
+ });
446
+ async function fetchRegistry(paths) {
447
+ try {
448
+ const results = await Promise.all(
449
+ paths.map(async (path5) => {
450
+ const response = await fetch(`${BASE_URL}/registry/${path5}`);
451
+ return await response.json();
452
+ })
453
+ );
454
+ return results;
455
+ } catch (e) {
456
+ console.log(e);
457
+ throw new Error(`Failed to fetch registry from ${BASE_URL}.`);
322
458
  }
323
- body {
324
- @apply bg-background text-foreground;
325
- font-feature-settings:
326
- "rlig" 1,
327
- "calt" 1;
459
+ }
460
+ async function getRegistryIndex() {
461
+ try {
462
+ const [result] = await fetchRegistry(["index.json"]);
463
+ return parse(RegistryIndexSchema, result).filter((item) => item.type === "ui");
464
+ } catch (e) {
465
+ throw new Error(`Failed to fetch components from registry.`);
466
+ }
467
+ }
468
+ async function resolveTree(index, names) {
469
+ const tree = [];
470
+ for (const name of names) {
471
+ const entry = index.find((entry2) => entry2.name === name);
472
+ if (!entry) {
473
+ continue;
474
+ }
475
+ tree.push(entry);
476
+ if (entry.registryDependencies) {
477
+ const dependencies = await resolveTree(index, entry.registryDependencies);
478
+ tree.push(...dependencies);
479
+ }
480
+ }
481
+ return tree.filter(
482
+ (component, idx, self) => self.findIndex((c) => c.name === component.name) === idx
483
+ );
484
+ }
485
+ async function fetchTree(tree) {
486
+ try {
487
+ const paths = tree.map((item) => `ui/${item.name}.json`);
488
+ const results = await fetchRegistry(paths);
489
+ return parse(array(RegistryItemSchema), results);
490
+ } catch (e) {
491
+ throw new Error(`Failed to fetch components from registry.`);
328
492
  }
329
493
  }
330
494
 
331
- @media (max-width: 640px) {
332
- .container {
333
- @apply px-4;
495
+ // src/utils/transformers/index.ts
496
+ import { mkdtemp } from "node:fs/promises";
497
+ import { tmpdir } from "node:os";
498
+ import path2 from "node:path";
499
+ import { Project, ScriptKind } from "ts-morph";
500
+
501
+ // src/utils/transformers/transform-import.ts
502
+ var transformImport = async ({ sourceFile, config }) => {
503
+ const importDeclarations = sourceFile.getImportDeclarations();
504
+ for (const importDeclaration of importDeclarations) {
505
+ const moduleSpecifier = importDeclaration.getModuleSpecifierValue();
506
+ if (moduleSpecifier.startsWith("~/registry/")) {
507
+ importDeclaration.setModuleSpecifier(
508
+ moduleSpecifier.replace(/^~\/registry\/ui/, config.aliases.components)
509
+ );
510
+ } else if (moduleSpecifier === "~/lib/utils") {
511
+ importDeclaration.setModuleSpecifier(
512
+ moduleSpecifier.replace(/^~\/lib\/utils/, config.aliases.utils)
513
+ );
514
+ }
334
515
  }
335
- }`;
336
- var TAILWIND_CONFIG = `/**@type {import("tailwindcss").Config} */
337
- module.exports = {
338
- darkMode: ["class", '[data-kb-theme="dark"]'],
339
- content: ["./src/**/*.{ts,tsx}"],
340
- theme: {
341
- container: {
342
- center: true,
343
- padding: "2rem",
344
- screens: {
345
- "2xl": "1400px"
346
- }
347
- },
348
- extend: {
349
- colors: {
350
- border: "hsl(var(--border))",
351
- input: "hsl(var(--input))",
352
- ring: "hsl(var(--ring))",
353
- background: "hsl(var(--background))",
354
- foreground: "hsl(var(--foreground))",
355
- primary: {
356
- DEFAULT: "hsl(var(--primary))",
357
- foreground: "hsl(var(--primary-foreground))"
358
- },
359
- secondary: {
360
- DEFAULT: "hsl(var(--secondary))",
361
- foreground: "hsl(var(--secondary-foreground))"
362
- },
363
- destructive: {
364
- DEFAULT: "hsl(var(--destructive))",
365
- foreground: "hsl(var(--destructive-foreground))"
366
- },
367
- info: {
368
- DEFAULT: "hsl(var(--info))",
369
- foreground: "hsl(var(--info-foreground))"
370
- },
371
- success: {
372
- DEFAULT: "hsl(var(--success))",
373
- foreground: "hsl(var(--success-foreground))"
374
- },
375
- warning: {
376
- DEFAULT: "hsl(var(--warning))",
377
- foreground: "hsl(var(--warning-foreground))"
378
- },
379
- error: {
380
- DEFAULT: "hsl(var(--error))",
381
- foreground: "hsl(var(--error-foreground))"
382
- },
383
- muted: {
384
- DEFAULT: "hsl(var(--muted))",
385
- foreground: "hsl(var(--muted-foreground))"
386
- },
387
- accent: {
388
- DEFAULT: "hsl(var(--accent))",
389
- foreground: "hsl(var(--accent-foreground))"
390
- },
391
- popover: {
392
- DEFAULT: "hsl(var(--popover))",
393
- foreground: "hsl(var(--popover-foreground))"
394
- },
395
- card: {
396
- DEFAULT: "hsl(var(--card))",
397
- foreground: "hsl(var(--card-foreground))"
398
- }
399
- },
400
- borderRadius: {
401
- xl: "calc(var(--radius) + 4px)",
402
- lg: "var(--radius)",
403
- md: "calc(var(--radius) - 2px)",
404
- sm: "calc(var(--radius) - 4px)"
405
- },
406
- keyframes: {
407
- "accordion-down": {
408
- from: { height: 0 },
409
- to: { height: "var(--kb-accordion-content-height)" }
410
- },
411
- "accordion-up": {
412
- from: { height: "var(--kb-accordion-content-height)" },
413
- to: { height: 0 }
414
- },
415
- "content-show": {
416
- from: { opacity: 0, transform: "scale(0.96)" },
417
- to: { opacity: 1, transform: "scale(1)" }
418
- },
419
- "content-hide": {
420
- from: { opacity: 1, transform: "scale(1)" },
421
- to: { opacity: 0, transform: "scale(0.96)" }
422
- }
423
- },
424
- animation: {
425
- "accordion-down": "accordion-down 0.2s ease-out",
426
- "accordion-up": "accordion-up 0.2s ease-out",
427
- "content-show": "content-show 0.2s ease-out",
428
- "content-hide": "content-hide 0.2s ease-out"
429
- }
430
- }
431
- },
432
- plugins: [require("tailwindcss-animate")]
433
- }`;
434
-
435
- // src/lib/transformImports.ts
436
- function transformImports(source, config) {
437
- const pathAlias = config.aliases.path.replace("/*", "");
438
- return source.replaceAll(/~\/registry\/ui/g, `${pathAlias}/components/ui`).replaceAll(/~\/lib\/utils/g, `${pathAlias}/lib/utils`);
439
- }
516
+ return sourceFile;
517
+ };
440
518
 
441
- // src/lib/transpileTS.ts
519
+ // src/utils/transformers/transform-jsx.ts
442
520
  import { transformFromAstSync } from "@babel/core";
443
521
  import { parse as parse2 } from "@babel/parser";
444
522
  import transformTypescript from "@babel/plugin-transform-typescript";
@@ -490,15 +568,19 @@ var PARSE_OPTIONS = {
490
568
  "jsx"
491
569
  ]
492
570
  };
493
- var transpileTS = (source) => {
494
- const ast = recast.parse(source, {
571
+ var transformJsx = async ({ sourceFile, config }) => {
572
+ const output = sourceFile.getFullText();
573
+ if (config.tsx) {
574
+ return output;
575
+ }
576
+ const ast = recast.parse(output, {
495
577
  parser: {
496
578
  parse: (code) => {
497
579
  return parse2(code, PARSE_OPTIONS);
498
580
  }
499
581
  }
500
582
  });
501
- const result = transformFromAstSync(ast, source, {
583
+ const result = transformFromAstSync(ast, output, {
502
584
  cloneInputAst: false,
503
585
  code: false,
504
586
  ast: true,
@@ -511,275 +593,628 @@ var transpileTS = (source) => {
511
593
  return recast.print(result.ast).code;
512
594
  };
513
595
 
514
- // src/lib/types.ts
515
- var configSchema = object({
516
- tsx: boolean(),
517
- componentDir: string(),
518
- tailwind: object({
519
- config: string(),
520
- css: string()
521
- }),
522
- aliases: object({
523
- path: string()
524
- })
525
- });
526
-
527
- // src/lib/utils.ts
528
- import { execSync } from "child_process";
529
- import { readFile } from "fs";
530
- import { detect } from "@antfu/ni";
531
- import { log, spinner } from "@clack/prompts";
532
- import JSON5 from "json5";
533
- function readJsonFile(filePath, callback) {
534
- readFile(filePath, "utf8", (err, data) => {
535
- if (err) {
536
- callback(err, null);
537
- return;
596
+ // src/utils/transformers/transform-tw-prefix.ts
597
+ import { SyntaxKind } from "ts-morph";
598
+ var transformTwPrefix = async ({ sourceFile, config }) => {
599
+ if (!config.tailwind.prefix) {
600
+ return sourceFile;
601
+ }
602
+ sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression).filter((node) => node.getExpression().getText() === "cva").forEach((node) => {
603
+ if (node.getArguments()[0]?.isKind(SyntaxKind.StringLiteral)) {
604
+ const defaultClassNames = node.getArguments()[0];
605
+ if (defaultClassNames) {
606
+ defaultClassNames.replaceWithText(
607
+ `"${applyPrefix(defaultClassNames.getText()?.replace(/"/g, ""), config.tailwind.prefix)}"`
608
+ );
609
+ }
538
610
  }
539
- try {
540
- const jsonObject = JSON5.parse(data);
541
- callback(null, jsonObject);
542
- } catch (parseError) {
543
- callback(parseError, null);
611
+ if (node.getArguments()[1]?.isKind(SyntaxKind.ObjectLiteralExpression)) {
612
+ node.getArguments()[1]?.getDescendantsOfKind(SyntaxKind.PropertyAssignment).find((node2) => node2.getName() === "variants")?.getDescendantsOfKind(SyntaxKind.PropertyAssignment).forEach((node2) => {
613
+ node2.getDescendantsOfKind(SyntaxKind.PropertyAssignment).forEach((node3) => {
614
+ const classNames = node3.getInitializerIfKind(SyntaxKind.StringLiteral);
615
+ if (classNames) {
616
+ classNames?.replaceWithText(
617
+ `"${applyPrefix(classNames.getText()?.replace(/"/g, ""), config.tailwind.prefix)}"`
618
+ );
619
+ }
620
+ });
621
+ });
544
622
  }
545
623
  });
546
- }
547
- function runCommand(command, message, endMessage) {
548
- try {
549
- const indicator = spinner();
550
- indicator.start(message);
551
- execSync(command);
552
- indicator.stop(endMessage ?? "Done");
553
- } catch (error) {
554
- log.error(`${error}`);
624
+ sourceFile.getDescendantsOfKind(SyntaxKind.JsxAttribute).forEach((node) => {
625
+ if (node.getName() === "class") {
626
+ if (node.getInitializer()?.isKind(SyntaxKind.StringLiteral)) {
627
+ const value = node.getInitializer();
628
+ if (value) {
629
+ value.replaceWithText(
630
+ `"${applyPrefix(value.getText()?.replace(/"/g, ""), config.tailwind.prefix)}"`
631
+ );
632
+ }
633
+ }
634
+ if (node.getInitializer()?.isKind(SyntaxKind.JsxExpression)) {
635
+ const callExpression = node.getInitializer()?.getDescendantsOfKind(SyntaxKind.CallExpression).find((node2) => node2.getExpression().getText() === "cn");
636
+ if (callExpression) {
637
+ callExpression.getArguments().forEach((node2) => {
638
+ if (node2.isKind(SyntaxKind.ConditionalExpression) || node2.isKind(SyntaxKind.BinaryExpression)) {
639
+ node2.getChildrenOfKind(SyntaxKind.StringLiteral).forEach((node3) => {
640
+ node3.replaceWithText(
641
+ `"${applyPrefix(node3.getText()?.replace(/"/g, ""), config.tailwind.prefix)}"`
642
+ );
643
+ });
644
+ }
645
+ if (node2.isKind(SyntaxKind.StringLiteral)) {
646
+ node2.replaceWithText(
647
+ `"${applyPrefix(node2.getText()?.replace(/"/g, ""), config.tailwind.prefix)}"`
648
+ );
649
+ }
650
+ });
651
+ }
652
+ }
653
+ }
654
+ });
655
+ return sourceFile;
656
+ };
657
+ function applyPrefix(input, prefix = "") {
658
+ const classNames = input.split(" ");
659
+ const prefixed = [];
660
+ for (const className of classNames) {
661
+ const [variant, value, modifier] = splitClassName(className);
662
+ if (variant) {
663
+ modifier ? prefixed.push(`${variant}:${prefix}${value}/${modifier}`) : prefixed.push(`${variant}:${prefix}${value}`);
664
+ } else {
665
+ modifier ? prefixed.push(`${prefix}${value}/${modifier}`) : prefixed.push(`${prefix}${value}`);
666
+ }
555
667
  }
668
+ return prefixed.join(" ");
556
669
  }
557
- function removeExtension(value) {
558
- const splitWords = value.split(".");
559
- return splitWords[0];
560
- }
561
- async function installPackages(...packages) {
562
- const packageManager = await detect({ programmatic: true });
563
- switch (packageManager) {
564
- case "bun":
565
- case "pnpm":
566
- case "pnpm@6":
567
- case "yarn":
568
- case "yarn@berry":
569
- runCommand(`${packageManager} add ${packages.join(" ")}`, "Installing dependencies");
570
- break;
571
- default:
572
- runCommand(`${packageManager} install ${packages.join(" ")}`, "Installing dependencies");
670
+ function splitClassName(className) {
671
+ if (!className.includes("/") && !className.includes(":")) {
672
+ return [null, className, null];
673
+ }
674
+ const parts = [];
675
+ const [rest, alpha] = className.split("/");
676
+ if (!rest?.includes(":")) {
677
+ return [null, rest, alpha];
573
678
  }
679
+ const split = rest?.split(":");
680
+ const name = split.pop();
681
+ const variant = split.join(":");
682
+ parts.push(variant ?? null, name ?? null, alpha ?? null);
683
+ return parts;
574
684
  }
575
685
 
576
- // src/commands/add.ts
577
- async function getComponent(componentName) {
578
- const componentUri = `${registryUIUrl}/${componentName}.json`;
579
- const res = await (await fetch(componentUri)).json();
580
- return res;
686
+ // src/utils/transformers/index.ts
687
+ var project = new Project({
688
+ compilerOptions: {}
689
+ });
690
+ async function createTempSourceFile(filename) {
691
+ const dir = await mkdtemp(path2.join(tmpdir(), "solidui-"));
692
+ return path2.join(dir, filename);
581
693
  }
582
- async function componentSelectionPrompt() {
583
- try {
584
- const componentList = await (await fetch(registryIndexUrl)).json();
585
- const selectedComponents = await prompts({
586
- name: "Selected Components",
587
- type: "multiselect",
588
- message: "Which components would you like to add?",
589
- choices: componentList.map((component) => ({ title: component.name, value: component.name }))
590
- });
591
- await add(selectedComponents["Selected Components"]);
592
- } catch (error) {
593
- log2.info(`Error: ${error}`);
594
- log2.error("Command terminated.");
595
- process.exit(1);
596
- }
694
+ async function transform(props) {
695
+ const tempFile = await createTempSourceFile(props.filename);
696
+ const sourceFile = project.createSourceFile(tempFile, props.raw, { scriptKind: ScriptKind.TSX });
697
+ transformImport({ sourceFile, ...props });
698
+ transformTwPrefix({ sourceFile, ...props });
699
+ return await transformJsx({ sourceFile, ...props });
597
700
  }
598
- async function add(componentNames) {
599
- if (componentNames.length === 0)
600
- await componentSelectionPrompt();
601
- const activityIndicator = spinner2();
602
- activityIndicator.start("Creating components...");
701
+
702
+ // src/commands/add.ts
703
+ var addOptionsSchema = object({
704
+ components: optional(array(string()), []),
705
+ cwd: string(),
706
+ overwrite: boolean(),
707
+ all: boolean()
708
+ });
709
+ var add = new Command().name("add").description("add components to your project").argument("[components...]", "the components to add").option("-c, --cwd <cwd>", "the working directory", process.cwd()).option("-o --overwrite", "overwrite existing files", false).option("-a, --all", "add all available components", false).action(async (components, opts) => {
603
710
  try {
604
- const readUIConfig = readFileSync(path.resolve(cwd(), "ui.config.json"));
605
- const uiConfig = parse(configSchema, JSON.parse(readUIConfig.toString()));
606
- const isTypescriptEnabled = uiConfig.tsx;
607
- const componentFolderDir = path.resolve(cwd(), uiConfig.componentDir);
608
- const dirExists = existsSync(componentFolderDir);
609
- if (!dirExists)
610
- mkdirSync(componentFolderDir, { recursive: true });
611
- const components = await Promise.all(
612
- componentNames.map(async (name) => await getComponent(name))
613
- );
614
- try {
615
- for (const component of components) {
616
- log2.message(`Adding ${component.name} component`);
617
- if (component.dependencies?.length > 0) {
618
- log2.step(`Installing ${component.name} component dependencies`);
619
- await installPackages(...component.dependencies);
620
- }
621
- if (component.registryDependencies?.length > 0) {
622
- log2.step("Installing any other required components");
623
- await add(component.registryDependencies);
711
+ const options = parse(addOptionsSchema, { components, ...opts });
712
+ const cwd = path3.resolve(options.cwd);
713
+ if (!existsSync2(cwd)) {
714
+ throw new Error(`The path ${cwd} does not exist. Please try again.`);
715
+ }
716
+ const config = await getConfig(cwd);
717
+ if (!config) {
718
+ p2.log.warning(
719
+ `Configuration is missing. Please run ${highlight(`init`)} to create a components.json file.`
720
+ );
721
+ process.exit(1);
722
+ }
723
+ const registryIndex = await getRegistryIndex();
724
+ let selectedComponents = options.all ? registryIndex.map((v) => v.name) : options.components;
725
+ if (!selectedComponents.length) {
726
+ const prompts = await p2.group(
727
+ {
728
+ components: () => p2.multiselect({
729
+ message: `Which ${highlight("components")} would you like to add?`,
730
+ options: registryIndex.map((v) => ({ label: v.name, value: v.name }))
731
+ })
732
+ },
733
+ {
734
+ onCancel: () => {
735
+ p2.cancel("Cancelled.");
736
+ process.exit(0);
737
+ }
624
738
  }
625
- for (const file of component.files) {
626
- log2.step(`Creating ${file.name}`);
627
- const content = transformImports(file.content, uiConfig);
628
- if (isTypescriptEnabled) {
629
- writeFileSync(componentFolderDir + `/${file.name}`, content);
630
- } else {
631
- writeFileSync(
632
- componentFolderDir + `/${removeExtension(file.name)}.jsx`,
633
- transpileTS(content)
739
+ );
740
+ selectedComponents = prompts.components;
741
+ }
742
+ if (!selectedComponents.length) {
743
+ p2.log.warn(`No components selected. Exiting.`);
744
+ process.exit(0);
745
+ }
746
+ const tree = await resolveTree(registryIndex, selectedComponents);
747
+ const payload = await fetchTree(tree);
748
+ if (!payload.length) {
749
+ p2.log.warn(`Selected components not found. Exiting.`);
750
+ process.exit(0);
751
+ }
752
+ const spinner3 = p2.spinner();
753
+ spinner3.start("Installing...");
754
+ const targetDir = config.resolvedPaths.components;
755
+ if (!existsSync2(targetDir)) {
756
+ await mkdir(targetDir, { recursive: true });
757
+ }
758
+ for (const item of payload) {
759
+ spinner3.message(`Installing ${highlight(item.name)}...`);
760
+ const existingComponent = item.files.filter(
761
+ (file) => existsSync2(path3.resolve(targetDir, file.name))
762
+ );
763
+ if (existingComponent.length && !options.overwrite) {
764
+ if (selectedComponents.includes(item.name)) {
765
+ spinner3.stop();
766
+ const prompts = await p2.group(
767
+ {
768
+ overwrite: () => p2.confirm({
769
+ message: `Component ${item.name} already exists. Would you like to overwrite?`,
770
+ initialValue: false
771
+ })
772
+ },
773
+ {
774
+ onCancel: () => {
775
+ p2.cancel("Cancelled.");
776
+ process.exit(0);
777
+ }
778
+ }
779
+ );
780
+ const overwrite = prompts.overwrite;
781
+ if (!overwrite) {
782
+ p2.log.info(
783
+ `Skipped ${item.name}. To overwrite, run with the ${highlight("--overwrite")} flag.`
634
784
  );
785
+ continue;
635
786
  }
787
+ spinner3.start(`Installing ${highlight(item.name)}...`);
788
+ } else {
789
+ continue;
636
790
  }
637
791
  }
638
- } catch (error) {
639
- log2.error(`Something went wrong: ${error}`);
640
- process.exit(1);
792
+ for (const file of item.files) {
793
+ let filePath = path3.resolve(targetDir, file.name);
794
+ const content = await transform({
795
+ filename: file.name,
796
+ raw: file.content,
797
+ config
798
+ });
799
+ if (!config.tsx) {
800
+ filePath = filePath.replace(/\.tsx$/, ".jsx");
801
+ filePath = filePath.replace(/\.ts$/, ".js");
802
+ }
803
+ await writeFile(filePath, content, "utf-8");
804
+ }
805
+ if (item.dependencies?.length) {
806
+ const packageManager = await getPackageManager(cwd);
807
+ await execa(packageManager, ["add", ...item.dependencies], { cwd });
808
+ }
641
809
  }
642
- activityIndicator.stop("Successfully created components! \u{1F389}");
643
- return;
644
- } catch (error) {
645
- activityIndicator.stop();
646
- log2.error(
647
- `Something went wrong while creating your components. Have you ran ${chalk.green(
648
- "solidui-cli init"
649
- )}?`
650
- );
651
- process.exit(1);
810
+ spinner3.stop("Done.");
811
+ } catch (e) {
812
+ handleError(e);
652
813
  }
653
- }
814
+ });
654
815
 
655
816
  // src/commands/init.ts
656
- import { existsSync as existsSync2, mkdirSync as mkdirSync2, writeFile, writeFileSync as writeFileSync2 } from "fs";
657
- import { cwd as cwd2 } from "process";
658
- import { confirm, log as log3, select, spinner as spinner3, text } from "@clack/prompts";
659
- async function init() {
660
- const isTypescript = await confirm({
661
- message: "Would you like to use TypeScript? (recommended)",
662
- initialValue: true
663
- });
664
- const globalCssDir = await text({
665
- message: "Where is your global CSS file?",
666
- initialValue: "src/app.css"
667
- });
668
- const tailwindConfigDir = await text({
669
- message: "Where is your tailwind.config.js located?",
670
- initialValue: "tailwind.config.cjs"
671
- });
672
- const pathAlias = await text({
673
- message: "Configure the import alias for the src directory:",
674
- initialValue: "~/*"
675
- });
676
- const config = parse(configSchema, {
677
- tsx: isTypescript,
678
- componentDir: "./src/components/ui",
679
- tailwind: {
680
- config: tailwindConfigDir,
681
- css: globalCssDir
817
+ import { existsSync as existsSync3 } from "node:fs";
818
+ import { mkdir as mkdir2, writeFile as writeFile2 } from "node:fs/promises";
819
+ import path4 from "node:path";
820
+ import * as p3 from "@clack/prompts";
821
+ import { Command as Command2 } from "commander";
822
+ import { execa as execa2 } from "execa";
823
+
824
+ // src/utils/get-package-info.ts
825
+ import fs from "node:fs";
826
+ import { dirname, resolve } from "node:path";
827
+ import { fileURLToPath } from "node:url";
828
+ var __filename = fileURLToPath(import.meta.url);
829
+ var __dirname = dirname(__filename);
830
+ function getPackageInfo() {
831
+ const location = resolve(__dirname, "..", "package.json");
832
+ return readJSONSync(location);
833
+ }
834
+ function readJSONSync(path5) {
835
+ const content = fs.readFileSync(path5, { encoding: "utf-8" });
836
+ return JSON.parse(content);
837
+ }
838
+
839
+ // src/utils/templates.ts
840
+ var UTILS = `import { type ClassValue, clsx } from "clsx"
841
+ import { twMerge } from "tailwind-merge"
842
+
843
+ export function cn(...inputs: ClassValue[]) {
844
+ return twMerge(clsx(inputs))
845
+ }
846
+ `;
847
+ var UTILS_JS = `import { clsx } from "clsx"
848
+ import { twMerge } from "tailwind-merge"
849
+
850
+ export function cn(...inputs) {
851
+ return twMerge(clsx(inputs))
852
+ }
853
+ `;
854
+ var TAILWIND_CONFIG = `/** @type {import('tailwindcss').Config} */
855
+ export default {
856
+ darkMode: ["variant", [".dark &", '[data-kb-theme="dark"] &']],
857
+ content: ["./src/**/*.{ts,tsx}"],
858
+ prefix: "<%- prefix %>",
859
+ theme: {
860
+ container: {
861
+ center: true,
862
+ padding: "2rem",
863
+ screens: {
864
+ "2xl": "1400px"
865
+ }
682
866
  },
683
- aliases: {
684
- path: pathAlias
867
+ extend: {
868
+ colors: {
869
+ border: "hsl(var(--border))",
870
+ input: "hsl(var(--input))",
871
+ ring: "hsl(var(--ring))",
872
+ background: "hsl(var(--background))",
873
+ foreground: "hsl(var(--foreground))",
874
+ primary: {
875
+ DEFAULT: "hsl(var(--primary))",
876
+ foreground: "hsl(var(--primary-foreground))"
877
+ },
878
+ secondary: {
879
+ DEFAULT: "hsl(var(--secondary))",
880
+ foreground: "hsl(var(--secondary-foreground))"
881
+ },
882
+ destructive: {
883
+ DEFAULT: "hsl(var(--destructive))",
884
+ foreground: "hsl(var(--destructive-foreground))"
885
+ },
886
+ info: {
887
+ DEFAULT: "hsl(var(--info))",
888
+ foreground: "hsl(var(--info-foreground))"
889
+ },
890
+ success: {
891
+ DEFAULT: "hsl(var(--success))",
892
+ foreground: "hsl(var(--success-foreground))"
893
+ },
894
+ warning: {
895
+ DEFAULT: "hsl(var(--warning))",
896
+ foreground: "hsl(var(--warning-foreground))"
897
+ },
898
+ error: {
899
+ DEFAULT: "hsl(var(--error))",
900
+ foreground: "hsl(var(--error-foreground))"
901
+ },
902
+ muted: {
903
+ DEFAULT: "hsl(var(--muted))",
904
+ foreground: "hsl(var(--muted-foreground))"
905
+ },
906
+ accent: {
907
+ DEFAULT: "hsl(var(--accent))",
908
+ foreground: "hsl(var(--accent-foreground))"
909
+ },
910
+ popover: {
911
+ DEFAULT: "hsl(var(--popover))",
912
+ foreground: "hsl(var(--popover-foreground))"
913
+ },
914
+ card: {
915
+ DEFAULT: "hsl(var(--card))",
916
+ foreground: "hsl(var(--card-foreground))"
917
+ }
918
+ },
919
+ borderRadius: {
920
+ xl: "calc(var(--radius) + 4px)",
921
+ lg: "var(--radius)",
922
+ md: "calc(var(--radius) - 2px)",
923
+ sm: "calc(var(--radius) - 4px)"
924
+ },
925
+ keyframes: {
926
+ "accordion-down": {
927
+ from: { height: 0 },
928
+ to: { height: "var(--kb-accordion-content-height)" }
929
+ },
930
+ "accordion-up": {
931
+ from: { height: "var(--kb-accordion-content-height)" },
932
+ to: { height: 0 }
933
+ },
934
+ "content-show": {
935
+ from: { opacity: 0, transform: "scale(0.96)" },
936
+ to: { opacity: 1, transform: "scale(1)" }
937
+ },
938
+ "content-hide": {
939
+ from: { opacity: 1, transform: "scale(1)" },
940
+ to: { opacity: 0, transform: "scale(0.96)" }
941
+ },
942
+ "caret-blink": {
943
+ "0%,70%,100%": { opacity: "1" },
944
+ "20%,50%": { opacity: "0" }
945
+ }
946
+ },
947
+ animation: {
948
+ "accordion-down": "accordion-down 0.2s ease-out",
949
+ "accordion-up": "accordion-up 0.2s ease-out",
950
+ "content-show": "content-show 0.2s ease-out",
951
+ "content-hide": "content-hide 0.2s ease-out",
952
+ "caret-blink": "caret-blink 1.25s ease-out infinite"
953
+ }
685
954
  }
686
- });
687
- saveConfig(config);
688
- writeTsconfig(config.aliases.path);
689
- writeUtils();
690
- await writeTailwindConfig(config.tailwind.config);
691
- await writeCSS(config.tailwind.css);
692
- log3.success("Project configuration completed.");
693
- await installDeps();
694
- log3.success("Success! Try 'npx solidui-cli add button' to add a button component to your project");
695
- process.exit(0);
696
- }
697
- function writeUtils() {
698
- const doesLibPathExist = existsSync2(cwd2() + "/src/lib");
699
- const indicator = spinner3();
700
- indicator.start("Creating utils.ts file...");
701
- if (!doesLibPathExist)
702
- mkdirSync2(cwd2() + "/src/lib");
703
- writeFileSync2(cwd2() + "/src/lib/utils.ts", UTILS);
704
- indicator.stop("Done creating utils.ts file!");
705
- }
706
- async function writeCSS(cssPath) {
707
- const indicator = spinner3();
708
- indicator.start("Writing CSS styles...");
709
- writeFile(
710
- cssPath,
711
- ROOT_CSS,
712
- (error) => error && log3.error(error.message || "Something went wrong")
713
- );
714
- indicator.stop("Done Writing CSS styles!");
955
+ },
956
+ plugins: [require("tailwindcss-animate")]
715
957
  }
716
- async function installDeps() {
717
- const shouldInstallDeps = await confirm({
718
- message: "Would you like to install the required dependencies? (recommended)",
719
- initialValue: true
720
- });
721
- if (shouldInstallDeps) {
722
- const packageManager = await select({
723
- message: "Which package manager would you like to use?",
724
- options: [
725
- { label: "npm", value: "npm" },
726
- { label: "yarn", value: "yarn" },
727
- { label: "pnpm", value: "pnpm" },
728
- { label: "bun", value: "bun" }
729
- ],
730
- initialValue: "npm"
731
- });
732
- runCommand(
733
- `${packageManager} ${packageManager === "yarn" ? "add" : "install"} ${PROJECT_DEPS.join(" ")}`,
734
- "Installing Solid UI Component dependencies",
735
- "Dependencies installed"
736
- );
958
+ `;
959
+ var TAILWIND_CSS = `@tailwind base;
960
+ @tailwind components;
961
+ @tailwind utilities;
962
+
963
+ @layer base {
964
+ :root {
965
+ --background: 0 0% 100%;
966
+ --foreground: 240 10% 3.9%;
967
+
968
+ --muted: 240 4.8% 95.9%;
969
+ --muted-foreground: 240 3.8% 46.1%;
970
+
971
+ --popover: 0 0% 100%;
972
+ --popover-foreground: 240 10% 3.9%;
973
+
974
+ --border: 240 5.9% 90%;
975
+ --input: 240 5.9% 90%;
976
+
977
+ --card: 0 0% 100%;
978
+ --card-foreground: 240 10% 3.9%;
979
+
980
+ --primary: 240 5.9% 10%;
981
+ --primary-foreground: 0 0% 98%;
982
+
983
+ --secondary: 240 4.8% 95.9%;
984
+ --secondary-foreground: 240 5.9% 10%;
985
+
986
+ --accent: 240 4.8% 95.9%;
987
+ --accent-foreground: 240 5.9% 10%;
988
+
989
+ --destructive: 0 84.2% 60.2%;
990
+ --destructive-foreground: 0 0% 98%;
991
+
992
+ --info: 204 94% 94%;
993
+ --info-foreground: 199 89% 48%;
994
+
995
+ --success: 149 80% 90%;
996
+ --success-foreground: 160 84% 39%;
997
+
998
+ --warning: 48 96% 89%;
999
+ --warning-foreground: 25 95% 53%;
1000
+
1001
+ --error: 0 93% 94%;
1002
+ --error-foreground: 0 84% 60%;
1003
+
1004
+ --ring: 240 5.9% 10%;
1005
+
1006
+ --radius: 0.5rem;
1007
+ }
1008
+
1009
+ .dark,
1010
+ [data-kb-theme="dark"] {
1011
+ --background: 240 10% 3.9%;
1012
+ --foreground: 0 0% 98%;
1013
+
1014
+ --muted: 240 3.7% 15.9%;
1015
+ --muted-foreground: 240 5% 64.9%;
1016
+
1017
+ --accent: 240 3.7% 15.9%;
1018
+ --accent-foreground: 0 0% 98%;
1019
+
1020
+ --popover: 240 10% 3.9%;
1021
+ --popover-foreground: 0 0% 98%;
1022
+
1023
+ --border: 240 3.7% 15.9%;
1024
+ --input: 240 3.7% 15.9%;
1025
+
1026
+ --card: 240 10% 3.9%;
1027
+ --card-foreground: 0 0% 98%;
1028
+
1029
+ --primary: 0 0% 98%;
1030
+ --primary-foreground: 240 5.9% 10%;
1031
+
1032
+ --secondary: 240 3.7% 15.9%;
1033
+ --secondary-foreground: 0 0% 98%;
1034
+
1035
+ --destructive: 0 62.8% 30.6%;
1036
+ --destructive-foreground: 0 0% 98%;
1037
+
1038
+ --info: 204 94% 94%;
1039
+ --info-foreground: 199 89% 48%;
1040
+
1041
+ --success: 149 80% 90%;
1042
+ --success-foreground: 160 84% 39%;
1043
+
1044
+ --warning: 48 96% 89%;
1045
+ --warning-foreground: 25 95% 53%;
1046
+
1047
+ --error: 0 93% 94%;
1048
+ --error-foreground: 0 84% 60%;
1049
+
1050
+ --ring: 240 4.9% 83.9%;
1051
+
1052
+ --radius: 0.5rem;
737
1053
  }
738
1054
  }
739
- function saveConfig(config) {
740
- const indicator = spinner3();
741
- indicator.start("Writing ui.config.json...");
742
- writeFile("ui.config.json", JSON.stringify(config, null, 2), (error) => {
743
- if (error)
744
- log3.error("There was an error while saving your preferences");
745
- });
746
- indicator.stop("ui.config.json successfully created!");
747
- }
748
- async function writeTailwindConfig(tailwindConfigDir) {
749
- const indicator = spinner3();
750
- indicator.start("Configuring tailwind.config.cjs to support Solid UI Components...");
751
- writeFile(tailwindConfigDir, TAILWIND_CONFIG, (error) => {
752
- if (error)
753
- log3.error(`Something went wrong while writing your tailwind.config.cjs: ${error}`);
754
- });
755
- indicator.stop("Done done configuring your tailwind.config.cjs");
756
- }
757
- function writeTsconfig(alias) {
758
- const indicator = spinner3();
759
- indicator.start("Configuring your tsconfig.json");
760
- readJsonFile(process.cwd() + "/tsconfig.json", (error, data) => {
761
- if (error) {
762
- log3.error(
763
- "Something went wrong while configuring your tsconfig.json. Please make sure it is formatted correctly and doesn't contain any comments."
764
- );
765
- process.exit(1);
1055
+
1056
+ @layer base {
1057
+ * {
1058
+ @apply border-border;
1059
+ }
1060
+ body {
1061
+ @apply bg-background text-foreground;
1062
+ font-feature-settings:
1063
+ "rlig" 1,
1064
+ "calt" 1;
1065
+ }
1066
+ }
1067
+
1068
+ @layer utilities {
1069
+ .step {
1070
+ counter-increment: step;
1071
+ }
1072
+
1073
+ .step:before {
1074
+ @apply absolute w-9 h-9 bg-muted rounded-full font-mono font-medium text-center text-base inline-flex items-center justify-center -indent-px border-4 border-background;
1075
+ @apply ml-[-50px] mt-[-4px];
1076
+ content: counter(step);
1077
+ }
1078
+ }
1079
+
1080
+ @media (max-width: 640px) {
1081
+ .container {
1082
+ @apply px-4;
1083
+ }
1084
+ }
1085
+
1086
+ ::-webkit-scrollbar {
1087
+ width: 16px;
1088
+ }
1089
+
1090
+ ::-webkit-scrollbar-thumb {
1091
+ border-radius: 9999px;
1092
+ border: 4px solid transparent;
1093
+ background-clip: content-box;
1094
+ @apply bg-accent;
1095
+ }
1096
+
1097
+ ::-webkit-scrollbar-corner {
1098
+ display: none;
1099
+ }
1100
+ `;
1101
+
1102
+ // src/commands/init.ts
1103
+ var PROJECT_DEPENDENCIES = [
1104
+ "tailwindcss-animate",
1105
+ "class-variance-authority",
1106
+ "clsx",
1107
+ "tailwind-merge"
1108
+ ];
1109
+ var initOptionsSchema = object({
1110
+ cwd: string()
1111
+ });
1112
+ var init = new Command2().name("init").description("initialize your project and install dependencies").option("-c, --cwd <cwd>", "the working directory", process.cwd()).action(async (opts) => {
1113
+ try {
1114
+ const options = parse(initOptionsSchema, opts);
1115
+ const cwd = path4.resolve(options.cwd);
1116
+ if (!existsSync3(cwd)) {
1117
+ throw new Error(`The path ${cwd} does not exist. Please try again.`);
1118
+ }
1119
+ const info = getPackageInfo();
1120
+ p3.intro(headline(` ${info.name} - ${info.version} `));
1121
+ const rawConfig = await promptForConfig();
1122
+ const spinner3 = p3.spinner();
1123
+ spinner3.start(`Creating ui.config.json...`);
1124
+ const targetPath = path4.resolve(cwd, "ui.config.json");
1125
+ await writeFile2(targetPath, JSON.stringify(rawConfig, null, 2), "utf-8");
1126
+ spinner3.stop(`ui.config.json created.`);
1127
+ const config = await resolveConfigPaths(cwd, rawConfig);
1128
+ spinner3.start(`Initializing project...`);
1129
+ for (const [key, resolvedPath] of Object.entries(config.resolvedPaths)) {
1130
+ let dirname2 = path4.extname(resolvedPath) ? path4.dirname(resolvedPath) : resolvedPath;
1131
+ if (key === "utils" && resolvedPath.endsWith("/utils")) {
1132
+ dirname2 = dirname2.replace(/\/utils$/, "");
1133
+ }
1134
+ if (!existsSync3(dirname2)) {
1135
+ await mkdir2(dirname2, { recursive: true });
1136
+ }
1137
+ }
1138
+ const extension = config.tsx ? "ts" : "js";
1139
+ await writeFile2(
1140
+ config.resolvedPaths.tailwindConfig,
1141
+ TAILWIND_CONFIG.replace("<%- prefix %>", config.tailwind.prefix),
1142
+ "utf-8"
1143
+ );
1144
+ await writeFile2(config.resolvedPaths.tailwindCss, TAILWIND_CSS, "utf-8");
1145
+ await writeFile2(
1146
+ `${config.resolvedPaths.utils}.${extension}`,
1147
+ extension === "ts" ? UTILS : UTILS_JS,
1148
+ "utf-8"
1149
+ );
1150
+ spinner3.stop(`Project initialized.`);
1151
+ spinner3.start(`Installing dependencies...`);
1152
+ const packageManager = await getPackageManager(cwd);
1153
+ await execa2(packageManager, ["add", ...PROJECT_DEPENDENCIES], { cwd });
1154
+ spinner3.stop(`Dependencies installed.`);
1155
+ p3.outro(
1156
+ `${highlight("Success!")} Project initialization completed. You may now add components.`
1157
+ );
1158
+ } catch (e) {
1159
+ handleError(e);
1160
+ }
1161
+ });
1162
+ async function promptForConfig() {
1163
+ const options = await p3.group(
1164
+ {
1165
+ typescript: () => p3.confirm({
1166
+ message: `Would you like to use ${highlight("Typescript")} (recommended)?`,
1167
+ initialValue: true
1168
+ }),
1169
+ cssFile: () => p3.text({
1170
+ message: `Where is your ${highlight("global CSS")} file? ${subtle("(this file will be overwritten)")}`,
1171
+ initialValue: DEFAULT_CSS_FILE
1172
+ }),
1173
+ tailwindConfig: () => p3.text({
1174
+ message: `Where is your ${highlight("Tailwind config")} located? ${subtle("(this file will be overwritten)")}`,
1175
+ initialValue: DEFAULT_TAILWIND_CONFIG
1176
+ }),
1177
+ tailwindPrefix: () => p3.text({
1178
+ message: `Are you using a custom ${highlight("tailwind prefix eg. tw-")}? (Leave blank if not)`,
1179
+ initialValue: DEFAULT_TAILWIND_PREFIX
1180
+ }),
1181
+ components: () => p3.text({
1182
+ message: `Configure the import alias for ${highlight("components")}:`,
1183
+ initialValue: DEFAULT_COMPONENTS
1184
+ }),
1185
+ utils: () => p3.text({
1186
+ message: `Configure the import alias for ${highlight("utils")}:`,
1187
+ initialValue: DEFAULT_UTILS
1188
+ })
1189
+ },
1190
+ {
1191
+ onCancel: () => {
1192
+ p3.cancel("Cancelled.");
1193
+ process.exit(0);
1194
+ }
766
1195
  }
767
- const tsconfigData = data;
768
- if (!tsconfigData.compilerOptions.paths) {
769
- tsconfigData.compilerOptions.paths = {};
1196
+ );
1197
+ return parse(RawConfigSchema, {
1198
+ $schema: "https://solid-ui.com/schema.json",
1199
+ tsx: options.typescript,
1200
+ tailwind: {
1201
+ css: options.cssFile,
1202
+ config: options.tailwindConfig,
1203
+ prefix: options.tailwindPrefix
1204
+ },
1205
+ aliases: {
1206
+ components: options.components,
1207
+ utils: options.utils
770
1208
  }
771
- tsconfigData.compilerOptions.paths[alias] = ["./src/*"];
772
- writeFile("tsconfig.json", JSON.stringify(tsconfigData, null, 2), (error2) => {
773
- if (error2)
774
- log3.error(`Something went wrong while configuring your tsconfig.json: ${error2}`);
775
- });
776
1209
  });
777
- indicator.stop("Done configuring your tsconfig.json");
778
1210
  }
779
1211
 
780
1212
  // src/index.ts
781
- var program = new Command();
782
- program.name("solidui-cli").description("A CLI used for the Solid-UI components library").version("0.1");
783
- program.command("init").description("Initialize and install the necessary things to make use of Solid-UI").action(async () => await init());
784
- program.command("add").argument("[components...]", "Components to be added to your project").description("Add a component to your project").action(async (component) => await add(component));
785
- program.parse();
1213
+ process.on("SIGINT", () => process.exit(0));
1214
+ process.on("SIGTERM", () => process.exit(0));
1215
+ async function main() {
1216
+ console.clear();
1217
+ const packageInfo = getPackageInfo();
1218
+ new Command3().name("solidui-cli").description("add SolidUI components to your project").version(packageInfo.version || "0.0.0", "-v, --version", "display the version number").addCommand(init).addCommand(add).parse();
1219
+ }
1220
+ main();