shadcn-nsh 0.1.0 → 0.2.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.
package/README.md CHANGED
@@ -1,18 +1,105 @@
1
1
  # shadcn-nsh
2
2
 
3
+ [中文](./README.zh.md)
4
+
3
5
  CLI for adding styled NSH components (copy-into-app) from the shadcn-nsh registry.
4
6
 
5
7
  ```sh
6
- bunx shadcn-nsh@latest create my-app
7
8
  bunx shadcn-nsh@latest init -c apps/web
8
9
  bunx shadcn-nsh@latest add button
9
10
  ```
10
11
 
11
12
  Default registry: `https://raw.githubusercontent.com/aningdev/shadcn-nsh/main/public/r/{name}.json`.
12
13
 
14
+ ## Commands
15
+
16
+ | Command | What it does |
17
+ | ------------------- | -------------------------------------------------------------------- |
18
+ | `init` | Writes `nsh-ui.json`, installs `theme`, points each `nsh.json` at it |
19
+ | `add [components…]` | Copies items and their `registryDependencies` into the app |
20
+ | `list` | The registry's items, `✓` on the ones the app has |
21
+ | `view <items…>` | The files `add` would write: target paths and contents |
22
+ | `diff [items…]` | The app's files against the registry's; exit code 1 when they differ |
23
+ | `build` | Builds `registry.json` into `public/r` (maintaining this registry) |
24
+ | `serve` | Serves `public/r` over HTTP for local testing |
25
+
26
+ Every command takes `-c, --cwd <dir>` (default: the current directory). `init`, `add`, `list`,
27
+ `view` and `diff` also take `--registry <url>`, a template with `{name}` in it; without it, `add`,
28
+ `list`, `view` and `diff` use the one in `nsh-ui.json`, and `init` uses the public registry.
29
+ `init` also takes `--overwrite` and `-y` (accepted; nothing prompts today).
30
+
31
+ ## add
32
+
33
+ ```sh
34
+ shadcn-nsh add button -c apps/web
35
+ shadcn-nsh add --all
36
+ shadcn-nsh add button --dry-run
37
+ shadcn-nsh add button --overwrite
38
+ ```
39
+
40
+ - A file the app does not have is written; one identical to the registry's is skipped.
41
+ - A file the app changed is kept and reported: `kept components/ui/button.tsx, differs (run diff)`.
42
+ `--overwrite` (`-o`) replaces it and prints the change: `overwrite components/ui/button.tsx (+2 -1)`.
43
+ - `theme.json` is merged by key: the app keeps its colors and gains the tokens it lacks. A
44
+ recolored theme is kept as it is (`kept theme.json (the app's colors stay)`).
45
+ - `--all` (`-a`) adds every `registry:ui` item the catalog lists, dependencies included.
46
+ - `--dry-run` prints the same lines as `would write …` / `would overwrite …` and writes nothing —
47
+ not even `nsh-ui.json` or the theme `init` would install first.
48
+
49
+ ## list, view, diff
50
+
51
+ ```sh
52
+ shadcn-nsh list
53
+ shadcn-nsh list --json
54
+ shadcn-nsh view button
55
+ shadcn-nsh diff
56
+ shadcn-nsh diff button
57
+ ```
58
+
59
+ `list` reads the catalog (`index.json`) and marks an item when any of its files is in the app.
60
+
61
+ `view` prints what `add` would write — dependencies first, at their target paths, with imports
62
+ rewritten for this app — and writes nothing.
63
+
64
+ `diff` compares the same rewritten content with the app's files. Without an item it lists the
65
+ installed items that differ; with one it prints the changed lines. It exits 1 when anything
66
+ differs, so it can gate an update:
67
+
68
+ ```sh
69
+ shadcn-nsh diff || echo "run shadcn-nsh add <item> --overwrite"
70
+ ```
71
+
72
+ Lines are the registry's version against the app's: `-` is a line of the app's file that
73
+ overwriting would drop, `+` one it would add. `theme.json` compares keys, not values — a
74
+ recolored theme is the app's own, and only `add --overwrite` replaces it.
75
+
76
+ ## nsh-ui.json
77
+
78
+ `init` writes it where components install:
79
+
80
+ ```json
81
+ {
82
+ "registry": "https://raw.githubusercontent.com/aningdev/shadcn-nsh/main/public/r/{name}.json",
83
+ "aliases": {
84
+ "components": "./components",
85
+ "ui": "./components/ui",
86
+ "lib": "./lib",
87
+ "theme": "./lib/theme"
88
+ }
89
+ }
90
+ ```
91
+
92
+ In a monorepo (`apps/*` + `packages/ui`) it lives in `packages/ui` and `add -c apps/web`
93
+ installs there.
94
+
13
95
  ## Develop in this monorepo
14
96
 
15
97
  ```sh
16
98
  bun run shadcn-nsh -- --help
17
99
  bun run cli:build
100
+ bun run registry:build # public/r, then e2e against it
101
+ bun run shadcn-nsh -- add button -c apps/web --registry "file://$PWD/public/r/{name}.json"
18
102
  ```
103
+
104
+ `bun test packages/cli` runs the command tests against a temporary app and a `file://` registry
105
+ built from `public/r`.
package/README.zh.md CHANGED
@@ -1,18 +1,100 @@
1
1
  # shadcn-nsh
