dsh-plugin-scaffold-kit 0.1.2 → 0.1.3

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,128 @@
1
1
  # dsh-plugin-scaffold-kit
2
2
 
3
- 一键生成新 **DSH UI 插件**仓库骨架(结构对齐官方 `decoration` 模板)。
3
+ English | [简体中文](./README.zh-CN.md)
4
+
5
+ Scaffold a new **DSH UI plugin** repository in one command: bundle manifest, `cordis.patch.yml`, host/client halves, build script, minimal e2e config and a gate preflight — structure aligned with the official `decoration` template.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm i -D dsh-plugin-scaffold-kit
11
+ # or run it without installing
12
+ npx dsh-plugin-scaffold-kit init --dir ./my-plugin --name dsh-my-plugin
13
+ ```
14
+
15
+ - Node `>= 22.15.0`, DSH `>= 0.2.2-rc.5` (see `engines` in `package.json`).
16
+ - No runtime dependencies.
17
+
18
+ ## Quick start
4
19
 
5
20
  ```bash
6
- dsh-plugin-scaffold-kit init --dir ./my-plugin --name @local/my-plugin [--id my-plugin] [--slot conversation.composer.dock] [--force]
21
+ npx dsh-plugin-scaffold-kit init --dir ./my-plugin --name dsh-my-plugin
22
+ cd my-plugin
23
+ npm install && npm run build
7
24
  ```
8
25
 
9
- 生成内容:
10
- - `package.json`(`exports . / ./client`、`dsh.bundle.patch` + `dsh.client.inject`、`scripts.build`)
11
- - `index.js`(Host 半侧)、`src/client.js`(客户端半侧,`window.__ModuleLoader__.load` + slot 注册)
12
- - `build.mjs`(把 `src/client.js` 复制成 `client.js` 并加 GENERATED 头)
13
- - `cordis.patch.yml`(insert bundle 行)
14
- - `e2e.config.mjs` + `e2e/smoke.spec.mjs`(最小冒烟,接 dsh-plugin-e2e)
15
- - `gate/preflight.mjs`(跨 OS 原生包 preflight)
16
- - `README.md`、`.gitignore`
26
+ Real output:
27
+
28
+ ```text
29
+ scaffold 完成 -> /home/me/my-plugin (bundleId=my-plugin)
30
+ 写入: package.json, index.js, cordis.patch.yml, src/client.js, build.mjs, .gitignore, README.md, e2e.config.mjs, e2e/smoke.spec.mjs, gate/preflight.mjs
31
+
32
+ 下一步:
33
+ cd /home/me/my-plugin
34
+ npm install && npm run build # 生成 client.js
35
+ npx dsh-plugin-publish-check check --dir . # 发布体检
36
+ npx dsh-plugin-e2e run # 跑 e2e(需先 install-browser)
37
+ ```
38
+
39
+ `npm run build` turns `src/client.js` into `client.js` at the package root, which is what the DSH client loader actually loads.
40
+
41
+ ## Usage
42
+
43
+ ```bash
44
+ dsh-plugin-scaffold-kit init [--dir <targetDir>] [--name <pkgName>] [--id <bundleId>] [--slot <slotName>] [--force]
45
+ dsh-plugin-scaffold-kit --help
46
+ ```
47
+
48
+ `init` is the default subcommand, so `dsh-plugin-scaffold-kit --name dsh-x` also scaffolds (into the current directory).
49
+
50
+ ## Options
51
+
52
+ | Option | Default | Meaning |
53
+ |---|---|---|
54
+ | `--dir <dir>` | `.` | Target directory. Created (with parents) if missing. |
55
+ | `--name <pkgName>` | `@local/my-plugin` | Package name written into `package.json`, the `cordis.patch.yml` entry and the generated README title. |
56
+ | `--id <bundleId>` | derived from `--name` | Bundle id used for the patch row id and the client module id. Derived by taking the segment after the last `/` and replacing every character outside `[A-Za-z0-9_-]` with `-` (`@local/my-plugin` → `my-plugin`). |
57
+ | `--slot <slotName>` | `conversation.composer.dock` | Slot the client half registers into. |
58
+ | `--force` | off | Overwrite files that already exist. See [What `--force` actually does](#what---force-actually-does). |
59
+ | `--help`, `-h`, `help` | — | Print usage, exit `0`. |
60
+
61
+ ## What gets generated
62
+
63
+ Ten files, all created with `mkdirSync(..., { recursive: true })` for their parent directories:
64
+
65
+ | File | Contents |
66
+ |---|---|
67
+ | `package.json` | `name`, `version: "0.1.0"`, `private: true`, `license: "MIT"`, `type: "module"`, `exports: { ".": "./index.js", "./client": "./client.js" }`, `files: ["index.js", "client.js", "cordis.patch.yml"]`, `scripts.build: "node build.mjs"`, and `dsh: { bundle: { patch: "./cordis.patch.yml" }, client: { platform: "web", immediately: true, inject: ["@deepseek-ai/dsh-client-ui-conversation"] } }`. |
68
+ | `index.js` | Host half: a one-line `export function apply() {}` with a comment that the client module owns rendering. |
69
+ | `cordis.patch.yml` | `- insert:` with one row: `id: <bundleId>`, `name: '<pkgName>'`. |
70
+ | `src/client.js` | Client half: `window.__ModuleLoader__.load({ id, factory(require) { … } })`, `require('react')`, a `Decoration` component rendering a 48×48 SVG circle, and an `apply(ctx)` that does `ctx.slots.inject('<slot>', () => ctx.slots.register({ name: '<slot>', id, order: 5 }, Decoration))`. |
71
+ | `build.mjs` | No bundler: reads `src/client.js`, writes `client.js` at the package root prefixed with `// GENERATED from src/client.js by build.mjs — do not edit.` |
72
+ | `.gitignore` | `node_modules/`, `.tmp/`, `client.js`, `*.log`. |
73
+ | `README.md` | A Chinese README for the new plugin: dev flow (`npm install` / `npm run build`), where each half lives, optional e2e and gate sections. |
74
+ | `e2e.config.mjs` | `{ plugin: '.', spec: 'e2e/smoke.spec.mjs', out: '.tmp/e2e', channel: 'msedge' }`. |
75
+ | `e2e/smoke.spec.mjs` | Minimal smoke spec: `export default async function ({ h, expect }) { await h.shot('boot'); expect(true, 'boot ok') }` — replace with real assertions. |
76
+ | `gate/preflight.mjs` | Exports `checkNative(dir)`: scans `node_modules` (including `@scope/` children) for `*-<os>-<arch>` native packages built for a different OS and returns their names. Run directly, it prints `[preflight] ok (<platform>)` or the offending names and exits `1`. |
77
+
78
+ The generated `package.json` deliberately has **no** `repository`, `bin` or `publishConfig` — it is `private: true`, so add publishing metadata yourself when you decide to ship.
79
+
80
+ ## API
81
+
82
+ | Export | Signature | Returns |
83
+ |---|---|---|
84
+ | `initScaffold` | `({ dir = '.', name = '@local/my-plugin', id, slot = 'conversation.composer.dock', force = false } = {})` | `{ target, bundleId, written, skipped }` — absolute target path, the resolved bundle id, and the two file lists. Throws when `package.json` exists and `force` is false. |
85
+ | `scaffoldFiles` | `({ name, id, slot })` | `Record<relativePath, fileContents>` — the ten generated files as strings, without touching disk. Useful for previewing or testing. |
86
+
87
+ ```js
88
+ import { initScaffold, scaffoldFiles } from 'dsh-plugin-scaffold-kit'
89
+
90
+ const r = initScaffold({ dir: './my-plugin', name: 'dsh-my-plugin' })
91
+ console.log(r.target, r.bundleId, r.written)
92
+
93
+ // or just look at what would be written
94
+ const files = scaffoldFiles({ name: 'dsh-x', id: 'x', slot: 'conversation.composer.dock' })
95
+ console.log(Object.keys(files))
96
+ ```
97
+
98
+ ## What `--force` actually does
99
+
100
+ `--force` is **all-or-nothing per run, and there are two separate checks**:
101
+
102
+ 1. **`package.json` gate.** If `<dir>/package.json` exists and `--force` is not passed, the whole run aborts before writing anything: `目标已存在 package.json:…(用 --force 覆盖)`, exit `1`. This is the only case where a scaffold refuses to proceed.
103
+ 2. **Per-file skip.** For every other generated file, an existing file is **skipped** (listed in `skipped`) rather than overwritten, and the run still exits `0`.
104
+
105
+ So without `--force`, scaffolding into a directory that already has, say, an `index.js` produces a **partial** scaffold: `package.json` and the rest are written, `index.js` is left untouched and reported as `跳过(已存在): index.js`. With `--force`, every generated file is overwritten — including hand-edited ones — and `skipped` is empty.
106
+
107
+ ## Exit codes
108
+
109
+ | Code | When |
110
+ |---|---|
111
+ | `0` | Scaffold written (files may have been skipped — check the `跳过(已存在)` line). |
112
+ | `1` | `package.json` already exists and `--force` was not passed, or an unexpected error was thrown. |
113
+ | `2` | Unknown subcommand, or an unknown option — any `-…` argument outside `--dir` / `--name` / `--id` / `--slot` / `--force` (`--help` / `-h` are handled earlier and exit `0`). |
114
+
115
+ ## Notes
116
+
117
+ - **Missing option values are not validated.** `--dir` with nothing after it falls back to `--dir`'s default (the current directory) and exits `0`; the same applies to `--name` and `--slot`. Worse, if the next argument is another flag it is **consumed as the value**: `init --dir --force --name x` creates a directory literally named `--force`. Always pass values explicitly.
118
+ - **`--help` wins over anything.** If `--help` or `-h` appears anywhere, or `help` is the first word, usage is printed and the exit code is `0` — even alongside unknown flags. `init help` is *not* a help request: `help` becomes an ignored positional and the scaffold runs normally.
119
+ - **No `--opt=value` form.** `--dir=./x` is rejected as an unknown option (exit `2`); write `--dir ./x`.
120
+ - **Positional arguments after `init` are ignored.** `init whatever --name dsh-x` scaffolds into `.` and never mentions `whatever` — the extra word is not validated.
121
+ - **The generated `client.js` is a placeholder.** It renders a blue circle purely so you can confirm the plugin loads and the slot renders; replace the `Decoration` component and the slot name with your real UI.
122
+ - **`client.js` is gitignored on purpose.** `build.mjs` regenerates it from `src/client.js`; edit the source, not the artifact.
123
+ - **The generated README is in Chinese.** Only that file's language is fixed by the template; rename or rewrite it freely.
124
+ - **It does not install anything.** No `npm install`, no git init, no profile wiring — the "next steps" block it prints is guidance only.
125
+
126
+ ## License
17
127
 
