preskok-ui 0.0.3 → 0.0.5

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 CHANGED
@@ -3,13 +3,13 @@
3
3
  Thin CLI wrapper around shadcn with Preskok registry wiring.
4
4
 
5
5
  ```bash
6
- npx preskok-ui@latest init
7
- npx preskok-ui@latest add button
6
+ npx preskok-ui@latest init button
8
7
  ```
9
8
 
10
- The CLI delegates to `shadcn@latest`. `init` registers Preskok after shadcn setup, and `add` resolves bare component names through the Preskok registry.
9
+ The CLI delegates to `shadcn@latest`. `init` installs the Preskok base and optional components in one pass, and `add` resolves bare component names through the Preskok registry.
11
10
 
12
11
  ```bash
13
12
  npx preskok-ui@latest registry
14
- npx preskok-ui@latest diff
13
+ npx preskok-ui@latest view button
14
+ npx preskok-ui@latest diff button
15
15
  ```
@@ -3,6 +3,7 @@ import { spawnSync } from "node:child_process"
3
3
 
4
4
  const REGISTRY = "@preskok=https://ui-three-mu.vercel.app/r/{name}.json"
5
5
  const DEFAULT_REGISTRY_ITEM = "https://ui-three-mu.vercel.app/r/default.json"
6
+ const CWD_OPTION_VALUES = new Set(["-c", "--cwd"])
6
7
 
7
8
  const args = process.argv.slice(2)
8
9
  const [command, ...commandArgs] = args
@@ -25,7 +26,9 @@ if (command === "add") {
25
26
  }
26
27
 
27
28
  if (command === "init") {
28
- process.exit(runShadcn(["init", DEFAULT_REGISTRY_ITEM, ...commandArgs]))
29
+ process.exit(
30
+ runShadcn(["init", DEFAULT_REGISTRY_ITEM, ...toPreskokInitItems(commandArgs)])
31
+ )
29
32
  }
30
33
 
31
34
  if (command === "registry") {
@@ -34,6 +37,22 @@ if (command === "registry") {
34
37
  process.exit(runShadcn(["registry", "add", REGISTRY, ...registryArgs]))
35
38
  }
36
39
 
40
+ if (command === "view") {
41
+ process.exit(
42
+ runShadcn(["view", ...toPreskokCommandItems(commandArgs, CWD_OPTION_VALUES)])
43
+ )
44
+ }
45
+
46
+ if (command === "diff") {
47
+ process.exit(
48
+ runShadcn([
49
+ "add",
50
+ ...toPreskokCommandItems(commandArgs, CWD_OPTION_VALUES),
51
+ "--diff",
52
+ ])
53
+ )
54
+ }
55
+
37
56
  process.exit(runShadcn(args))
38
57
 
39
58
  function runShadcn(shadcnArgs) {
@@ -58,12 +77,63 @@ function runShadcn(shadcnArgs) {
58
77
  }
59
78
 
60
79
  function toPreskokItems(values) {
80
+ return values.map(toPreskokItem)
81
+ }
82
+
83
+ function toPreskokItem(value) {
84
+ if (value.startsWith("-") || value.startsWith("@") || value.includes("/")) {
85
+ return value
86
+ }
87
+
88
+ return `@preskok/${value.replace(/\.(tsx|ts|jsx|js|json)$/, "")}`
89
+ }
90
+
91
+ function toPreskokCommandItems(values, optionsWithValues) {
92
+ let skipNext = false
93
+
61
94
  return values.map((value) => {
62
- if (value.startsWith("-") || value.startsWith("@") || value.includes("/")) {
95
+ if (skipNext) {
96
+ skipNext = false
97
+ return value
98
+ }
99
+
100
+ if (optionsWithValues.has(value)) {
101
+ skipNext = true
102
+ return value
103
+ }
104
+
105
+ return toPreskokItem(value)
106
+ })
107
+ }
108
+
109
+ function toPreskokInitItems(values) {
110
+ const initOptionsWithValues = new Set([
111
+ "-t",
112
+ "--template",
113
+ "-b",
114
+ "--base",
115
+ "-p",
116
+ "--preset",
117
+ "-c",
118
+ "--cwd",
119
+ "-n",
120
+ "--name",
121
+ ])
122
+
123
+ let skipNext = false
124
+
125
+ return values.map((value) => {
126
+ if (skipNext) {
127
+ skipNext = false
128
+ return value
129
+ }
130
+
131
+ if (initOptionsWithValues.has(value)) {
132
+ skipNext = true
63
133
  return value
64
134
  }
65
135
 
66
- return `@preskok/${value}`
136
+ return toPreskokItems([value])[0]
67
137
  })
68
138
  }
69
139
 
@@ -71,13 +141,14 @@ function printHelp() {
71
141
  console.log(`Usage: preskok-ui <command> [options]
72
142
 
73
143
  Commands:
74
- init run shadcn init and register Preskok
144
+ init [items...] run shadcn init with the Preskok base and optional items
75
145
  add <items...> register Preskok and add items by name
76
146
  registry register the @preskok namespace in components.json
77
147
 
78
148
  Examples:
79
- npx preskok-ui@latest init
149
+ npx preskok-ui@latest init button
80
150
  npx preskok-ui@latest add button
81
- npx preskok-ui@latest diff
151
+ npx preskok-ui@latest view button
152
+ npx preskok-ui@latest diff button
82
153
  npx preskok-ui@latest registry`)
83
154
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "preskok-ui",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "bin": {