dsh-plugin-scaffold-kit 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +127 -2
- package/README.zh-CN.md +128 -0
- package/bin/dsh-plugin-scaffold-kit.mjs +39 -0
- package/package.json +35 -4
- package/src/index.mjs +28 -0
- package/src/templates.mjs +110 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 dsh-plugin-e2e contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,128 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-plugin-scaffold-kit
|
|
2
2
|
|
|
3
|
-
|
|
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
|
|
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
|
+
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
|
|
127
|
+
|
|
128
|
+
MIT
|
package/README.zh-CN.md
ADDED
|
@@ -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
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// dsh-plugin-scaffold-kit:生成新 DSH UI 插件仓库骨架。
|
|
3
|
+
import { initScaffold } from '../src/index.mjs'
|
|
4
|
+
|
|
5
|
+
const args = process.argv.slice(2)
|
|
6
|
+
if (args.includes('--help') || args.includes('-h') || args[0] === 'help') {
|
|
7
|
+
console.log('用法: dsh-plugin-scaffold-kit init [--dir <目标目录>] [--name <包名>] [--id <bundleId>] [--slot <slotName>] [--force]')
|
|
8
|
+
process.exit(0)
|
|
9
|
+
}
|
|
10
|
+
const sub = args[0] && !args[0].startsWith('--') ? args[0] : 'init'
|
|
11
|
+
if (sub !== 'init') {
|
|
12
|
+
console.error('未知子命令: ' + sub + '\n用法: dsh-plugin-scaffold-kit init [--dir <目标目录>] [--name <包名>] [--id <bundleId>] [--slot <slotName>] [--force]')
|
|
13
|
+
process.exit(2)
|
|
14
|
+
}
|
|
15
|
+
const opt = (n, d) => {
|
|
16
|
+
const i = args.indexOf('--' + n)
|
|
17
|
+
return i >= 0 ? args[i + 1] : d
|
|
18
|
+
}
|
|
19
|
+
const known = new Set(['--dir', '--name', '--id', '--slot', '--force'])
|
|
20
|
+
const bad = args.find((a) => a.startsWith('-') && !known.has(a))
|
|
21
|
+
if (bad) {
|
|
22
|
+
console.error('未知参数: ' + bad)
|
|
23
|
+
process.exit(2)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
const r = initScaffold({ dir: opt('dir', '.'), name: opt('name', '@local/my-plugin'), id: opt('id'), slot: opt('slot', 'conversation.composer.dock'), force: args.includes('--force') })
|
|
28
|
+
console.log('scaffold 完成 -> ' + r.target + ' (bundleId=' + r.bundleId + ')')
|
|
29
|
+
console.log('写入: ' + r.written.join(', '))
|
|
30
|
+
if (r.skipped.length) console.log('跳过(已存在): ' + r.skipped.join(', '))
|
|
31
|
+
console.log('\n下一步:')
|
|
32
|
+
console.log(' cd ' + r.target)
|
|
33
|
+
console.log(' npm install && npm run build # 生成 client.js')
|
|
34
|
+
console.log(' npx dsh-plugin-publish-check check --dir . # 发布体检')
|
|
35
|
+
console.log(' npx dsh-plugin-e2e run # 跑 e2e(需先 install-browser)')
|
|
36
|
+
} catch (e) {
|
|
37
|
+
console.error(e.message || String(e))
|
|
38
|
+
process.exit(1)
|
|
39
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-scaffold-kit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"private": false,
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"description": "Scaffold a new DSH UI plugin repo (bundle manifest + cordis.patch + host/client halves + build script + minimal e2e config + gate preflight).",
|
|
8
|
+
"bin": {
|
|
9
|
+
"dsh-plugin-scaffold-kit": "bin/dsh-plugin-scaffold-kit.mjs"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": "./src/index.mjs"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"bin/",
|
|
16
|
+
"src/",
|
|
17
|
+
"README.md",
|
|
18
|
+
"README.zh-CN.md"
|
|
19
|
+
],
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/metal-huang/dsh-devtools.git",
|
|
23
|
+
"directory": "packages/dsh-plugin-scaffold-kit"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public",
|
|
27
|
+
"registry": "https://registry.npmjs.org/"
|
|
28
|
+
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"dsh": ">=0.2.2-rc.5",
|
|
31
|
+
"node": ">=22.15.0"
|
|
32
|
+
},
|
|
33
|
+
"dshTestedOn": [
|
|
34
|
+
"0.2.2-rc.5",
|
|
35
|
+
"0.2.3-alpha.2"
|
|
36
|
+
]
|
|
37
|
+
}
|
package/src/index.mjs
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync, existsSync } from 'node:fs'
|
|
2
|
+
import { dirname, join, resolve } from 'node:path'
|
|
3
|
+
import { scaffoldFiles } from './templates.mjs'
|
|
4
|
+
|
|
5
|
+
export { scaffoldFiles }
|
|
6
|
+
|
|
7
|
+
/** 把骨架写进 targetDir;package.json 已存在时需 force。返回 {written, skipped}。 */
|
|
8
|
+
export function initScaffold({ dir = '.', name = '@local/my-plugin', id, slot = 'conversation.composer.dock', force = false } = {}) {
|
|
9
|
+
const target = resolve(dir)
|
|
10
|
+
if (existsSync(join(target, 'package.json')) && !force) {
|
|
11
|
+
throw new Error(`目标已存在 package.json:${join(target, 'package.json')}(用 --force 覆盖)`)
|
|
12
|
+
}
|
|
13
|
+
const bundleId = id || name.split('/').pop().replace(/[^a-zA-Z0-9_-]/g, '-')
|
|
14
|
+
const files = scaffoldFiles({ name, id: bundleId, slot })
|
|
15
|
+
const written = []
|
|
16
|
+
const skipped = []
|
|
17
|
+
for (const [rel, content] of Object.entries(files)) {
|
|
18
|
+
const p = join(target, rel)
|
|
19
|
+
if (existsSync(p) && !force) {
|
|
20
|
+
skipped.push(rel)
|
|
21
|
+
continue
|
|
22
|
+
}
|
|
23
|
+
mkdirSync(dirname(p), { recursive: true })
|
|
24
|
+
writeFileSync(p, content)
|
|
25
|
+
written.push(rel)
|
|
26
|
+
}
|
|
27
|
+
return { target, bundleId, written, skipped }
|
|
28
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// 生成新 DSH UI 插件仓库的文件集合(基于官方 decoration 模板的结构)。
|
|
2
|
+
export function scaffoldFiles({ name, id, slot }) {
|
|
3
|
+
const pkg = {
|
|
4
|
+
name,
|
|
5
|
+
version: '0.1.0',
|
|
6
|
+
private: true,
|
|
7
|
+
license: 'MIT',
|
|
8
|
+
type: 'module',
|
|
9
|
+
description: `DSH plugin: ${name}`,
|
|
10
|
+
exports: { '.': './index.js', './client': './client.js' },
|
|
11
|
+
files: ['index.js', 'client.js', 'cordis.patch.yml'],
|
|
12
|
+
scripts: { build: 'node build.mjs' },
|
|
13
|
+
dsh: {
|
|
14
|
+
bundle: { patch: './cordis.patch.yml' },
|
|
15
|
+
client: { platform: 'web', immediately: true, inject: ['@deepseek-ai/dsh-client-ui-conversation'] },
|
|
16
|
+
},
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
'package.json': JSON.stringify(pkg, null, 2) + '\n',
|
|
20
|
+
'index.js': `/** Host half of the bundle; the Client module owns rendering. */\nexport function apply() {}\n`,
|
|
21
|
+
'cordis.patch.yml': `- insert:\n - id: ${id}\n name: '${name}'\n`,
|
|
22
|
+
'src/client.js': `window.__ModuleLoader__.load({
|
|
23
|
+
id: '${id}',
|
|
24
|
+
factory(require) {
|
|
25
|
+
const React = require('react')
|
|
26
|
+
const h = React.createElement
|
|
27
|
+
function Decoration() {
|
|
28
|
+
return h('svg', { viewBox: '0 0 64 64', width: 48, height: 48, 'aria-hidden': true, style: { display: 'block', pointerEvents: 'none' } }, h('circle', { cx: 32, cy: 32, r: 24, fill: '#247bbf' }))
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
inject: ['slots'],
|
|
32
|
+
apply(ctx) {
|
|
33
|
+
ctx.slots.inject('${slot}', () => ctx.slots.register({ name: '${slot}', id: '${id}', order: 5 }, Decoration))
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
})
|
|
38
|
+
`,
|
|
39
|
+
'build.mjs': `// 无打包:把可读源 src/client.js 复制到包根 client.js,并加 GENERATED 头。
|
|
40
|
+
import { readFileSync, writeFileSync } from 'node:fs'
|
|
41
|
+
const src = readFileSync(new URL('./src/client.js', import.meta.url), 'utf8')
|
|
42
|
+
const header = '// GENERATED from src/client.js by build.mjs — do not edit.\\n'
|
|
43
|
+
writeFileSync(new URL('./client.js', import.meta.url), header + src)
|
|
44
|
+
console.log('built client.js')
|
|
45
|
+
`,
|
|
46
|
+
'.gitignore': 'node_modules/\n.tmp/\nclient.js\n*.log\n',
|
|
47
|
+
'README.md': `# ${name}
|
|
48
|
+
|
|
49
|
+
DSH UI 插件(由 dsh-plugin-scaffold-kit 生成)。
|
|
50
|
+
|
|
51
|
+
## 开发
|
|
52
|
+
\`\`\`bash
|
|
53
|
+
npm install
|
|
54
|
+
npm run build # 生成 client.js(不要手改)
|
|
55
|
+
# 装进某个 profile(示例,按需):
|
|
56
|
+
# dsh plugin --profile web add <本目录>
|
|
57
|
+
\`\`\`
|
|
58
|
+
- 客户端 UI 在 \`src/client.js\`(改它,然后 \`npm run build\`);Host 半侧在 \`index.js\`;bundle 声明在 \`cordis.patch.yml\` + \`package.json\` 的 \`dsh\` 字段。
|
|
59
|
+
|
|
60
|
+
## E2E(可选)
|
|
61
|
+
\`\`\`bash
|
|
62
|
+
npm i -D dsh-plugin-e2e
|
|
63
|
+
npx dsh-plugin-e2e install-browser
|
|
64
|
+
npx dsh-plugin-e2e run # 读 e2e.config.mjs
|
|
65
|
+
\`\`\`
|
|
66
|
+
|
|
67
|
+
## 门禁(可选)
|
|
68
|
+
\`\`\`bash
|
|
69
|
+
npm i -D dsh-plugin-gate-kit
|
|
70
|
+
npx dsh-plugin-gate-kit preflight
|
|
71
|
+
npx dsh-plugin-gate-kit init # 生成 gate/preflight.mjs
|
|
72
|
+
\`\`\`
|
|
73
|
+
`,
|
|
74
|
+
'e2e.config.mjs': `export default {\n plugin: '.',\n spec: 'e2e/smoke.spec.mjs',\n out: '.tmp/e2e',\n channel: 'msedge',\n}\n`,
|
|
75
|
+
'e2e/smoke.spec.mjs': `// 最小冒烟:先能起实例、能截图即可;按你的插件补真实断言。
|
|
76
|
+
export default async function ({ h, expect }) {
|
|
77
|
+
await h.shot('boot')
|
|
78
|
+
expect(true, 'boot ok')
|
|
79
|
+
}
|
|
80
|
+
`,
|
|
81
|
+
'gate/preflight.mjs': `// 平台原生包 preflight:检测 node_modules 是否被另一个 OS 装过(jscpd 等原生包)。
|
|
82
|
+
import { readdirSync, existsSync } from 'node:fs'
|
|
83
|
+
import { join } from 'node:path'
|
|
84
|
+
import { pathToFileURL } from 'node:url'
|
|
85
|
+
const OS = { win32: 'windows', darwin: 'darwin', linux: 'linux' }[process.platform] || process.platform
|
|
86
|
+
const RE = /^(?:@[^/]+\\/)?[^/]+-(windows|linux|darwin)-(x64|arm64|ia32)(?:-|$)/
|
|
87
|
+
export function checkNative(dir = process.cwd()) {
|
|
88
|
+
const nm = join(dir, 'node_modules')
|
|
89
|
+
if (!existsSync(nm)) return []
|
|
90
|
+
const names = []
|
|
91
|
+
for (const n of readdirSync(nm)) {
|
|
92
|
+
if (n.startsWith('@')) { try { for (const s of readdirSync(join(nm, n))) names.push(n + '/' + s) } catch {} }
|
|
93
|
+
else names.push(n)
|
|
94
|
+
}
|
|
95
|
+
const p = []
|
|
96
|
+
for (const n of names) {
|
|
97
|
+
const b = n.includes('/') ? n.split('/').pop() : n
|
|
98
|
+
const m = RE.exec(b)
|
|
99
|
+
if (m && m[1] !== OS) p.push(n)
|
|
100
|
+
}
|
|
101
|
+
return p
|
|
102
|
+
}
|
|
103
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
104
|
+
const p = checkNative()
|
|
105
|
+
if (p.length) { console.error('[preflight] ' + p.join('; ')); process.exit(1) }
|
|
106
|
+
console.log('[preflight] ok(' + process.platform + ')')
|
|
107
|
+
}
|
|
108
|
+
`,
|
|
109
|
+
}
|
|
110
|
+
}
|