18
- 目标已存在 `package.json` 时需 `--force` 覆盖。生成后:`npm install && npm run build` 生成 `client.js`,再 `dsh-plugin-publish-check check` / `dsh-plugin-e2e run`。
128
+ MIT
@@ -0,0 +1,128 @@
1
+ # dsh-plugin-scaffold-kit
2
+
3
+ [English](./README.md) | 简体中文
4
+
5
+ 一条命令生成新的 **DSH UI 插件**仓库骨架:bundle 清单、`cordis.patch.yml`、Host/Client 两半、构建脚本、最小 e2e 配置、门禁 preflight——结构对齐官方 `decoration` 模板。
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ npm i -D dsh-plugin-scaffold-kit
11
+ # 或直接跑,不安装
12
+ npx dsh-plugin-scaffold-kit init --dir ./my-plugin --name dsh-my-plugin
13
+ ```
14
+
15
+ - Node `>= 22.15.0`,DSH `>= 0.2.2-rc.5`(见 `package.json` 的 `engines`)。
16
+ - 无运行时依赖。
17
+
18
+ ## 快速开始
19
+
20
+ ```bash
21
+ npx dsh-plugin-scaffold-kit init --dir ./my-plugin --name dsh-my-plugin
22
+ cd my-plugin
23
+ npm install && npm run build
24
+ ```
25
+
26
+ 真实输出:
27
+
28
+ ```text
29
+ scaffold 完成 -> /home/me/my-plugin (bundleId=my-plugin)
30
+ 写入: package.json, index.js, cordis.patch.yml, src/client.js, build.mjs, .gitignore, README.md, e2e.config.mjs, e2e/smoke.spec.mjs, gate/preflight.mjs
31
+
32
+ 下一步:
33
+ cd /home/me/my-plugin
34
+ npm install && npm run build # 生成 client.js
35
+ npx dsh-plugin-publish-check check --dir . # 发布体检
36
+ npx dsh-plugin-e2e run # 跑 e2e(需先 install-browser)
37
+ ```
38
+
39
+ `npm run build` 会把 `src/client.js` 变成包根的 `client.js`——DSH 客户端加载器真正读的就是这个文件。
40
+
41
+ ## 用法
42
+
43
+ ```bash
44
+ dsh-plugin-scaffold-kit init [--dir <目标目录>] [--name <包名>] [--id <bundleId>] [--slot <slotName>] [--force]
45
+ dsh-plugin-scaffold-kit --help
46
+ ```
47
+
48
+ `init` 是默认子命令,所以 `dsh-plugin-scaffold-kit --name dsh-x` 也会生成骨架(生成到当前目录)。
49
+
50
+ ## 选项
51
+
52
+ | 选项 | 默认值 | 说明 |
53
+ |---|---|---|
54
+ | `--dir <目录>` | `.` | 目标目录。不存在会连同父目录一起创建。 |
55
+ | `--name <包名>` | `@local/my-plugin` | 包名,写进 `package.json`、`cordis.patch.yml` 的插件行和生成的 README 标题。 |
56
+ | `--id <bundleId>` | 由 `--name` 推导 | bundle id,用于 patch 行 id 与客户端模块 id。推导方式是取最后一个 `/` 之后的段,并把 `[A-Za-z0-9_-]` 之外的字符全换成 `-`(`@local/my-plugin` → `my-plugin`)。 |
57
+ | `--slot <slotName>` | `conversation.composer.dock` | 客户端半侧注册到的 slot。 |
58
+ | `--force` | 关 | 覆盖已存在的文件。具体语义见 [--force 到底做什么](#--force-到底做什么)。 |
59
+ | `--help`、`-h`、`help` | — | 打印用法,退出 `0`。 |
60
+
61
+ ## 生成什么
62
+
63
+ 共 10 个文件,父目录都用 `mkdirSync(..., { recursive: true })` 创建:
64
+
65
+ | 文件 | 内容 |
66
+ |---|---|
67
+ | `package.json` | `name`、`version: "0.1.0"`、`private: true`、`license: "MIT"`、`type: "module"`、`exports: { ".": "./index.js", "./client": "./client.js" }`、`files: ["index.js", "client.js", "cordis.patch.yml"]`、`scripts.build: "node build.mjs"`,以及 `dsh: { bundle: { patch: "./cordis.patch.yml" }, client: { platform: "web", immediately: true, inject: ["@deepseek-ai/dsh-client-ui-conversation"] } }`。 |
68
+ | `index.js` | Host 半侧:一行 `export function apply() {}`,注释说明渲染归 Client 模块管。 |
69
+ | `cordis.patch.yml` | `- insert:` 下一条插件行:`id: <bundleId>`、`name: '<包名>'`。 |
70
+ | `src/client.js` | 客户端半侧:`window.__ModuleLoader__.load({ id, factory(require) { … } })`、`require('react')`、渲染 48×48 SVG 圆形的 `Decoration` 组件,以及 `apply(ctx)` 里的 `ctx.slots.inject('<slot>', () => ctx.slots.register({ name: '<slot>', id, order: 5 }, Decoration))`。 |
71
+ | `build.mjs` | 不打包:读 `src/client.js`,在包根写出 `client.js`,并在开头加 `// GENERATED from src/client.js by build.mjs — do not edit.` |
72
+ | `.gitignore` | `node_modules/`、`.tmp/`、`client.js`、`*.log`。 |
73
+ | `README.md` | 给新插件的中文 README:开发流程(`npm install` / `npm run build`)、两半各在哪、可选的 e2e 与门禁小节。 |
74
+ | `e2e.config.mjs` | `{ plugin: '.', spec: 'e2e/smoke.spec.mjs', out: '.tmp/e2e', channel: 'msedge' }`。 |
75
+ | `e2e/smoke.spec.mjs` | 最小冒烟:`export default async function ({ h, expect }) { await h.shot('boot'); expect(true, 'boot ok') }`——请换成真实断言。 |
76
+ | `gate/preflight.mjs` | 导出 `checkNative(dir)`:扫 `node_modules`(含 `@scope/` 下的子包),找出为另一个 OS 构建的 `*-<os>-<arch>` 原生包并返回其名字。直接运行时打印 `[preflight] ok (<平台>)`,或列出问题包并退出 `1`。 |
77
+
78
+ 生成的 `package.json` **故意不带** `repository`、`bin`、`publishConfig`——它是 `private: true`,等真要发布时自己补发布元数据。
79
+
80
+ ## API
81
+
82
+ | 导出 | 签名 | 返回 |
83
+ |---|---|---|
84
+ | `initScaffold` | `({ dir = '.', name = '@local/my-plugin', id, slot = 'conversation.composer.dock', force = false } = {})` | `{ target, bundleId, written, skipped }`——目标绝对路径、解析出的 bundle id、两个文件清单。`package.json` 已存在且 `force` 为假时抛错。 |
85
+ | `scaffoldFiles` | `({ name, id, slot })` | `Record<相对路径, 文件内容>`——10 个生成文件的字符串,不落盘。适合预览或写测试。 |
86
+
87
+ ```js
88
+ import { initScaffold, scaffoldFiles } from 'dsh-plugin-scaffold-kit'
89
+
90
+ const r = initScaffold({ dir: './my-plugin', name: 'dsh-my-plugin' })
91
+ console.log(r.target, r.bundleId, r.written)
92
+
93
+ // 或者只看会写出什么
94
+ const files = scaffoldFiles({ name: 'dsh-x', id: 'x', slot: 'conversation.composer.dock' })
95
+ console.log(Object.keys(files))
96
+ ```
97
+
98
+ ## --force 到底做什么
99
+
100
+ `--force` 是**按次全有全无,而且是两道独立的闸**:
101
+
102
+ 1. **`package.json` 闸。** `<dir>/package.json` 已存在且没给 `--force` 时,整次运行在写任何文件之前中止:`目标已存在 package.json:…(用 --force 覆盖)`,退出 `1`。这是唯一会让 scaffold 拒绝执行的情况。
103
+ 2. **逐文件跳过。** 其余每个生成文件,若已存在则**跳过**(记入 `skipped`)而不是覆盖,运行仍退出 `0`。
104
+
105
+ 所以不给 `--force` 往一个已经有 `index.js` 的目录里生成,会得到一个**半成品**骨架:`package.json` 等文件被写入,`index.js` 保持原样并报 `跳过(已存在): index.js`。给了 `--force`,每个生成文件都被覆盖——包括手改过的——`skipped` 为空。
106
+
107
+ ## 退出码
108
+
109
+ | 码 | 何时 |
110
+ |---|---|
111
+ | `0` | 骨架已写出(可能有文件被跳过——看 `跳过(已存在)` 那行)。 |
112
+ | `1` | `package.json` 已存在且没给 `--force`,或抛了意外错误。 |
113
+ | `2` | 未知子命令,或未知参数——`--dir` / `--name` / `--id` / `--slot` / `--force` 之外的任何 `-…` 参数(`--help` / `-h` 在更早处处理,退出 `0`)。 |
114
+
115
+ ## 注意事项
116
+
117
+ - **参数缺值不做校验。** `init --dir` 后面什么都不写,会用 `--dir` 的默认值(当前目录)并退出 `0`;`--name`、`--slot` 同理。更糟的是,如果下一个参数本身是开关,它会被**当成值吞掉**:`init --dir --force --name x` 会创建一个名字就叫 `--force` 的目录。请显式传值。
118
+ - **`--help` 优先级最高。** 只要出现 `--help` 或 `-h`,或第一个词就是 `help`,就打印用法并退出 `0`——即使同时带了未知参数。但 `init help` **不是**求帮助:`help` 会变成被忽略的位置参数,骨架照常生成。
119
+ - **不支持 `--opt=value` 写法。** `--dir=./x` 会被当成未知参数(退出 `2`),要写 `--dir ./x`。
120
+ - **`init` 之后的位置参数会被忽略。** `init whatever --name dsh-x` 会把骨架生成到 `.`,且从不提及 `whatever`——那个多余的词不会被校验。
121
+ - **生成的 `client.js` 是占位实现。** 它画一个蓝圆,只为让你确认插件能加载、slot 能渲染;请把 `Decoration` 组件和 slot 名换成你真正的 UI。
122
+ - **`client.js` 是被 `.gitignore` 挡住的。** `build.mjs` 从 `src/client.js` 重新生成它;改源文件,别改产物。
123
+ - **生成的 README 是中文。** 只有这一个文件的语言被模板固定;随便改名或重写。
124
+ - **它不安装任何东西。** 不跑 `npm install`、不 git init、不接 profile——它打印的「下一步」只是提示。
125
+
126
+ ## License
127
+
128
+ MIT
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-scaffold-kit",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,7 +14,8 @@
14
14
  "files": [
15
15
  "bin/",
16
16
  "src/",
17
- "README.md"
17
+ "README.md",
18
+ "README.zh-CN.md"
18
19
  ],
19
20
  "repository": {
20
21
  "type": "git",