solidui-cli 0.1.2 → 0.1.4
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/README.md +43 -0
- package/dist/index.js +842 -0
- package/package.json +30 -14
- package/CHANGELOG.md +0 -22
- package/src/commands/add.ts +0 -110
- package/src/commands/init.ts +0 -166
- package/src/index.ts +0 -23
- package/src/lib/constants.ts +0 -236
- package/src/lib/transformImports.ts +0 -8
- package/src/lib/transpileTS.ts +0 -85
- package/src/lib/types.ts +0 -40
- package/src/lib/utils.ts +0 -56
- package/tsconfig.json +0 -18
- package/tsup.config.json +0 -7
package/dist/index.js
ADDED
|
@@ -0,0 +1,842 @@
|
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
|
|
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";
|
|
13
|
+
|
|
14
|
+
// ../../node_modules/.pnpm/valibot@0.18.0/node_modules/valibot/dist/index.js
|
|
15
|
+
var ValiError = class extends Error {
|
|
16
|
+
issues;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a Valibot error with useful information.
|
|
19
|
+
*
|
|
20
|
+
* @param issues The error issues.
|
|
21
|
+
*/
|
|
22
|
+
constructor(issues) {
|
|
23
|
+
super(issues[0].message);
|
|
24
|
+
this.name = "ValiError";
|
|
25
|
+
this.issues = issues;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var BrandSymbol = Symbol("brand");
|
|
29
|
+
function getIssues(issues) {
|
|
30
|
+
return { issues };
|
|
31
|
+
}
|
|
32
|
+
function getOutput(output) {
|
|
33
|
+
return { output };
|
|
34
|
+
}
|
|
35
|
+
function getIssue(info, issue) {
|
|
36
|
+
return {
|
|
37
|
+
reason: info?.reason,
|
|
38
|
+
validation: issue.validation,
|
|
39
|
+
origin: info?.origin || "value",
|
|
40
|
+
message: issue.message,
|
|
41
|
+
input: issue.input,
|
|
42
|
+
path: issue.path,
|
|
43
|
+
abortEarly: info?.abortEarly,
|
|
44
|
+
abortPipeEarly: info?.abortPipeEarly,
|
|
45
|
+
skipPipe: info?.skipPipe
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function getPipeInfo(info, reason) {
|
|
49
|
+
return {
|
|
50
|
+
reason,
|
|
51
|
+
origin: info?.origin,
|
|
52
|
+
abortEarly: info?.abortEarly,
|
|
53
|
+
abortPipeEarly: info?.abortPipeEarly,
|
|
54
|
+
skipPipe: info?.skipPipe
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function executePipe(input, pipe, parseInfo, reason) {
|
|
58
|
+
if (!pipe || !pipe.length || parseInfo?.skipPipe) {
|
|
59
|
+
return getOutput(input);
|
|
60
|
+
}
|
|
61
|
+
let pipeInfo;
|
|
62
|
+
let issues;
|
|
63
|
+
let output = input;
|
|
64
|
+
for (const action of pipe) {
|
|
65
|
+
const result = action(output);
|
|
66
|
+
if (result.issues) {
|
|
67
|
+
pipeInfo = pipeInfo || getPipeInfo(parseInfo, reason);
|
|
68
|
+
for (const issueInfo of result.issues) {
|
|
69
|
+
const issue = getIssue(pipeInfo, issueInfo);
|
|
70
|
+
issues ? issues.push(issue) : issues = [issue];
|
|
71
|
+
}
|
|
72
|
+
if (pipeInfo.abortEarly || pipeInfo.abortPipeEarly) {
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
output = result.output;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return issues ? getIssues(issues) : getOutput(output);
|
|
80
|
+
}
|
|
81
|
+
function getDefaultArgs(arg1, arg2) {
|
|
82
|
+
return Array.isArray(arg1) ? [void 0, arg1] : [arg1, arg2];
|
|
83
|
+
}
|
|
84
|
+
function getErrorMessage(error) {
|
|
85
|
+
return typeof error === "function" ? error() : error;
|
|
86
|
+
}
|
|
87
|
+
function getSchemaIssues(info, reason, validation, error, input, issues) {
|
|
88
|
+
return {
|
|
89
|
+
issues: [
|
|
90
|
+
{
|
|
91
|
+
reason,
|
|
92
|
+
validation,
|
|
93
|
+
origin: info?.origin || "value",
|
|
94
|
+
message: getErrorMessage(error),
|
|
95
|
+
input,
|
|
96
|
+
issues,
|
|
97
|
+
abortEarly: info?.abortEarly,
|
|
98
|
+
abortPipeEarly: info?.abortPipeEarly,
|
|
99
|
+
skipPipe: info?.skipPipe
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function boolean(arg1, arg2) {
|
|
105
|
+
const [error, pipe] = getDefaultArgs(arg1, arg2);
|
|
106
|
+
return {
|
|
107
|
+
/**
|
|
108
|
+
* The schema type.
|
|
109
|
+
*/
|
|
110
|
+
schema: "boolean",
|
|
111
|
+
/**
|
|
112
|
+
* Whether it's async.
|
|
113
|
+
*/
|
|
114
|
+
async: false,
|
|
115
|
+
/**
|
|
116
|
+
* Parses unknown input based on its schema.
|
|
117
|
+
*
|
|
118
|
+
* @param input The input to be parsed.
|
|
119
|
+
* @param info The parse info.
|
|
120
|
+
*
|
|
121
|
+
* @returns The parsed output.
|
|
122
|
+
*/
|
|
123
|
+
_parse(input, info) {
|
|
124
|
+
if (typeof input !== "boolean") {
|
|
125
|
+
return getSchemaIssues(
|
|
126
|
+
info,
|
|
127
|
+
"type",
|
|
128
|
+
"boolean",
|
|
129
|
+
error || "Invalid type",
|
|
130
|
+
input
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
return executePipe(input, pipe, info, "boolean");
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function object(object2, arg2, arg3) {
|
|
138
|
+
const [error, pipe] = getDefaultArgs(arg2, arg3);
|
|
139
|
+
let cachedEntries;
|
|
140
|
+
return {
|
|
141
|
+
/**
|
|
142
|
+
* The schema type.
|
|
143
|
+
*/
|
|
144
|
+
schema: "object",
|
|
145
|
+
/**
|
|
146
|
+
* The object schema.
|
|
147
|
+
*/
|
|
148
|
+
object: object2,
|
|
149
|
+
/**
|
|
150
|
+
* Whether it's async.
|
|
151
|
+
*/
|
|
152
|
+
async: false,
|
|
153
|
+
/**
|
|
154
|
+
* Parses unknown input based on its schema.
|
|
155
|
+
*
|
|
156
|
+
* @param input The input to be parsed.
|
|
157
|
+
* @param info The parse info.
|
|
158
|
+
*
|
|
159
|
+
* @returns The parsed output.
|
|
160
|
+
*/
|
|
161
|
+
_parse(input, info) {
|
|
162
|
+
if (!input || typeof input !== "object") {
|
|
163
|
+
return getSchemaIssues(
|
|
164
|
+
info,
|
|
165
|
+
"type",
|
|
166
|
+
"object",
|
|
167
|
+
error || "Invalid type",
|
|
168
|
+
input
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
cachedEntries = cachedEntries || Object.entries(object2);
|
|
172
|
+
let issues;
|
|
173
|
+
const output = {};
|
|
174
|
+
for (const [key, schema] of cachedEntries) {
|
|
175
|
+
const value2 = input[key];
|
|
176
|
+
const result = schema._parse(value2, info);
|
|
177
|
+
if (result.issues) {
|
|
178
|
+
const pathItem = {
|
|
179
|
+
schema: "object",
|
|
180
|
+
input,
|
|
181
|
+
key,
|
|
182
|
+
value: value2
|
|
183
|
+
};
|
|
184
|
+
for (const issue of result.issues) {
|
|
185
|
+
if (issue.path) {
|
|
186
|
+
issue.path.unshift(pathItem);
|
|
187
|
+
} else {
|
|
188
|
+
issue.path = [pathItem];
|
|
189
|
+
}
|
|
190
|
+
issues?.push(issue);
|
|
191
|
+
}
|
|
192
|
+
if (!issues) {
|
|
193
|
+
issues = result.issues;
|
|
194
|
+
}
|
|
195
|
+
if (info?.abortEarly) {
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
} else {
|
|
199
|
+
output[key] = result.output;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return issues ? getIssues(issues) : executePipe(
|
|
203
|
+
output,
|
|
204
|
+
pipe,
|
|
205
|
+
info,
|
|
206
|
+
"object"
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
function string(arg1, arg2) {
|
|
212
|
+
const [error, pipe] = getDefaultArgs(arg1, arg2);
|
|
213
|
+
return {
|
|
214
|
+
/**
|
|
215
|
+
* The schema type.
|
|
216
|
+
*/
|
|
217
|
+
schema: "string",
|
|
218
|
+
/**
|
|
219
|
+
* Whether it's async.
|
|
220
|
+
*/
|
|
221
|
+
async: false,
|
|
222
|
+
/**
|
|
223
|
+
* Parses unknown input based on its schema.
|
|
224
|
+
*
|
|
225
|
+
* @param input The input to be parsed.
|
|
226
|
+
* @param info The parse info.
|
|
227
|
+
*
|
|
228
|
+
* @returns The parsed output.
|
|
229
|
+
*/
|
|
230
|
+
_parse(input, info) {
|
|
231
|
+
if (typeof input !== "string") {
|
|
232
|
+
return getSchemaIssues(
|
|
233
|
+
info,
|
|
234
|
+
"type",
|
|
235
|
+
"string",
|
|
236
|
+
error || "Invalid type",
|
|
237
|
+
input
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
return executePipe(input, pipe, info, "string");
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
function parse(schema, input, info) {
|
|
245
|
+
const result = schema._parse(input, info);
|
|
246
|
+
if (result.issues) {
|
|
247
|
+
throw new ValiError(result.issues);
|
|
248
|
+
}
|
|
249
|
+
return result.output;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// src/lib/constants.ts
|
|
253
|
+
var PROJECT_DEPS = [
|
|
254
|
+
"tailwindcss-animate",
|
|
255
|
+
"class-variance-authority",
|
|
256
|
+
"clsx",
|
|
257
|
+
"tailwind-merge",
|
|
258
|
+
"@kobalte/core",
|
|
259
|
+
"tailwindcss"
|
|
260
|
+
];
|
|
261
|
+
var registryUIUrl = "https://solid-ui-components.vercel.app/registry/ui";
|
|
262
|
+
var registryIndexUrl = "https://solid-ui-components.vercel.app/registry/index.json";
|
|
263
|
+
var UTILS = `import type { ClassValue } from "clsx"
|
|
264
|
+
import { clsx } from "clsx"
|
|
265
|
+
import { twMerge } from "tailwind-merge"
|
|
266
|
+
|
|
267
|
+
export function cn(...inputs: ClassValue[]) {
|
|
268
|
+
return twMerge(clsx(inputs))
|
|
269
|
+
}`;
|
|
270
|
+
var ROOT_CSS = `@tailwind base;
|
|
271
|
+
@tailwind components;
|
|
272
|
+
@tailwind utilities;
|
|
273
|
+
|
|
274
|
+
@layer base {
|
|
275
|
+
:root {
|
|
276
|
+
--background: 0 0% 100%;
|
|
277
|
+
--foreground: 240 10% 3.9%;
|
|
278
|
+
|
|
279
|
+
--muted: 240 4.8% 95.9%;
|
|
280
|
+
--muted-foreground: 240 3.8% 46.1%;
|
|
281
|
+
|
|
282
|
+
--popover: 0 0% 100%;
|
|
283
|
+
--popover-foreground: 240 10% 3.9%;
|
|
284
|
+
|
|
285
|
+
--border: 240 5.9% 90%;
|
|
286
|
+
--input: 240 5.9% 90%;
|
|
287
|
+
|
|
288
|
+
--card: 0 0% 100%;
|
|
289
|
+
--card-foreground: 240 10% 3.9%;
|
|
290
|
+
|
|
291
|
+
--primary: 240 5.9% 10%;
|
|
292
|
+
--primary-foreground: 0 0% 98%;
|
|
293
|
+
|
|
294
|
+
--secondary: 240 4.8% 95.9%;
|
|
295
|
+
--secondary-foreground: 240 5.9% 10%;
|
|
296
|
+
|
|
297
|
+
--accent: 240 4.8% 95.9%;
|
|
298
|
+
--accent-foreground: 240 5.9% 10%;
|
|
299
|
+
|
|
300
|
+
--destructive: 0 84.2% 60.2%;
|
|
301
|
+
--destructive-foreground: 0 0% 98%;
|
|
302
|
+
|
|
303
|
+
--info: 204 94% 94%;
|
|
304
|
+
--info-foreground: 199 89% 48%;
|
|
305
|
+
|
|
306
|
+
--success: 149 80% 90%;
|
|
307
|
+
--success-foreground: 160 84% 39%;
|
|
308
|
+
|
|
309
|
+
--warning: 48 96% 89%;
|
|
310
|
+
--warning-foreground: 25 95% 53%;
|
|
311
|
+
|
|
312
|
+
--error: 0 93% 94%;
|
|
313
|
+
--error-foreground: 0 84% 60%;
|
|
314
|
+
|
|
315
|
+
--ring: 240 5.9% 10%;
|
|
316
|
+
|
|
317
|
+
--radius: 0.5rem;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
[data-kb-theme="dark"] {
|
|
321
|
+
--background: 240 10% 3.9%;
|
|
322
|
+
--foreground: 0 0% 98%;
|
|
323
|
+
|
|
324
|
+
--muted: 240 3.7% 15.9%;
|
|
325
|
+
--muted-foreground: 240 5% 64.9%;
|
|
326
|
+
|
|
327
|
+
--accent: 240 3.7% 15.9%;
|
|
328
|
+
--accent-foreground: 0 0% 98%;
|
|
329
|
+
|
|
330
|
+
--popover: 240 10% 3.9%;
|
|
331
|
+
--popover-foreground: 0 0% 98%;
|
|
332
|
+
|
|
333
|
+
--border: 240 3.7% 15.9%;
|
|
334
|
+
--input: 240 3.7% 15.9%;
|
|
335
|
+
|
|
336
|
+
--card: 240 10% 3.9%;
|
|
337
|
+
--card-foreground: 0 0% 98%;
|
|
338
|
+
|
|
339
|
+
--primary: 0 0% 98%;
|
|
340
|
+
--primary-foreground: 240 5.9% 10%;
|
|
341
|
+
|
|
342
|
+
--secondary: 240 3.7% 15.9%;
|
|
343
|
+
--secondary-foreground: 0 0% 98%;
|
|
344
|
+
|
|
345
|
+
--destructive: 0 62.8% 30.6%;
|
|
346
|
+
--destructive-foreground: 0 0% 98%;
|
|
347
|
+
|
|
348
|
+
--info: 204 94% 94%;
|
|
349
|
+
--info-foreground: 199 89% 48%;
|
|
350
|
+
|
|
351
|
+
--success: 149 80% 90%;
|
|
352
|
+
--success-foreground: 160 84% 39%;
|
|
353
|
+
|
|
354
|
+
--warning: 48 96% 89%;
|
|
355
|
+
--warning-foreground: 25 95% 53%;
|
|
356
|
+
|
|
357
|
+
--error: 0 93% 94%;
|
|
358
|
+
--error-foreground: 0 84% 60%;
|
|
359
|
+
|
|
360
|
+
--ring: 240 4.9% 83.9%;
|
|
361
|
+
|
|
362
|
+
--radius: 0.5rem;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
@layer base {
|
|
367
|
+
* {
|
|
368
|
+
@apply border-border;
|
|
369
|
+
}
|
|
370
|
+
body {
|
|
371
|
+
@apply bg-background text-foreground;
|
|
372
|
+
font-feature-settings:
|
|
373
|
+
"rlig" 1,
|
|
374
|
+
"calt" 1;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
@media (max-width: 640px) {
|
|
379
|
+
.container {
|
|
380
|
+
@apply px-4;
|
|
381
|
+
}
|
|
382
|
+
}`;
|
|
383
|
+
var TAILWIND_PRESET = `const {fontFamily} = require("tailwindcss/defaultTheme")
|
|
384
|
+
|
|
385
|
+
/**@type {import("tailwindcss").Config} */
|
|
386
|
+
module.exports = {
|
|
387
|
+
darkMode: ["class", '[data-kb-theme="dark"]'],
|
|
388
|
+
content: ["./src/**/*.{js,jsx,md,mdx,ts,tsx}"],
|
|
389
|
+
theme: {
|
|
390
|
+
container: {
|
|
391
|
+
center: true,
|
|
392
|
+
padding: "2rem",
|
|
393
|
+
screens: {
|
|
394
|
+
"2xl": "1400px"
|
|
395
|
+
}
|
|
396
|
+
},
|
|
397
|
+
extend: {
|
|
398
|
+
colors: {
|
|
399
|
+
border: "hsl(var(--border))",
|
|
400
|
+
input: "hsl(var(--input))",
|
|
401
|
+
ring: "hsl(var(--ring))",
|
|
402
|
+
background: "hsl(var(--background))",
|
|
403
|
+
foreground: "hsl(var(--foreground))",
|
|
404
|
+
primary: {
|
|
405
|
+
DEFAULT: "hsl(var(--primary))",
|
|
406
|
+
foreground: "hsl(var(--primary-foreground))"
|
|
407
|
+
},
|
|
408
|
+
secondary: {
|
|
409
|
+
DEFAULT: "hsl(var(--secondary))",
|
|
410
|
+
foreground: "hsl(var(--secondary-foreground))"
|
|
411
|
+
},
|
|
412
|
+
destructive: {
|
|
413
|
+
DEFAULT: "hsl(var(--destructive))",
|
|
414
|
+
foreground: "hsl(var(--destructive-foreground))"
|
|
415
|
+
},
|
|
416
|
+
info: {
|
|
417
|
+
DEFAULT: "hsl(var(--info))",
|
|
418
|
+
foreground: "hsl(var(--info-foreground))"
|
|
419
|
+
},
|
|
420
|
+
success: {
|
|
421
|
+
DEFAULT: "hsl(var(--success))",
|
|
422
|
+
foreground: "hsl(var(--success-foreground))"
|
|
423
|
+
},
|
|
424
|
+
warning: {
|
|
425
|
+
DEFAULT: "hsl(var(--warning))",
|
|
426
|
+
foreground: "hsl(var(--warning-foreground))"
|
|
427
|
+
},
|
|
428
|
+
error: {
|
|
429
|
+
DEFAULT: "hsl(var(--error))",
|
|
430
|
+
foreground: "hsl(var(--error-foreground))"
|
|
431
|
+
},
|
|
432
|
+
muted: {
|
|
433
|
+
DEFAULT: "hsl(var(--muted))",
|
|
434
|
+
foreground: "hsl(var(--muted-foreground))"
|
|
435
|
+
},
|
|
436
|
+
accent: {
|
|
437
|
+
DEFAULT: "hsl(var(--accent))",
|
|
438
|
+
foreground: "hsl(var(--accent-foreground))"
|
|
439
|
+
},
|
|
440
|
+
popover: {
|
|
441
|
+
DEFAULT: "hsl(var(--popover))",
|
|
442
|
+
foreground: "hsl(var(--popover-foreground))"
|
|
443
|
+
},
|
|
444
|
+
card: {
|
|
445
|
+
DEFAULT: "hsl(var(--card))",
|
|
446
|
+
foreground: "hsl(var(--card-foreground))"
|
|
447
|
+
}
|
|
448
|
+
},
|
|
449
|
+
borderRadius: {
|
|
450
|
+
lg: "var(--radius)",
|
|
451
|
+
md: "calc(var(--radius) - 2px)",
|
|
452
|
+
sm: "calc(var(--radius) - 4px)"
|
|
453
|
+
},
|
|
454
|
+
fontFamily: {
|
|
455
|
+
sans: ["Inter", ...fontFamily.sans]
|
|
456
|
+
},
|
|
457
|
+
keyframes: {
|
|
458
|
+
"accordion-down": {
|
|
459
|
+
from: { height: 0 },
|
|
460
|
+
to: { height: "var(--kb-accordion-content-height)" }
|
|
461
|
+
},
|
|
462
|
+
"accordion-up": {
|
|
463
|
+
from: { height: "var(--kb-accordion-content-height)" },
|
|
464
|
+
to: { height: 0 }
|
|
465
|
+
}
|
|
466
|
+
},
|
|
467
|
+
animation: {
|
|
468
|
+
"accordion-down": "accordion-down 0.2s ease-out",
|
|
469
|
+
"accordion-up": "accordion-up 0.2s ease-out"
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
},
|
|
473
|
+
plugins: [require("tailwindcss-animate")]
|
|
474
|
+
}`;
|
|
475
|
+
var TAILWIND_CONFIG = `/** @type {import('tailwindcss').Config} */
|
|
476
|
+
export default {
|
|
477
|
+
darkMode: ["class"],
|
|
478
|
+
content: [
|
|
479
|
+
"./src/**/*.{html,js,jsx,md,mdx,ts,tsx}"
|
|
480
|
+
],
|
|
481
|
+
presets: [require("./suc.preset.js")]
|
|
482
|
+
}`;
|
|
483
|
+
|
|
484
|
+
// src/lib/transformImports.ts
|
|
485
|
+
function transformImports(source, config) {
|
|
486
|
+
const pathAlias = config.aliases.path.replace("/*", "");
|
|
487
|
+
return source.replaceAll(/~\/registry\/ui/g, `${pathAlias}/components/ui`).replaceAll(/~\/lib\/utils/g, `${pathAlias}/lib/utils`);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// src/lib/transpileTS.ts
|
|
491
|
+
import { transformFromAstSync } from "@babel/core";
|
|
492
|
+
import { parse as parse2 } from "@babel/parser";
|
|
493
|
+
import transformTypescript from "@babel/plugin-transform-typescript";
|
|
494
|
+
import * as recast from "recast";
|
|
495
|
+
var PARSE_OPTIONS = {
|
|
496
|
+
sourceType: "module",
|
|
497
|
+
allowImportExportEverywhere: true,
|
|
498
|
+
allowReturnOutsideFunction: true,
|
|
499
|
+
startLine: 1,
|
|
500
|
+
tokens: true,
|
|
501
|
+
plugins: [
|
|
502
|
+
"asyncGenerators",
|
|
503
|
+
"bigInt",
|
|
504
|
+
"classPrivateMethods",
|
|
505
|
+
"classPrivateProperties",
|
|
506
|
+
"classProperties",
|
|
507
|
+
"classStaticBlock",
|
|
508
|
+
"decimal",
|
|
509
|
+
"decorators-legacy",
|
|
510
|
+
"doExpressions",
|
|
511
|
+
"dynamicImport",
|
|
512
|
+
"exportDefaultFrom",
|
|
513
|
+
"exportNamespaceFrom",
|
|
514
|
+
"functionBind",
|
|
515
|
+
"functionSent",
|
|
516
|
+
"importAssertions",
|
|
517
|
+
"importMeta",
|
|
518
|
+
"nullishCoalescingOperator",
|
|
519
|
+
"numericSeparator",
|
|
520
|
+
"objectRestSpread",
|
|
521
|
+
"optionalCatchBinding",
|
|
522
|
+
"optionalChaining",
|
|
523
|
+
[
|
|
524
|
+
"pipelineOperator",
|
|
525
|
+
{
|
|
526
|
+
proposal: "minimal"
|
|
527
|
+
}
|
|
528
|
+
],
|
|
529
|
+
[
|
|
530
|
+
"recordAndTuple",
|
|
531
|
+
{
|
|
532
|
+
syntaxType: "hash"
|
|
533
|
+
}
|
|
534
|
+
],
|
|
535
|
+
"throwExpressions",
|
|
536
|
+
"topLevelAwait",
|
|
537
|
+
"v8intrinsic",
|
|
538
|
+
"typescript",
|
|
539
|
+
"jsx"
|
|
540
|
+
]
|
|
541
|
+
};
|
|
542
|
+
var transpileTS = (source) => {
|
|
543
|
+
const ast = recast.parse(source, {
|
|
544
|
+
parser: {
|
|
545
|
+
parse: (code) => {
|
|
546
|
+
return parse2(code, PARSE_OPTIONS);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
const result = transformFromAstSync(ast, source, {
|
|
551
|
+
cloneInputAst: false,
|
|
552
|
+
code: false,
|
|
553
|
+
ast: true,
|
|
554
|
+
plugins: [transformTypescript],
|
|
555
|
+
configFile: false
|
|
556
|
+
});
|
|
557
|
+
if (!result || !result.ast) {
|
|
558
|
+
throw new Error("Failed to transform JSX");
|
|
559
|
+
}
|
|
560
|
+
return recast.print(result.ast).code;
|
|
561
|
+
};
|
|
562
|
+
|
|
563
|
+
// src/lib/types.ts
|
|
564
|
+
var configSchema = object({
|
|
565
|
+
tsx: boolean(),
|
|
566
|
+
componentDir: string(),
|
|
567
|
+
tailwind: object({
|
|
568
|
+
config: string(),
|
|
569
|
+
css: string()
|
|
570
|
+
}),
|
|
571
|
+
aliases: object({
|
|
572
|
+
path: string()
|
|
573
|
+
})
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
// src/lib/utils.ts
|
|
577
|
+
import { execSync } from "child_process";
|
|
578
|
+
import { readFile } from "fs";
|
|
579
|
+
import { log, spinner } from "@clack/prompts";
|
|
580
|
+
import { detect } from "detect-package-manager";
|
|
581
|
+
function readJsonFile(filePath, callback) {
|
|
582
|
+
readFile(filePath, "utf8", (err, data) => {
|
|
583
|
+
if (err) {
|
|
584
|
+
callback(err, null);
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
try {
|
|
588
|
+
const jsonObject = JSON.parse(data);
|
|
589
|
+
callback(null, jsonObject);
|
|
590
|
+
} catch (parseError) {
|
|
591
|
+
callback(parseError, null);
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
function runCommand(command, message, endMessage) {
|
|
596
|
+
try {
|
|
597
|
+
const indicator = spinner();
|
|
598
|
+
indicator.start(message);
|
|
599
|
+
execSync(command);
|
|
600
|
+
indicator.stop(endMessage ?? "Done");
|
|
601
|
+
} catch (error) {
|
|
602
|
+
log.error(`${error}`);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
function removeExtension(value) {
|
|
606
|
+
const splitWords = value.split(".");
|
|
607
|
+
return splitWords[0];
|
|
608
|
+
}
|
|
609
|
+
async function installPackages(...packages) {
|
|
610
|
+
const packageManager = await detect();
|
|
611
|
+
switch (packageManager) {
|
|
612
|
+
case "yarn":
|
|
613
|
+
case "pnpm":
|
|
614
|
+
runCommand(`${packageManager} add ${packages.join(" ")}`, "Installing dependencies");
|
|
615
|
+
break;
|
|
616
|
+
default:
|
|
617
|
+
runCommand(`${packageManager} install ${packages.join(" ")}`, "Installing dependencies");
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
// src/commands/add.ts
|
|
622
|
+
async function getComponent(componentName) {
|
|
623
|
+
const componentUri = `${registryUIUrl}/${componentName}.json`;
|
|
624
|
+
const res = await (await fetch(componentUri)).json();
|
|
625
|
+
return res;
|
|
626
|
+
}
|
|
627
|
+
async function componentSelectionPrompt() {
|
|
628
|
+
try {
|
|
629
|
+
const componentList = await (await fetch(registryIndexUrl)).json();
|
|
630
|
+
const selectedComponents = await prompts({
|
|
631
|
+
name: "Selected Components",
|
|
632
|
+
type: "multiselect",
|
|
633
|
+
message: "Which components would you like to add?",
|
|
634
|
+
choices: componentList.map((component) => ({ title: component.name, value: component.name }))
|
|
635
|
+
});
|
|
636
|
+
await add(selectedComponents["Selected Components"]);
|
|
637
|
+
} catch (error) {
|
|
638
|
+
log2.info(`Error: ${error}`);
|
|
639
|
+
log2.error("Command terminated.");
|
|
640
|
+
process.exit(1);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
async function add(componentNames) {
|
|
644
|
+
if (componentNames.length === 0)
|
|
645
|
+
await componentSelectionPrompt();
|
|
646
|
+
const activityIndicator = spinner2();
|
|
647
|
+
activityIndicator.start("Creating components...");
|
|
648
|
+
try {
|
|
649
|
+
const readSUCConfig = readFileSync(path.resolve(cwd(), "suc.config.json"));
|
|
650
|
+
const sucConfig = parse(configSchema, JSON.parse(readSUCConfig.toString()));
|
|
651
|
+
const isTypescriptEnabled = sucConfig.tsx;
|
|
652
|
+
const componentFolderDir = path.resolve(cwd(), sucConfig.componentDir);
|
|
653
|
+
const dirExists = existsSync(componentFolderDir);
|
|
654
|
+
if (!dirExists)
|
|
655
|
+
mkdirSync(componentFolderDir, { recursive: true });
|
|
656
|
+
const components = await Promise.all(
|
|
657
|
+
componentNames.map(async (name) => await getComponent(name))
|
|
658
|
+
);
|
|
659
|
+
try {
|
|
660
|
+
for (const component of components) {
|
|
661
|
+
log2.message(`Adding ${component.name} component`);
|
|
662
|
+
if (component.dependencies?.length > 0) {
|
|
663
|
+
log2.step(`Installing ${component.name} component dependencies`);
|
|
664
|
+
await installPackages(...component.dependencies);
|
|
665
|
+
}
|
|
666
|
+
if (component.registryDependencies?.length > 0) {
|
|
667
|
+
log2.step("Installing any other required components");
|
|
668
|
+
await add(component.registryDependencies);
|
|
669
|
+
}
|
|
670
|
+
for (const file of component.files) {
|
|
671
|
+
log2.step(`Creating ${file.name}`);
|
|
672
|
+
const content = transformImports(file.content, sucConfig);
|
|
673
|
+
if (isTypescriptEnabled) {
|
|
674
|
+
writeFileSync(componentFolderDir + `/${file.name}`, content);
|
|
675
|
+
} else {
|
|
676
|
+
writeFileSync(
|
|
677
|
+
componentFolderDir + `/${removeExtension(file.name)}.jsx`,
|
|
678
|
+
transpileTS(content)
|
|
679
|
+
);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
} catch (error) {
|
|
684
|
+
log2.error(`Something went wrong: ${error}`);
|
|
685
|
+
process.exit(1);
|
|
686
|
+
}
|
|
687
|
+
activityIndicator.stop("Successfully created components! \u{1F389}");
|
|
688
|
+
return;
|
|
689
|
+
} catch (error) {
|
|
690
|
+
activityIndicator.stop();
|
|
691
|
+
log2.error(
|
|
692
|
+
`Something went wrong while creating your components. Have you ran ${chalk.green(
|
|
693
|
+
"@solid-ui/cli init"
|
|
694
|
+
)}?`
|
|
695
|
+
);
|
|
696
|
+
process.exit(1);
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
// src/commands/init.ts
|
|
701
|
+
import { existsSync as existsSync2, mkdirSync as mkdirSync2, writeFile, writeFileSync as writeFileSync2 } from "fs";
|
|
702
|
+
import { cwd as cwd2 } from "process";
|
|
703
|
+
import { text, confirm, log as log3, spinner as spinner3, select } from "@clack/prompts";
|
|
704
|
+
async function init() {
|
|
705
|
+
const isTypescript = await confirm({
|
|
706
|
+
message: "Would you like to use TypeScript? (recommended)",
|
|
707
|
+
initialValue: true
|
|
708
|
+
});
|
|
709
|
+
const globalCssDir = await text({
|
|
710
|
+
message: "Where is your global CSS file?",
|
|
711
|
+
initialValue: "src/root.css"
|
|
712
|
+
});
|
|
713
|
+
const tailwindConfigDir = await text({
|
|
714
|
+
message: "Where is your tailwind.config.js located?",
|
|
715
|
+
initialValue: "tailwind.config.cjs"
|
|
716
|
+
});
|
|
717
|
+
const pathAlias = await text({
|
|
718
|
+
message: "Configure the import alias for the src directory:",
|
|
719
|
+
initialValue: "~/*"
|
|
720
|
+
});
|
|
721
|
+
const config = parse(configSchema, {
|
|
722
|
+
tsx: isTypescript,
|
|
723
|
+
componentDir: "./src/components/ui",
|
|
724
|
+
tailwind: {
|
|
725
|
+
config: tailwindConfigDir,
|
|
726
|
+
css: globalCssDir
|
|
727
|
+
},
|
|
728
|
+
aliases: {
|
|
729
|
+
path: pathAlias
|
|
730
|
+
}
|
|
731
|
+
});
|
|
732
|
+
saveConfig(config);
|
|
733
|
+
writeTsconfig(config.aliases.path);
|
|
734
|
+
writeUtils();
|
|
735
|
+
await writeSUCPreset();
|
|
736
|
+
await writeTailwindConfig(config.tailwind.config);
|
|
737
|
+
await writeCSS(config.tailwind.css);
|
|
738
|
+
log3.success("Project configuration completed.");
|
|
739
|
+
await installDeps();
|
|
740
|
+
log3.success(
|
|
741
|
+
"Success! Try 'npx @solid-ui/cli add button' to add a button component to your project"
|
|
742
|
+
);
|
|
743
|
+
process.exit(0);
|
|
744
|
+
}
|
|
745
|
+
function writeUtils() {
|
|
746
|
+
const doesLibPathExist = existsSync2(cwd2() + "/src/lib");
|
|
747
|
+
const indicator = spinner3();
|
|
748
|
+
indicator.start("Creating utils.ts file...");
|
|
749
|
+
if (!doesLibPathExist)
|
|
750
|
+
mkdirSync2(cwd2() + "/src/lib");
|
|
751
|
+
writeFileSync2(cwd2() + "/src/lib/utils.ts", UTILS);
|
|
752
|
+
indicator.stop("Done creating utils.ts file!");
|
|
753
|
+
}
|
|
754
|
+
async function writeCSS(cssPath) {
|
|
755
|
+
const indicator = spinner3();
|
|
756
|
+
indicator.start("Writing CSS styles...");
|
|
757
|
+
writeFile(
|
|
758
|
+
cssPath,
|
|
759
|
+
ROOT_CSS,
|
|
760
|
+
(error) => error && log3.error(error.message || "Something went wrong")
|
|
761
|
+
);
|
|
762
|
+
indicator.stop("Done Writing CSS styles!");
|
|
763
|
+
}
|
|
764
|
+
async function installDeps() {
|
|
765
|
+
const shouldInstallDeps = await confirm({
|
|
766
|
+
message: "Would you like to install the required dependencies? (recommended)",
|
|
767
|
+
initialValue: true
|
|
768
|
+
});
|
|
769
|
+
if (shouldInstallDeps) {
|
|
770
|
+
const packageManager = await select({
|
|
771
|
+
message: "Which package manager would you like to use?",
|
|
772
|
+
options: [
|
|
773
|
+
{ label: "npm", value: "npm" },
|
|
774
|
+
{ label: "yarn", value: "yarn" },
|
|
775
|
+
{ label: "pnpm", value: "pnpm" },
|
|
776
|
+
{ label: "bun", value: "bun" }
|
|
777
|
+
],
|
|
778
|
+
initialValue: "npm"
|
|
779
|
+
});
|
|
780
|
+
runCommand(
|
|
781
|
+
`${packageManager} install ${PROJECT_DEPS.join(" ")}`,
|
|
782
|
+
"Installing Solid UI Component dependencies",
|
|
783
|
+
"Dependencies installed"
|
|
784
|
+
);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
function saveConfig(config) {
|
|
788
|
+
const indicator = spinner3();
|
|
789
|
+
indicator.start("Writing suc.config.json...");
|
|
790
|
+
writeFile("suc.config.json", JSON.stringify(config, null, 2), (error) => {
|
|
791
|
+
if (error)
|
|
792
|
+
log3.error("There was an error while saving your preferences");
|
|
793
|
+
});
|
|
794
|
+
indicator.stop("suc.config.json successfully created!");
|
|
795
|
+
}
|
|
796
|
+
async function writeSUCPreset() {
|
|
797
|
+
const indicator = spinner3();
|
|
798
|
+
indicator.start("Writing Solid UI Components tailwind preset...");
|
|
799
|
+
try {
|
|
800
|
+
writeFile("suc.preset.js", TAILWIND_PRESET, (error) => {
|
|
801
|
+
if (error)
|
|
802
|
+
log3.error(`There was an error while writing the sui.preset.js: ${error}`);
|
|
803
|
+
});
|
|
804
|
+
} catch (error) {
|
|
805
|
+
log3.error(`Sorry, something went wrong while getting the tailwind presets: ${error}`);
|
|
806
|
+
}
|
|
807
|
+
indicator.stop("suc.preset.js successfully created!");
|
|
808
|
+
}
|
|
809
|
+
async function writeTailwindConfig(tailwindConfigDir) {
|
|
810
|
+
const indicator = spinner3();
|
|
811
|
+
indicator.start("Configuring tailwind.config.cjs to support Solid UI Components...");
|
|
812
|
+
writeFile(tailwindConfigDir, TAILWIND_CONFIG, (error) => {
|
|
813
|
+
if (error)
|
|
814
|
+
log3.error(`Something went wrong while writing your tailwind.config.cjs: ${error}`);
|
|
815
|
+
});
|
|
816
|
+
indicator.stop("Done done configuring your tailwind.config.cjs");
|
|
817
|
+
}
|
|
818
|
+
function writeTsconfig(alias) {
|
|
819
|
+
const indicator = spinner3();
|
|
820
|
+
indicator.start("Configuring your tsconfig.json");
|
|
821
|
+
readJsonFile(process.cwd() + "/tsconfig.json", (error, data) => {
|
|
822
|
+
if (error)
|
|
823
|
+
log3.error("Something went wrong while configuring your tsconfig.json");
|
|
824
|
+
const tsconfigData = data;
|
|
825
|
+
if (!tsconfigData.compilerOptions.paths) {
|
|
826
|
+
tsconfigData.compilerOptions.paths = {};
|
|
827
|
+
}
|
|
828
|
+
tsconfigData.compilerOptions.paths[alias] = ["./src/*"];
|
|
829
|
+
writeFile("tsconfig.json", JSON.stringify(tsconfigData, null, 2), (error2) => {
|
|
830
|
+
if (error2)
|
|
831
|
+
log3.error(`Something went wrong while configuring your tsconfig.json: ${error2}`);
|
|
832
|
+
});
|
|
833
|
+
});
|
|
834
|
+
indicator.stop("Done configuring your tsconfig.json");
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
// src/index.ts
|
|
838
|
+
var program = new Command();
|
|
839
|
+
program.name("suc").description("A CLI used for the Solid UI components library").version("0.1");
|
|
840
|
+
program.command("init").description("Initialize and install the necessary things to make use of Solid UI Components").action(async () => await init());
|
|
841
|
+
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));
|
|
842
|
+
program.parse();
|