shadcn-nsh 0.1.0 → 0.3.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,115 @@
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 a 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`, `-y` (accepted; nothing prompts today) and `--theme <name>`,
30
+ `default` (the library's own) or `shadcn` (shadcn's neutral palette and flat finishes).
31
+
32
+ ## add
33
+
34
+ ```sh
35
+ shadcn-nsh add button -c apps/web
36
+ shadcn-nsh add --all
37
+ shadcn-nsh add button --dry-run
38
+ shadcn-nsh add button --overwrite
39
+ ```
40
+
41
+ - A file the app does not have is written; one identical to the registry's is skipped.
42
+ - A file the app changed is kept and reported: `kept components/ui/button.tsx, differs (run diff)`.
43
+ `--overwrite` (`-o`) replaces it and prints the change: `overwrite components/ui/button.tsx (+2 -1)`.
44
+ - `theme.json` is merged by key: the app keeps its colors and gains the tokens it lacks. A
45
+ recolored theme is kept as it is (`kept theme.json (the app's colors stay)`).
46
+ - `--all` (`-a`) adds every `registry:ui` item the catalog lists, dependencies included.
47
+ - Naming a theme (`add theme-shadcn`, or `add theme` to go back) switches the app's theme: its
48
+ files are written where they differ and `nsh-ui.json`'s `theme` records the new one. Naming the
49
+ theme the app already has is a plain `add`: its colors stay unless `--overwrite`.
50
+ - After that, `theme` as a dependency resolves to the theme the app has, so `add button`,
51
+ `add button --overwrite` and `add --all --overwrite` never write the default theme back.
52
+ - `--dry-run` prints the same lines as `would write …` / `would overwrite …` and writes nothing —
53
+ not even `nsh-ui.json` or the theme `init` would install first.
54
+
55
+ ## list, view, diff
56
+
57
+ ```sh
58
+ shadcn-nsh list
59
+ shadcn-nsh list --json
60
+ shadcn-nsh view button
61
+ shadcn-nsh diff
62
+ shadcn-nsh diff button
63
+ ```
64
+
65
+ `list` reads the catalog (`index.json`) and marks an item when any of its files is in the app.
66
+
67
+ `view` prints what `add` would write — dependencies first, at their target paths, with imports
68
+ rewritten for this app — and writes nothing.
69
+
70
+ `diff` compares the same rewritten content with the app's files. Without an item it lists the
71
+ installed items that differ; with one it prints the changed lines. It exits 1 when anything
72
+ differs, so it can gate an update:
73
+
74
+ ```sh
75
+ shadcn-nsh diff || echo "run shadcn-nsh add <item> --overwrite"
76
+ ```
77
+
78
+ Lines are the registry's version against the app's: `-` is a line of the app's file that
79
+ overwriting would drop, `+` one it would add. `theme.json` compares keys, not values — a
80
+ recolored theme is the app's own, and only `add --overwrite` replaces it.
81
+
82
+ ## nsh-ui.json
83
+
84
+ `init` writes it where components install:
85
+
86
+ ```json
87
+ {
88
+ "registry": "https://raw.githubusercontent.com/aningdev/shadcn-nsh/main/public/r/{name}.json",
89
+ "theme": "theme",
90
+ "aliases": {
91
+ "components": "./components",
92
+ "ui": "./components/ui",
93
+ "lib": "./lib",
94
+ "theme": "./lib/theme"
95
+ }
96
+ }
97
+ ```
98
+
99
+ `theme` is the `registry:theme` item the app installed (`theme`, or `theme-shadcn`); a file
100
+ without it is on `theme`.
101
+
102
+ In a monorepo (`apps/*` + `packages/ui`) it lives in `packages/ui` and `add -c apps/web`
103
+ installs there.
104
+
13
105
  ## Develop in this monorepo
14
106
 
15
107
  ```sh
16
108
  bun run shadcn-nsh -- --help
17
109
  bun run cli:build
110
+ bun run registry:build # public/r, then e2e against it
111
+ bun run shadcn-nsh -- add button -c apps/web --registry "file://$PWD/public/r/{name}.json"
18
112
  ```
113
+
114
+ `bun test packages/cli` runs the command tests against a temporary app and a `file://` registry
115
+ built from `public/r`.
package/README.zh.md CHANGED
@@ -1,18 +1,110 @@
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`、装一个主题、把每个 `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`(接受,当前不弹确认)与 `--theme <name>`:
29
+ `default`(本库自己的主题)或 `shadcn`(shadcn 的 neutral 配色与平面 finish)。
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
+ - 应用没有的文件写入;与 registry 相同的跳过。
41
+ - 应用改过的文件保留并报告 `kept components/ui/button.tsx, differs (run diff)`。
42
+ `--overwrite`(`-o`)替换它并打印改动量:`overwrite components/ui/button.tsx (+2 -1)`。
43
+ - `theme.json` 按 key 合并:应用保留自己的颜色,补上缺的 token;改过颜色的主题原样保留
44
+ (`kept theme.json (the app's colors stay)`)。
45
+ - `--all`(`-a`)加全部 `registry:ui` 条目(含依赖)。
46
+ - 点名一个主题(`add theme-shadcn`,`add theme` 是换回默认)就是换主题:文件写到应用里,
47
+ `nsh-ui.json` 的 `theme` 记下新的那个。点名应用已有的主题只是普通的 `add`:不加 `--overwrite`
48
+ 就保留应用的配色。
49
+ - 此后 `theme` 这个依赖按应用的主题解析,所以 `add button`、`add button --overwrite`、
50
+ `add --all --overwrite` 都不会把默认主题写回来。
51
+ - `--dry-run` 用 `would write …` / `would overwrite …` 打印同样的行,一个字节都不写——
52
+ 包括 `init` 会先写的 `nsh-ui.json` 与主题。
53
+
54
+ ## list、view、diff
55
+
56
+ ```sh
57
+ shadcn-nsh list
58
+ shadcn-nsh list --json
59
+ shadcn-nsh view button
60
+ shadcn-nsh diff
61
+ shadcn-nsh diff button
62
+ ```
63
+
64
+ `list` 读目录(`index.json`),条目任一文件在应用里就标为已装。
65
+
66
+ `view` 打印 `add` 会写的内容:依赖在前、目标路径、import 已按本应用改写;不写文件。
67
+
68
+ `diff` 用同一份改写后的内容与应用里的文件比较。不带条目时列出有差异的已装条目,带条目时
69
+ 打印改动的行。有差异时退出码 1,可以用来卡更新:
70
+
71
+ ```sh
72
+ shadcn-nsh diff || echo "run shadcn-nsh add <item> --overwrite"
73
+ ```
74
+
75
+ 行以 registry 版本对照应用版本:`-` 是覆盖会删掉的应用中的行,`+` 是它会加的行。
76
+ `theme.json` 按 key 比较、不按值——改过颜色的主题是应用自己的,只有 `add --overwrite`
77
+ 会整体替换。
78
+
79
+ ## nsh-ui.json
80
+
81
+ `init` 把它写在组件安装的地方:
82
+
83
+ ```json
84
+ {
85
+ "registry": "https://raw.githubusercontent.com/aningdev/shadcn-nsh/main/public/r/{name}.json",
86
+ "theme": "theme",
87
+ "aliases": {
88
+ "components": "./components",
89
+ "ui": "./components/ui",
90
+ "lib": "./lib",
91
+ "theme": "./lib/theme"
92
+ }
93
+ }
94
+ ```
95
+
96
+ `theme` 是应用装的 `registry:theme` 条目(`theme`,或 `theme-shadcn`);文件里没有它就是
97
+ `theme`。
98
+
99
+ monorepo(`apps/*` + `packages/ui`)里它位于 `packages/ui`,`add -c apps/web` 装到那里。
100
+
13
101
  ## 本仓开发
14
102
 
15
103
  ```sh
16
104
  bun run shadcn-nsh -- --help
17
105
  bun run cli:build
106
+ bun run registry:build # 生成 public/r,再用它做端到端
107
+ bun run shadcn-nsh -- add button -c apps/web --registry "file://$PWD/public/r/{name}.json"
18
108
  ```
109
+
110
+ `bun test packages/cli` 用临时应用和由 `public/r` 生成的 `file://` registry 跑命令测试。