preskok-ui 0.0.6 → 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 CHANGED
@@ -7,7 +7,7 @@ npx preskok-ui@latest init
7
7
  npx preskok-ui@latest init button
8
8
  ```
9
9
 
10
- The CLI delegates to `shadcn@latest`. `init` installs the Preskok base for new projects, only registers the Preskok namespace in projects that already have `components.json`, and can add optional components in one pass. `add` resolves bare component names through the Preskok registry.
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.
11
11
 
12
12
  ```bash
13
13
  npx preskok-ui@latest registry
@@ -1,21 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
  import { spawnSync } from "node:child_process"
3
- import { existsSync, readFileSync, unlinkSync, writeFileSync } from "node:fs"
4
- import path from "node:path"
5
3
 
6
4
  const REGISTRY_BASE_URL = (
7
5
  process.env.PRESKOK_REGISTRY_URL ?? "https://ui-three-mu.vercel.app"
8
6
  ).replace(/\/$/, "")
7
+ const SHADCN_VERSION = process.env.PRESKOK_SHADCN_VERSION ?? "4.9.0"
9
8
  const REGISTRY = `@preskok=${REGISTRY_BASE_URL}/r/{name}.json`
10
9
  const DEFAULT_REGISTRY_ITEM = `${REGISTRY_BASE_URL}/r/default.json`
11
10
  const CWD_OPTION_VALUES = new Set(["-c", "--cwd"])
12
11
  const ADD_OPTION_VALUES = new Set(["-c", "--cwd", "-p", "--path", "--diff"])
