dsh-plugin-scaffold-kit 0.0.0-stage → 0.1.2
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 +17 -2
- package/bin/dsh-plugin-scaffold-kit.mjs +39 -0
- package/package.json +34 -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,18 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-plugin-scaffold-kit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
一键生成新 **DSH UI 插件**仓库骨架(结构对齐官方 `decoration` 模板)。
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
dsh-plugin-scaffold-kit init --dir ./my-plugin --name @local/my-plugin [--id my-plugin] [--slot conversation.composer.dock] [--force]
|
|
7
|
+
```
|
|
8
|
+
|
|
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`
|
|
17
|
+
|
|
18
|
+
目标已存在 `package.json` 时需 `--force` 覆盖。生成后:`npm install && npm run build` 生成 `client.js`,再 `dsh-plugin-publish-check check` / `dsh-plugin-e2e run`。
|
|
@@ -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,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-scaffold-kit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.2",
|
|
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
|
+
],
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/metal-huang/dsh-devtools.git",
|
|
22
|
+
"directory": "packages/dsh-plugin-scaffold-kit"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public",
|
|
26
|
+
"registry": "https://registry.npmjs.org/"
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"dsh": ">=0.2.2-rc.5",
|
|
30
|
+
"node": ">=22.15.0"
|
|
31
|
+
},
|
|
32
|
+
"dshTestedOn": [
|
|
33
|
+
"0.2.2-rc.5",
|
|
34
|
+
"0.2.3-alpha.2"
|
|
35
|
+
]
|
|
36
|
+
}
|
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
|
+
}
|