preskok-ui 0.0.5 → 0.0.7
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 +2 -1
- package/bin/preskok-ui.mjs +115 -27
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
Thin CLI wrapper around shadcn with Preskok registry wiring.
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
|
+
npx preskok-ui@latest init
|
|
6
7
|
npx preskok-ui@latest init button
|
|
7
8
|
```
|
|
8
9
|
|
|
9
|
-
The CLI delegates to `shadcn@
|
|
10
|
+
The CLI delegates to `shadcn@4.9.0` by default. Set `PRESKOK_SHADCN_VERSION` to test another shadcn CLI version. Use `init` for new projects, `registry` for existing shadcn projects, and `add` to resolve bare component names through the Preskok registry.
|
|
10
11
|
|
|
11
12
|
```bash
|
|
12
13
|
npx preskok-ui@latest registry
|
package/bin/preskok-ui.mjs
CHANGED
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { spawnSync } from "node:child_process"
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
|
|
4
|
+
const REGISTRY_BASE_URL = (
|
|
5
|
+
process.env.PRESKOK_REGISTRY_URL ?? "https://ui-three-mu.vercel.app"
|
|
6
|
+
).replace(/\/$/, "")
|
|
7
|
+
const SHADCN_VERSION = process.env.PRESKOK_SHADCN_VERSION ?? "4.9.0"
|
|
8
|
+
const REGISTRY = `@preskok=${REGISTRY_BASE_URL}/r/{name}.json`
|
|
9
|
+
const DEFAULT_REGISTRY_ITEM = `${REGISTRY_BASE_URL}/r/default.json`
|
|
6
10
|
const CWD_OPTION_VALUES = new Set(["-c", "--cwd"])
|
|
11
|
+
const ADD_OPTION_VALUES = new Set(["-c", "--cwd", "-p", "--path", "--diff"])
|
|
12
|
+
const INIT_OPTION_VALUES = new Set([
|
|
13
|
+
"-t",
|
|
14
|
+
"--template",
|
|
15
|
+
"-b",
|
|
16
|
+
"--base",
|
|
17
|
+
"-p",
|
|
18
|
+
"--preset",
|
|
19
|
+
"-c",
|
|
20
|
+
"--cwd",
|
|
21
|
+
"-n",
|
|
22
|
+
"--name",
|
|
23
|
+
])
|
|
7
24
|
|
|
8
25
|
const args = process.argv.slice(2)
|
|
9
26
|
const [command, ...commandArgs] = args
|
|
@@ -14,20 +31,57 @@ if (!command || command === "-h" || command === "--help") {
|
|
|
14
31
|
}
|
|
15
32
|
|
|
16
33
|
if (command === "add") {
|
|
17
|
-
const registryStatus = runShadcn([
|
|
34
|
+
const registryStatus = runShadcn([
|
|
35
|
+
"registry",
|
|
36
|
+
"add",
|
|
37
|
+
REGISTRY,
|
|
38
|
+
...getCommandOptions(commandArgs, CWD_OPTION_VALUES),
|
|
39
|
+
])
|
|
18
40
|
|
|
19
41
|
if (registryStatus !== 0) {
|
|
20
42
|
process.exit(registryStatus)
|
|
21
43
|
}
|
|
22
44
|
|
|
23
45
|
process.exit(
|
|
24
|
-
runShadcn([
|
|
46
|
+
runShadcn([
|
|
47
|
+
"add",
|
|
48
|
+
"--yes",
|
|
49
|
+
...toPreskokCommandItems(commandArgs, ADD_OPTION_VALUES),
|
|
50
|
+
])
|
|
25
51
|
)
|
|
26
52
|
}
|
|
27
53
|
|
|
28
54
|
if (command === "init") {
|
|
55
|
+
const { initArgs, items } = splitInitArgs(commandArgs)
|
|
56
|
+
|
|
57
|
+
const initStatus = runShadcn(["init", DEFAULT_REGISTRY_ITEM, ...initArgs])
|
|
58
|
+
|
|
59
|
+
if (initStatus !== 0) {
|
|
60
|
+
process.exit(initStatus)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const registryStatus = runShadcn([
|
|
64
|
+
"registry",
|
|
65
|
+
"add",
|
|
66
|
+
REGISTRY,
|
|
67
|
+
...getCommandOptions(initArgs, CWD_OPTION_VALUES),
|
|
68
|
+
])
|
|
69
|
+
|
|
70
|
+
if (registryStatus !== 0) {
|
|
71
|
+
process.exit(registryStatus)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (items.length === 0) {
|
|
75
|
+
process.exit(0)
|
|
76
|
+
}
|
|
77
|
+
|
|
29
78
|
process.exit(
|
|
30
|
-
runShadcn([
|
|
79
|
+
runShadcn([
|
|
80
|
+
"add",
|
|
81
|
+
"--yes",
|
|
82
|
+
...getCommandOptions(initArgs, CWD_OPTION_VALUES),
|
|
83
|
+
...toPreskokItems(items),
|
|
84
|
+
])
|
|
31
85
|
)
|
|
32
86
|
}
|
|
33
87
|
|
|
@@ -39,7 +93,10 @@ if (command === "registry") {
|
|
|
39
93
|
|
|
40
94
|
if (command === "view") {
|
|
41
95
|
process.exit(
|
|
42
|
-
runShadcn([
|
|
96
|
+
runShadcn([
|
|
97
|
+
"view",
|
|
98
|
+
...toPreskokCommandItems(commandArgs, CWD_OPTION_VALUES),
|
|
99
|
+
])
|
|
43
100
|
)
|
|
44
101
|
}
|
|
45
102
|
|
|
@@ -63,7 +120,7 @@ function runShadcn(shadcnArgs) {
|
|
|
63
120
|
"exec",
|
|
64
121
|
"--yes",
|
|
65
122
|
"--package",
|
|
66
|
-
|
|
123
|
+
`shadcn@${SHADCN_VERSION}`,
|
|
67
124
|
"--",
|
|
68
125
|
"shadcn",
|
|
69
126
|
...shadcnArgs,
|
|
@@ -106,46 +163,77 @@ function toPreskokCommandItems(values, optionsWithValues) {
|
|
|
106
163
|
})
|
|
107
164
|
}
|
|
108
165
|
|
|
109
|
-
function
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
166
|
+
function getCommandOptions(values, optionsWithValues) {
|
|
167
|
+
let skipNext = false
|
|
168
|
+
const options = []
|
|
169
|
+
|
|
170
|
+
for (const value of values) {
|
|
171
|
+
if (skipNext) {
|
|
172
|
+
skipNext = false
|
|
173
|
+
options.push(value)
|
|
174
|
+
continue
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (optionsWithValues.has(value)) {
|
|
178
|
+
skipNext = true
|
|
179
|
+
options.push(value)
|
|
180
|
+
continue
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (hasInlineOptionValue(value, optionsWithValues)) {
|
|
184
|
+
options.push(value)
|
|
185
|
+
}
|
|
186
|
+
}
|
|
122
187
|
|
|
188
|
+
return options
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function splitInitArgs(values) {
|
|
123
192
|
let skipNext = false
|
|
193
|
+
const initArgs = []
|
|
194
|
+
const items = []
|
|
124
195
|
|
|
125
|
-
|
|
196
|
+
for (const value of values) {
|
|
126
197
|
if (skipNext) {
|
|
127
198
|
skipNext = false
|
|
128
|
-
|
|
199
|
+
initArgs.push(value)
|
|
200
|
+
continue
|
|
129
201
|
}
|
|
130
202
|
|
|
131
|
-
if (
|
|
203
|
+
if (INIT_OPTION_VALUES.has(value)) {
|
|
132
204
|
skipNext = true
|
|
133
|
-
|
|
205
|
+
initArgs.push(value)
|
|
206
|
+
continue
|
|
134
207
|
}
|
|
135
208
|
|
|
136
|
-
|
|
137
|
-
|
|
209
|
+
if (
|
|
210
|
+
hasInlineOptionValue(value, INIT_OPTION_VALUES) ||
|
|
211
|
+
value.startsWith("-")
|
|
212
|
+
) {
|
|
213
|
+
initArgs.push(value)
|
|
214
|
+
continue
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
items.push(value)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return { initArgs, items }
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function hasInlineOptionValue(value, options) {
|
|
224
|
+
return [...options].some((option) => value.startsWith(`${option}=`))
|
|
138
225
|
}
|
|
139
226
|
|
|
140
227
|
function printHelp() {
|
|
141
228
|
console.log(`Usage: preskok-ui <command> [options]
|
|
142
229
|
|
|
143
230
|
Commands:
|
|
144
|
-
init [items...] run shadcn init
|
|
231
|
+
init [items...] run shadcn init, register Preskok, and optionally add items
|
|
145
232
|
add <items...> register Preskok and add items by name
|
|
146
233
|
registry register the @preskok namespace in components.json
|
|
147
234
|
|
|
148
235
|
Examples:
|
|
236
|
+
npx preskok-ui@latest init
|
|
149
237
|
npx preskok-ui@latest init button
|
|
150
238
|
npx preskok-ui@latest add button
|
|
151
239
|
npx preskok-ui@latest view button
|