solidui-cli 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +193 -168
  2. package/package.json +2 -1
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import { log as log2, spinner as spinner2 } from "@clack/prompts";
11
11
  import chalk from "chalk";
12
12
  import prompts from "prompts";
13
13
 
14
- // ../../node_modules/.pnpm/valibot@0.21.0/node_modules/valibot/dist/index.js
14
+ // ../../node_modules/.pnpm/valibot@0.28.1/node_modules/valibot/dist/index.js
15
15
  var ValiError = class extends Error {
16
16
  issues;
17
17
  /**
@@ -26,210 +26,254 @@ var ValiError = class extends Error {
26
26
  }
27
27
  };
28
28
  var BrandSymbol = Symbol("brand");
29
- function getIssues(issues) {
30
- return { issues };
31
- }
32
- function getOutput(output) {
33
- return { output };
29
+ function defaultArgs(arg1, arg2) {
30
+ return Array.isArray(arg1) ? [void 0, arg1] : [arg1, arg2];
34
31
  }
35
- function getIssue(info, issue) {
32
+ var store;
33
+ function getGlobalConfig(config) {
36
34
  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
35
+ lang: config?.lang ?? store?.lang,
36
+ message: config?.message,
37
+ abortEarly: config?.abortEarly ?? store?.abortEarly,
38
+ abortPipeEarly: config?.abortPipeEarly ?? store?.abortPipeEarly,
39
+ skipPipe: config?.skipPipe ?? store?.skipPipe
46
40
  };
47
41
  }
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
- };
42
+ var store2;
43
+ function getGlobalMessage(lang) {
44
+ return store2?.get(lang);
56
45
  }
57
- function executePipe(input, pipe, parseInfo, reason) {
58
- if (!pipe || !pipe.length || parseInfo?.skipPipe) {
59
- return getOutput(input);
46
+ var store3;
47
+ function getSchemaMessage(lang) {
48
+ return store3?.get(lang);
49
+ }
50
+ var store4;
51
+ function getSpecificMessage(reference, lang) {
52
+ return store4?.get(reference)?.get(lang);
53
+ }
54
+ function i18n(context, reference, config, issue) {
55
+ const message = context.message ?? getSpecificMessage(reference, issue.lang) ?? (context.type === "type" ? getSchemaMessage(issue.lang) : null) ?? config?.message ?? getGlobalMessage(issue.lang) ?? issue.message;
56
+ return typeof message === "function" ? message(issue) : message;
57
+ }
58
+ function schemaResult(typed, output, issues) {
59
+ return { typed, output, issues };
60
+ }
61
+ function stringify(input) {
62
+ let type = typeof input;
63
+ if (type === "object") {
64
+ type = input ? Object.getPrototypeOf(input).constructor.name : "null";
60
65
  }
61
- let pipeInfo;
62
- let issues;
63
- let output = input;
64
- for (const action of pipe) {
65
- const result = action._parse(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;
66
+ return type === "string" ? `"${input}"` : type === "number" || type === "bigint" || type === "boolean" ? `${input}` : type;
67
+ }
68
+ function pipeIssue(context, config, issue) {
69
+ const received = issue.received ?? stringify(issue.input);
70
+ const schemaIssue2 = {
71
+ reason: context.type,
72
+ context: issue.context.type,
73
+ expected: issue.context.expects,
74
+ received,
75
+ message: `Invalid ${issue.label}: ${issue.context.expects ? `Expected ${issue.context.expects} but r` : "R"}eceived ${received}`,
76
+ input: issue.input,
77
+ requirement: issue.context.requirement,
78
+ path: issue.path,
79
+ lang: config?.lang,
80
+ abortEarly: config?.abortEarly,
81
+ abortPipeEarly: config?.abortPipeEarly,
82
+ skipPipe: config?.skipPipe
83
+ };
84
+ schemaIssue2.message = i18n(
85
+ issue.context,
86
+ issue.reference,
87
+ config,
88
+ schemaIssue2
89
+ );
90
+ return schemaIssue2;
91
+ }
92
+ function pipeResult(context, input, config, issues) {
93
+ if (context.pipe && !config?.skipPipe) {
94
+ for (const action of context.pipe) {
95
+ const result = action._parse(input);
96
+ if (result.issues) {
97
+ for (const actionIssue2 of result.issues) {
98
+ const schemaIssue2 = pipeIssue(context, config, actionIssue2);
99
+ issues ? issues.push(schemaIssue2) : issues = [schemaIssue2];
100
+ }
101
+ if (config?.abortEarly || config?.abortPipeEarly) {
102
+ break;
103
+ }
104
+ } else {
105
+ input = result.output;
74
106
  }
75
- } else {
76
- output = result.output;
77
107
  }
78
108
  }
79
- return issues ? getIssues(issues) : getOutput(output);
80
- }
81
- function getDefaultArgs(arg1, arg2) {
82
- return Array.isArray(arg1) ? [void 0, arg1] : [arg1, arg2];
109
+ return schemaResult(true, input, issues);
83
110
  }
84
- function getErrorMessage(message) {
85
- return typeof message === "function" ? message() : message;
86
- }
87
- function getRestAndDefaultArgs(arg1, arg2, arg3) {
111
+ function restAndDefaultArgs(arg1, arg2, arg3) {
88
112
  if (!arg1 || typeof arg1 === "object" && !Array.isArray(arg1)) {
89
- const [error2, pipe2] = getDefaultArgs(arg2, arg3);
113
+ const [error2, pipe2] = defaultArgs(arg2, arg3);
90
114
  return [arg1, error2, pipe2];
91
115
  }
92
- const [error, pipe] = getDefaultArgs(
116
+ const [error, pipe] = defaultArgs(
93
117
  arg1,
94
118
  arg2
95
119
  );
96
120
  return [void 0, error, pipe];
97
121
  }
98
- function getSchemaIssues(info, reason, validation, message, input, issues) {
99
- return {
100
- issues: [
101
- {
102
- reason,
103
- validation,
104
- origin: info?.origin || "value",
105
- message: getErrorMessage(message),
106
- input,
107
- issues,
108
- abortEarly: info?.abortEarly,
109
- abortPipeEarly: info?.abortPipeEarly,
110
- skipPipe: info?.skipPipe
111
- }
112
- ]
122
+ function schemaIssue(context, reference, input, config, other) {
123
+ const received = stringify(input);
124
+ const expected = other?.expected ?? context.expects;
125
+ const issue = {
126
+ reason: other?.reason ?? "type",
127
+ context: context.type,
128
+ expected,
129
+ received,
130
+ message: `Invalid type: Expected ${expected} but received ${received}`,
131
+ input,
132
+ path: other?.path,
133
+ issues: other?.issues,
134
+ lang: config?.lang,
135
+ abortEarly: config?.abortEarly,
136
+ abortPipeEarly: config?.abortPipeEarly,
137
+ skipPipe: config?.skipPipe
113
138
  };
139
+ issue.message = i18n(context, reference, config, issue);
140
+ return { typed: false, output: input, issues: [issue] };
114
141
  }
115
142
  function boolean(arg1, arg2) {
116
- const [message = "Invalid type", pipe] = getDefaultArgs(arg1, arg2);
143
+ const [message, pipe] = defaultArgs(arg1, arg2);
117
144
  return {
118
145
  type: "boolean",
146
+ expects: "boolean",
119
147
  async: false,
120
148
  message,
121
149
  pipe,
122
- _parse(input, info) {
123
- if (typeof input !== "boolean") {
124
- return getSchemaIssues(info, "type", "boolean", this.message, input);
150
+ _parse(input, config) {
151
+ if (typeof input === "boolean") {
152
+ return pipeResult(this, input, config);
125
153
  }
126
- return executePipe(input, this.pipe, info, "boolean");
154
+ return schemaIssue(this, boolean, input, config);
127
155
  }
128
156
  };
129
157
  }
130
158
  function object(entries, arg2, arg3, arg4) {
131
- const [rest, message = "Invalid type", pipe] = getRestAndDefaultArgs(arg2, arg3, arg4);
159
+ const [rest, message, pipe] = restAndDefaultArgs(arg2, arg3, arg4);
132
160
  let cachedEntries;
133
161
  return {
134
162
  type: "object",
163
+ expects: "Object",
135
164
  async: false,
136
165
  entries,
137
166
  rest,
138
167
  message,
139
168
  pipe,
140
- _parse(input, info) {
141
- if (!input || typeof input !== "object") {
142
- return getSchemaIssues(info, "type", "object", this.message, input);
143
- }
144
- cachedEntries = cachedEntries || Object.entries(this.entries);
145
- let issues;
146
- const output = {};
147
- for (const [key, schema] of cachedEntries) {
148
- const value2 = input[key];
149
- const result = schema._parse(value2, info);
150
- if (result.issues) {
151
- const pathItem = {
152
- type: "object",
153
- input,
154
- key,
155
- value: value2
156
- };
157
- for (const issue of result.issues) {
158
- if (issue.path) {
159
- issue.path.unshift(pathItem);
160
- } else {
161
- issue.path = [pathItem];
169
+ _parse(input, config) {
170
+ if (input && typeof input === "object") {
171
+ cachedEntries = cachedEntries ?? Object.entries(this.entries);
172
+ let typed = true;
173
+ let issues;
174
+ const output = {};
175
+ for (const [key, schema] of cachedEntries) {
176
+ const value2 = input[key];
177
+ const result = schema._parse(value2, config);
178
+ if (result.issues) {
179
+ const pathItem = {
180
+ type: "object",
181
+ origin: "value",
182
+ input,
183
+ key,
184
+ value: value2
185
+ };
186
+ for (const issue of result.issues) {
187
+ if (issue.path) {
188
+ issue.path.unshift(pathItem);
189
+ } else {
190
+ issue.path = [pathItem];
191
+ }
192
+ issues?.push(issue);
193
+ }
194
+ if (!issues) {
195
+ issues = result.issues;
196
+ }
197
+ if (config?.abortEarly) {
198
+ typed = false;
199
+ break;
162
200
  }
163
- issues?.push(issue);
164
201
  }
165
- if (!issues) {
166
- issues = result.issues;
202
+ if (!result.typed) {
203
+ typed = false;
167
204
  }
168
- if (info?.abortEarly) {
169
- break;
205
+ if (result.output !== void 0 || key in input) {
206
+ output[key] = result.output;
170
207
  }
171
- } else if (result.output !== void 0 || key in input) {
172
- output[key] = result.output;
173
208
  }
174
- }
175
- if (this.rest && !(info?.abortEarly && issues)) {
176
- for (const key in input) {
177
- if (!(key in this.entries)) {
178
- const value2 = input[key];
179
- const result = this.rest._parse(value2, info);
180
- if (result.issues) {
181
- const pathItem = {
182
- type: "object",
183
- input,
184
- key,
185
- value: value2
186
- };
187
- for (const issue of result.issues) {
188
- if (issue.path) {
189
- issue.path.unshift(pathItem);
190
- } else {
191
- issue.path = [pathItem];
209
+ if (this.rest && !(config?.abortEarly && issues)) {
210
+ for (const key in input) {
211
+ if (!(key in this.entries)) {
212
+ const value2 = input[key];
213
+ const result = this.rest._parse(value2, config);
214
+ if (result.issues) {
215
+ const pathItem = {
216
+ type: "object",
217
+ origin: "value",
218
+ input,
219
+ key,
220
+ value: value2
221
+ };
222
+ for (const issue of result.issues) {
223
+ if (issue.path) {
224
+ issue.path.unshift(pathItem);
225
+ } else {
226
+ issue.path = [pathItem];
227
+ }
228
+ issues?.push(issue);
229
+ }
230
+ if (!issues) {
231
+ issues = result.issues;
232
+ }
233
+ if (config?.abortEarly) {
234
+ typed = false;
235
+ break;
192
236
  }
193
- issues?.push(issue);
194
- }
195
- if (!issues) {
196
- issues = result.issues;
197
237
  }
198
- if (info?.abortEarly) {
199
- break;
238
+ if (!result.typed) {
239
+ typed = false;
200
240
  }
201
- } else {
202
241
  output[key] = result.output;
203
242
  }
204
243
  }
205
244
  }
245
+ if (typed) {
246
+ return pipeResult(
247
+ this,
248
+ output,
249
+ config,
250
+ issues
251
+ );
252
+ }
253
+ return schemaResult(false, output, issues);
206
254
  }
207
- return issues ? getIssues(issues) : executePipe(
208
- output,
209
- this.pipe,
210
- info,
211
- "object"
212
- );
255
+ return schemaIssue(this, object, input, config);
213
256
  }
214
257
  };
215
258
  }
216
259
  function string(arg1, arg2) {
217
- const [message = "Invalid type", pipe] = getDefaultArgs(arg1, arg2);
260
+ const [message, pipe] = defaultArgs(arg1, arg2);
218
261
  return {
219
262
  type: "string",
263
+ expects: "string",
220
264
  async: false,
221
265
  message,
222
266
  pipe,
223
- _parse(input, info) {
224
- if (typeof input !== "string") {
225
- return getSchemaIssues(info, "type", "string", this.message, input);
267
+ _parse(input, config) {
268
+ if (typeof input === "string") {
269
+ return pipeResult(this, input, config);
226
270
  }
227
- return executePipe(input, this.pipe, info, "string");
271
+ return schemaIssue(this, string, input, config);
228
272
  }
229
273
  };
230
274
  }
231
- function parse(schema, input, info) {
232
- const result = schema._parse(input, info);
275
+ function parse(schema, input, config) {
276
+ const result = schema._parse(input, getGlobalConfig(config));
233
277
  if (result.issues) {
234
278
  throw new ValiError(result.issues);
235
279
  }
@@ -304,6 +348,7 @@ var ROOT_CSS = `@tailwind base;
304
348
  --radius: 0.5rem;
305
349
  }
306
350
 
351
+ .dark,
307
352
  [data-kb-theme="dark"] {
308
353
  --background: 240 10% 3.9%;
309
354
  --foreground: 0 0% 98%;
@@ -367,12 +412,12 @@ var ROOT_CSS = `@tailwind base;
367
412
  @apply px-4;
368
413
  }
369
414
  }`;
370
- var TAILWIND_PRESET = `const {fontFamily} = require("tailwindcss/defaultTheme")
415
+ var TAILWIND_CONFIG = `const {fontFamily} = require("tailwindcss/defaultTheme")
371
416
 
372
417
  /**@type {import("tailwindcss").Config} */
373
418
  module.exports = {
374
419
  darkMode: ["class", '[data-kb-theme="dark"]'],
375
- content: ["./src/**/*.{js,jsx,md,mdx,ts,tsx}"],
420
+ content: ["./src/**/*.{ts,tsx}"],
376
421
  theme: {
377
422
  container: {
378
423
  center: true,
@@ -434,6 +479,7 @@ module.exports = {
434
479
  }
435
480
  },
436
481
  borderRadius: {
482
+ xl: "calc(var(--radius) + 4px)",
437
483
  lg: "var(--radius)",
438
484
  md: "calc(var(--radius) - 2px)",
439
485
  sm: "calc(var(--radius) - 4px)"
@@ -469,14 +515,6 @@ module.exports = {
469
515
  },
470
516
  plugins: [require("tailwindcss-animate")]
471
517
  }`;
472
- var TAILWIND_CONFIG = `/** @type {import('tailwindcss').Config} */
473
- export default {
474
- darkMode: ["class"],
475
- content: [
476
- "./src/**/*.{html,js,jsx,md,mdx,ts,tsx}"
477
- ],
478
- presets: [require("./ui.preset.js")]
479
- }`;
480
518
 
481
519
  // src/lib/transformImports.ts
482
520
  function transformImports(source, config) {
@@ -575,6 +613,7 @@ import { execSync } from "child_process";
575
613
  import { readFile } from "fs";
576
614
  import { log, spinner } from "@clack/prompts";
577
615
  import { detect } from "detect-package-manager";
616
+ import JSON5 from "json5";
578
617
  function readJsonFile(filePath, callback) {
579
618
  readFile(filePath, "utf8", (err, data) => {
580
619
  if (err) {
@@ -582,7 +621,7 @@ function readJsonFile(filePath, callback) {
582
621
  return;
583
622
  }
584
623
  try {
585
- const jsonObject = JSON.parse(data);
624
+ const jsonObject = JSON5.parse(data);
586
625
  callback(null, jsonObject);
587
626
  } catch (parseError) {
588
627
  callback(parseError, null);
@@ -697,7 +736,7 @@ async function add(componentNames) {
697
736
  // src/commands/init.ts
698
737
  import { existsSync as existsSync2, mkdirSync as mkdirSync2, writeFile, writeFileSync as writeFileSync2 } from "fs";
699
738
  import { cwd as cwd2 } from "process";
700
- import { text, confirm, log as log3, spinner as spinner3, select } from "@clack/prompts";
739
+ import { confirm, log as log3, select, spinner as spinner3, text } from "@clack/prompts";
701
740
  async function init() {
702
741
  const isTypescript = await confirm({
703
742
  message: "Would you like to use TypeScript? (recommended)",
@@ -705,7 +744,7 @@ async function init() {
705
744
  });
706
745
  const globalCssDir = await text({
707
746
  message: "Where is your global CSS file?",
708
- initialValue: "src/root.css"
747
+ initialValue: "src/app.css"
709
748
  });
710
749
  const tailwindConfigDir = await text({
711
750
  message: "Where is your tailwind.config.js located?",
@@ -729,7 +768,6 @@ async function init() {
729
768
  saveConfig(config);
730
769
  writeTsconfig(config.aliases.path);
731
770
  writeUtils();
732
- await writeUIPreset();
733
771
  await writeTailwindConfig(config.tailwind.config);
734
772
  await writeCSS(config.tailwind.css);
735
773
  log3.success("Project configuration completed.");
@@ -773,7 +811,7 @@ async function installDeps() {
773
811
  initialValue: "npm"
774
812
  });
775
813
  runCommand(
776
- `${packageManager} install ${PROJECT_DEPS.join(" ")}`,
814
+ `${packageManager} ${packageManager === "yarn" ? "add" : "install"} ${PROJECT_DEPS.join(" ")}`,
777
815
  "Installing Solid UI Component dependencies",
778
816
  "Dependencies installed"
779
817
  );
@@ -788,19 +826,6 @@ function saveConfig(config) {
788
826
  });
789
827
  indicator.stop("ui.config.json successfully created!");
790
828
  }
791
- async function writeUIPreset() {
792
- const indicator = spinner3();
793
- indicator.start("Writing Solid UI Components tailwind preset...");
794
- try {
795
- writeFile("ui.preset.js", TAILWIND_PRESET, (error) => {
796
- if (error)
797
- log3.error(`There was an error while writing the ui.preset.js: ${error}`);
798
- });
799
- } catch (error) {
800
- log3.error(`Sorry, something went wrong while getting the tailwind presets: ${error}`);
801
- }
802
- indicator.stop("ui.preset.js successfully created!");
803
- }
804
829
  async function writeTailwindConfig(tailwindConfigDir) {
805
830
  const indicator = spinner3();
806
831
  indicator.start("Configuring tailwind.config.cjs to support Solid UI Components...");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solidui-cli",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "Add Solid UI Components to your application using the Solid-UI CLI tool",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -43,6 +43,7 @@
43
43
  "chalk": "^5.3.0",
44
44
  "commander": "^11.0.0",
45
45
  "detect-package-manager": "^3.0.1",
46
+ "json5": "^2.2.3",
46
47
  "prompts": "^2.4.2",
47
48
  "recast": "^0.23.4",
48
49
  "ts-morph": "^20.0.0"