13
- const DEPENDENCY_SECTIONS = [
14
- "dependencies",
15
- "devDependencies",
16
- "optionalDependencies",
17
- "peerDependencies",
18
- ]
19
12
  const INIT_OPTION_VALUES = new Set([
20
13
  "-t",
21
14
  "--template",
@@ -31,14 +24,6 @@ const INIT_OPTION_VALUES = new Set([
31
24
 
32
25
  const args = process.argv.slice(2)
33
26
  const [command, ...commandArgs] = args
34
- const LOCKFILES = [
35
- "package-lock.json",
36
- "npm-shrinkwrap.json",
37
- "pnpm-lock.yaml",
38
- "yarn.lock",
39
- "bun.lock",
40
- "bun.lockb",
41
- ]
42
27
 
43
28
  if (!command || command === "-h" || command === "--help") {
44
29
  printHelp()
@@ -58,20 +43,21 @@ if (command === "add") {
58
43
  }
59
44
 
60
45
  process.exit(
61
- runPreskokAdd(toPreskokCommandItems(commandArgs, ADD_OPTION_VALUES))
46
+ runShadcn([
47
+ "add",
48
+ "--yes",
49
+ ...toPreskokCommandItems(commandArgs, ADD_OPTION_VALUES),
50
+ ])
62
51
  )
63
52
  }
64
53
 
65
54
  if (command === "init") {
66
55
  const { initArgs, items } = splitInitArgs(commandArgs)
67
- const cwd = getCwd(initArgs)
68
56
 
69
- if (!existsSync(path.join(cwd, "components.json"))) {
70
- const initStatus = runShadcn(["init", DEFAULT_REGISTRY_ITEM, ...initArgs])
57
+ const initStatus = runShadcn(["init", DEFAULT_REGISTRY_ITEM, ...initArgs])
71
58
 
72
- if (initStatus !== 0) {
73
- process.exit(initStatus)
74
- }
59
+ if (initStatus !== 0) {
60
+ process.exit(initStatus)
75
61
  }
76
62
 
77
63
  const registryStatus = runShadcn([
@@ -90,7 +76,9 @@ if (command === "init") {
90
76
  }
91
77
 
92
78
  process.exit(
93
- runPreskokAdd([
79
+ runShadcn([
80
+ "add",
81
+ "--yes",
94
82
  ...getCommandOptions(initArgs, CWD_OPTION_VALUES),
95
83
  ...toPreskokItems(items),
96
84
  ])
@@ -132,7 +120,7 @@ function runShadcn(shadcnArgs) {
132
120
  "exec",
133
121
  "--yes",
134
122
  "--package",
135
- "shadcn@latest",
123
+ `shadcn@${SHADCN_VERSION}`,
136
124
  "--",
137
125
  "shadcn",
138
126
  ...shadcnArgs,
@@ -145,14 +133,6 @@ function runShadcn(shadcnArgs) {
145
133
  return result.status ?? 1
146
134
  }
147
135
 
148
- function runPreskokAdd(addArgs) {
149
- const packageState = capturePackageState(addArgs)
150
- const status = runShadcn(["add", "--yes", ...addArgs])
151
- restorePackageState(packageState)
152
-
153
- return status
154
- }
155
-
156
136
  function toPreskokItems(values) {
157
137
  return values.map(toPreskokItem)
158
138
  }
@@ -240,123 +220,10 @@ function splitInitArgs(values) {
240
220
  return { initArgs, items }
241
221
  }
242
222
 
243
- function getCwd(values) {
244
- for (let index = 0; index < values.length; index++) {
245
- const value = values[index]
246
-
247
- if (value === "-c" || value === "--cwd") {
248
- return path.resolve(values[index + 1] ?? process.cwd())
249
- }
250
-
251
- if (value.startsWith("--cwd=")) {
252
- return path.resolve(value.slice("--cwd=".length))
253
- }
254
- }
255
-
256
- return process.cwd()
257
- }
258
-
259
223
  function hasInlineOptionValue(value, options) {
260
224
  return [...options].some((option) => value.startsWith(`${option}=`))
261
225
  }
262
226
 
263
- function capturePackageState(values) {
264
- const cwd = getCwd(values)
265
- const packageJsonPath = path.join(cwd, "package.json")
266
-
267
- if (!existsSync(packageJsonPath)) {
268
- return null
269
- }
270
-
271
- const packageJsonContent = readFileSync(packageJsonPath, "utf8")
272
- const packageJson = JSON.parse(packageJsonContent)
273
- const lockfiles = new Map()
274
-
275
- for (const lockfile of LOCKFILES) {
276
- const lockfilePath = path.join(cwd, lockfile)
277
-
278
- if (existsSync(lockfilePath)) {
279
- lockfiles.set(lockfile, readFileSync(lockfilePath))
280
- }
281
- }
282
-
283
- return {
284
- cwd,
285
- lockfiles,
286
- packageJson,
287
- packageJsonContent,
288
- packageJsonPath,
289
- }
290
- }
291
-
292
- function restorePackageState(packageState) {
293
- if (!packageState || !existsSync(packageState.packageJsonPath)) {
294
- return
295
- }
296
-
297
- const packageJson = JSON.parse(
298
- readFileSync(packageState.packageJsonPath, "utf8")
299
- )
300
- const beforeDependencyNames = getDependencyNames(packageState.packageJson)
301
- const afterDependencyNames = getDependencyNames(packageJson)
302
- const hasNewDependencies = [...afterDependencyNames].some((dependency) => {
303
- return !beforeDependencyNames.has(dependency)
304
- })
305
-
306
- if (!hasNewDependencies) {
307
- writeFileSync(packageState.packageJsonPath, packageState.packageJsonContent)
308
- restoreLockfiles(packageState)
309
- return
310
- }
311
-
312
- restoreExistingDependencySpecs(packageState.packageJson, packageJson)
313
- writeFileSync(
314
- packageState.packageJsonPath,
315
- `${JSON.stringify(packageJson, null, 2)}\n`
316
- )
317
- }
318
-
319
- function getDependencyNames(packageJson) {
320
- const names = new Set()
321
-
322
- for (const section of DEPENDENCY_SECTIONS) {
323
- for (const dependency of Object.keys(packageJson[section] ?? {})) {
324
- names.add(dependency)
325
- }
326
- }
327
-
328
- return names
329
- }
330
-
331
- function restoreExistingDependencySpecs(sourcePackageJson, targetPackageJson) {
332
- for (const section of DEPENDENCY_SECTIONS) {
333
- const sourceDependencies = sourcePackageJson[section] ?? {}
334
- const targetDependencies = targetPackageJson[section] ?? {}
335
-
336
- for (const [dependency, version] of Object.entries(sourceDependencies)) {
337
- if (targetDependencies[dependency] !== undefined) {
338
- targetDependencies[dependency] = version
339
- }
340
- }
341
- }
342
- }
343
-
344
- function restoreLockfiles(packageState) {
345
- for (const lockfile of LOCKFILES) {
346
- const lockfilePath = path.join(packageState.cwd, lockfile)
347
- const content = packageState.lockfiles.get(lockfile)
348
-
349
- if (content) {
350
- writeFileSync(lockfilePath, content)
351
- continue
352
- }
353
-
354
- if (existsSync(lockfilePath)) {
355
- unlinkSync(lockfilePath)
356
- }
357
- }
358
- }
359
-
360
227
  function printHelp() {
361
228
  console.log(`Usage: preskok-ui <command> [options]
362
229
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "preskok-ui",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "bin": {