2
2
 
3
+ [English](./README.md)
4
+
3
5
  从 shadcn-nsh registry 向应用复制 styled NSH 组件的 CLI。
4
6
 
5
7
  ```sh
6
- bunx shadcn-nsh@latest create my-app
7
8
  bunx shadcn-nsh@latest init -c apps/web
8
9
  bunx shadcn-nsh@latest add button
9
10
  ```
10
11
 
11
12
  默认 registry:`https://raw.githubusercontent.com/aningdev/shadcn-nsh/main/public/r/{name}.json`。
12
13
 
14
+ ## 命令
15
+
16
+ | 命令 | 作用 |
17
+ | ------------------- | ---------------------------------------------------------- |
18
+ | `init` | 写 `nsh-ui.json`、装 `theme`、把每个 `nsh.json` 指向它 |
19
+ | `add [components…]` | 复制条目及其 `registryDependencies` |
20
+ | `list` | registry 的全部条目,应用已有的标 `✓` |
21
+ | `view <items…>` | `add` 会写的文件:目标路径与内容 |
22
+ | `diff [items…]` | 对比应用内文件与 registry 的;有差异时退出码 1 |
23
+ | `build` | 把 `registry.json` 构建到 `public/r`(维护本 registry 用) |
24
+ | `serve` | 用 HTTP 提供 `public/r`,本地测试用 |
25
+
26
+ 每个命令都接受 `-c, --cwd <dir>`(默认:当前目录)。`init`、`add`、`list`、`view`、`diff`
27
+ 另接受 `--registry <url>`(含 `{name}` 的模板);省略时 `add`、`list`、`view`、`diff` 用
28
+ `nsh-ui.json` 里的,`init` 用公共 registry。`init` 还接受 `--overwrite` 与 `-y`(接受,当前不弹确认)。
29
+
30
+ ## add
31
+
32
+ ```sh
33
+ shadcn-nsh add button -c apps/web
34
+ shadcn-nsh add --all
35
+ shadcn-nsh add button --dry-run
36
+ shadcn-nsh add button --overwrite
37
+ ```
38
+
39
+ - 应用没有的文件写入;与 registry 相同的跳过。
40
+ - 应用改过的文件保留并报告 `kept components/ui/button.tsx, differs (run diff)`。
41
+ `--overwrite`(`-o`)替换它并打印改动量:`overwrite components/ui/button.tsx (+2 -1)`。
42
+ - `theme.json` 按 key 合并:应用保留自己的颜色,补上缺的 token;改过颜色的主题原样保留
43
+ (`kept theme.json (the app's colors stay)`)。
44
+ - `--all`(`-a`)加全部 `registry:ui` 条目(含依赖)。
45
+ - `--dry-run` 用 `would write …` / `would overwrite …` 打印同样的行,一个字节都不写——
46
+ 包括 `init` 会先写的 `nsh-ui.json` 与主题。
47
+
48
+ ## list、view、diff
49
+
50
+ ```sh
51
+ shadcn-nsh list
52
+ shadcn-nsh list --json
53
+ shadcn-nsh view button
54
+ shadcn-nsh diff
55
+ shadcn-nsh diff button
56
+ ```
57
+
58
+ `list` 读目录(`index.json`),条目任一文件在应用里就标为已装。
59
+
60
+ `view` 打印 `add` 会写的内容:依赖在前、目标路径、import 已按本应用改写;不写文件。
61
+
62
+ `diff` 用同一份改写后的内容与应用里的文件比较。不带条目时列出有差异的已装条目,带条目时
63
+ 打印改动的行。有差异时退出码 1,可以用来卡更新:
64
+
65
+ ```sh
66
+ shadcn-nsh diff || echo "run shadcn-nsh add <item> --overwrite"
67
+ ```
68
+
69
+ 行以 registry 版本对照应用版本:`-` 是覆盖会删掉的应用中的行,`+` 是它会加的行。
70
+ `theme.json` 按 key 比较、不按值——改过颜色的主题是应用自己的,只有 `add --overwrite`
71
+ 会整体替换。
72
+
73
+ ## nsh-ui.json
74
+
75
+ `init` 把它写在组件安装的地方:
76
+
77
+ ```json
78
+ {
79
+ "registry": "https://raw.githubusercontent.com/aningdev/shadcn-nsh/main/public/r/{name}.json",
80
+ "aliases": {
81
+ "components": "./components",
82
+ "ui": "./components/ui",
83
+ "lib": "./lib",
84
+ "theme": "./lib/theme"
85
+ }
86
+ }
87
+ ```
88
+
89
+ monorepo(`apps/*` + `packages/ui`)里它位于 `packages/ui`,`add -c apps/web` 装到那里。
90
+
13
91
  ## 本仓开发
14
92
 
15
93
  ```sh
16
94
  bun run shadcn-nsh -- --help
17
95
  bun run cli:build
96
+ bun run registry:build # 生成 public/r,再用它做端到端
97
+ bun run shadcn-nsh -- add button -c apps/web --registry "file://$PWD/public/r/{name}.json"
18
98
  ```
99
+
100
+ `bun test packages/cli` 用临时应用和由 `public/r` 生成的 `file://` registry 跑命令测试。