dsh-config-manager 0.1.38 → 0.1.39
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/lib/client.d.ts +0 -65
- package/lib/client.js +105 -918
- package/lib/client.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/market/github-repos.js +2 -2
- package/lib/market/github-repos.js.map +1 -1
- package/lib/ui/i18n.d.ts +0 -10
- package/lib/ui/i18n.js +0 -21
- package/lib/ui/i18n.js.map +1 -1
- package/package.json +1 -1
- package/src/client/market/MarketPanel.tsx +2 -14
- package/src/client/market/market-locales.ts +0 -117
- package/src/index.ts +1 -1
- package/src/market/github-repos.ts +2 -2
- package/src/ui/i18n.ts +0 -21
- package/lib/ui/market-publish.d.ts +0 -129
- package/lib/ui/market-publish.js +0 -168
- package/lib/ui/market-publish.js.map +0 -1
- package/src/client/market/PublishView.tsx +0 -388
- package/src/ui/market-publish.test.ts +0 -219
- package/src/ui/market-publish.ts +0 -256
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* m-market-publish:发布向导纯渲染/校验模型单测(node 可测,零依赖)。
|
|
3
|
-
*
|
|
4
|
-
* 覆盖:5 步模型、repoUrl 轻量校验(可选字段 + http(s) + 无 userinfo)、
|
|
5
|
-
* 表单校验(itemId 过 SAFE_ITEM_ID_RE / name 必填)、git 命令模板渲染、
|
|
6
|
-
* index.json 收录片段(JSON.parse 可过)、步骤状态机(canProceed/nextStepId/prevStepId)。
|
|
7
|
-
*/
|
|
8
|
-
import test from 'node:test'
|
|
9
|
-
import assert from 'node:assert/strict'
|
|
10
|
-
|
|
11
|
-
import { zhUiT, makeUiT } from './i18n.ts'
|
|
12
|
-
import {
|
|
13
|
-
buildGitPushCommands, buildIndexEntrySnippet, canProceed, EMPTY_PUBLISH_FORM,
|
|
14
|
-
INITIAL_PUBLISH_STATE, nextStepId, prevStepId, PUBLISH_STEP_IDS, publishFormValid,
|
|
15
|
-
publishSteps, validatePublishForm, validatePublishRepoUrl,
|
|
16
|
-
} from './market-publish.ts'
|
|
17
|
-
import type { PublishFormFields, PublishProgressState } from './market-publish.ts'
|
|
18
|
-
|
|
19
|
-
/* ---------------------------------------------------------------- 步骤模型 */
|
|
20
|
-
|
|
21
|
-
test('market-publish: publishSteps 5 步且顺序为 select→validate→prepare→push→submit', () => {
|
|
22
|
-
const steps = publishSteps(zhUiT)
|
|
23
|
-
assert.deepEqual(
|
|
24
|
-
steps.map((s) => s.id),
|
|
25
|
-
['select', 'validate', 'prepare', 'push', 'submit'],
|
|
26
|
-
)
|
|
27
|
-
assert.equal(steps.length, 5)
|
|
28
|
-
assert.deepEqual(PUBLISH_STEP_IDS, ['select', 'validate', 'prepare', 'push', 'submit'])
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
test('market-publish: publishSteps 标题走 i18n 字典(zh/en 均渲染,不硬编码)', () => {
|
|
32
|
-
const zh = publishSteps(zhUiT)
|
|
33
|
-
assert.match(zh[0]?.title ?? '', /选择配置包/)
|
|
34
|
-
assert.match(zh[4]?.title ?? '', /提交收录申请/)
|
|
35
|
-
const en = publishSteps(makeUiT('en'))
|
|
36
|
-
assert.match(en[0]?.title ?? '', /Select config package/)
|
|
37
|
-
assert.match(en[4]?.title ?? '', /Submit listing request/)
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
/* ---------------------------------------------------------------- repoUrl 校验 */
|
|
41
|
-
|
|
42
|
-
test('market-publish: validatePublishRepoUrl 可选字段 —— 空串/空白视为未填(合法)', () => {
|
|
43
|
-
assert.equal(validatePublishRepoUrl('', zhUiT), null)
|
|
44
|
-
assert.equal(validatePublishRepoUrl(' ', zhUiT), null)
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
test('market-publish: validatePublishRepoUrl 合法 https/http 通过', () => {
|
|
48
|
-
assert.equal(validatePublishRepoUrl('https://github.com/alice/dsh-items.git', zhUiT), null)
|
|
49
|
-
assert.equal(validatePublishRepoUrl('http://example.com/items.git', zhUiT), null)
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
test('market-publish: validatePublishRepoUrl 非 http(s) 拒绝(git@/ftp 等形态)', () => {
|
|
53
|
-
assert.match(validatePublishRepoUrl('git@github.com:alice/items.git', zhUiT) ?? '', /http\(s\)/)
|
|
54
|
-
assert.match(validatePublishRepoUrl('ftp://example.com/items.git', zhUiT) ?? '', /http\(s\)/)
|
|
55
|
-
assert.match(validatePublishRepoUrl('ssh://git@example.com/items.git', zhUiT) ?? '', /http\(s\)/)
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
test('market-publish: validatePublishRepoUrl 拒绝 userinfo(username:pass@ 与 username@)', () => {
|
|
59
|
-
assert.match(
|
|
60
|
-
validatePublishRepoUrl('https://user:token@github.com/alice/items.git', zhUiT) ?? '',
|
|
61
|
-
/userinfo/,
|
|
62
|
-
)
|
|
63
|
-
assert.match(
|
|
64
|
-
validatePublishRepoUrl('https://user@github.com/alice/items.git', zhUiT) ?? '',
|
|
65
|
-
/userinfo/,
|
|
66
|
-
)
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
test('market-publish: validatePublishRepoUrl 拒绝空白字符', () => {
|
|
70
|
-
assert.match(
|
|
71
|
-
validatePublishRepoUrl('https://github.com/alice/a b.git', zhUiT) ?? '',
|
|
72
|
-
/空白/,
|
|
73
|
-
)
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
/* ---------------------------------------------------------------- 表单校验 */
|
|
77
|
-
|
|
78
|
-
function form(overrides: Partial<PublishFormFields>): PublishFormFields {
|
|
79
|
-
return { ...EMPTY_PUBLISH_FORM, ...overrides }
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
test('market-publish: validatePublishForm 空表单 → itemId/name 错误、repoUrl 合法(可选)', () => {
|
|
83
|
-
const errs = validatePublishForm(EMPTY_PUBLISH_FORM, zhUiT)
|
|
84
|
-
assert.notEqual(errs.itemId, null)
|
|
85
|
-
assert.notEqual(errs.name, null)
|
|
86
|
-
assert.equal(errs.repoUrl, null, 'repoUrl 为空 = 未填 = 合法(可选字段)')
|
|
87
|
-
assert.equal(publishFormValid(errs), false)
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
test('market-publish: validatePublishForm 合法表单 → 全 null、publishFormValid=true', () => {
|
|
91
|
-
const errs = validatePublishForm(
|
|
92
|
-
form({
|
|
93
|
-
itemId: 'my-settings',
|
|
94
|
-
name: '我的设置包',
|
|
95
|
-
repoUrl: 'https://github.com/alice/dsh-items.git',
|
|
96
|
-
}),
|
|
97
|
-
zhUiT,
|
|
98
|
-
)
|
|
99
|
-
assert.deepEqual(errs, { itemId: null, name: null, repoUrl: null })
|
|
100
|
-
assert.equal(publishFormValid(errs), true)
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
test('market-publish: validatePublishForm itemId 过 SAFE_ITEM_ID_RE(合法形态通过)', () => {
|
|
104
|
-
for (const id of ['my-settings', 'My_Settings.1', 'a1', 'settings-v2']) {
|
|
105
|
-
assert.equal(validatePublishForm(form({ itemId: id, name: 'x' }), zhUiT).itemId, null, `${id} 应合法`)
|
|
106
|
-
}
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
test('market-publish: validatePublishForm itemId 非法形态拒绝(路径穿越/空白/斜杠/非 ASCII)', () => {
|
|
110
|
-
for (const id of ['../evil', 'a b', 'a/b', '中文id', '-lead', '.dot', '']) {
|
|
111
|
-
assert.notEqual(validatePublishForm(form({ itemId: id, name: 'x' }), zhUiT).itemId, null, `${JSON.stringify(id)} 应拒绝`)
|
|
112
|
-
}
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
test('market-publish: validatePublishForm name 空白拒绝', () => {
|
|
116
|
-
assert.notEqual(validatePublishForm(form({ itemId: 'ok', name: ' ' }), zhUiT).name, null)
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
/* ---------------------------------------------------------------- git 命令模板 */
|
|
120
|
-
|
|
121
|
-
test('market-publish: buildGitPushCommands 命令序列(clone→cd→mkdir→复制→add→commit→push)', () => {
|
|
122
|
-
const cmds = buildGitPushCommands({
|
|
123
|
-
repoUrl: 'https://github.com/alice/dsh-items.git',
|
|
124
|
-
itemId: 'my-settings',
|
|
125
|
-
dir: 'dsh-items',
|
|
126
|
-
})
|
|
127
|
-
assert.equal(cmds.length, 7)
|
|
128
|
-
assert.equal(cmds[0], 'git clone https://github.com/alice/dsh-items.git dsh-items')
|
|
129
|
-
assert.equal(cmds[1], 'cd dsh-items')
|
|
130
|
-
assert.equal(cmds[2], 'mkdir -p items/my-settings')
|
|
131
|
-
assert.equal(cmds[3], 'cp -r ../dist/items/my-settings/. items/my-settings/')
|
|
132
|
-
assert.equal(cmds[4], 'git add items/my-settings')
|
|
133
|
-
assert.equal(cmds[5], 'git commit -m "publish my-settings"')
|
|
134
|
-
assert.equal(cmds[6], 'git push origin HEAD')
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
test('market-publish: buildGitPushCommands 注入 repoUrl/itemId/dir 且不携带凭据字段', () => {
|
|
138
|
-
const cmds = buildGitPushCommands({
|
|
139
|
-
repoUrl: 'https://github.com/bob/items.git',
|
|
140
|
-
itemId: 'bob-pack',
|
|
141
|
-
dir: 'repo',
|
|
142
|
-
})
|
|
143
|
-
const joined = cmds.join('\n')
|
|
144
|
-
assert.match(joined, /https:\/\/github\.com\/bob\/items\.git/)
|
|
145
|
-
assert.match(joined, /bob-pack/)
|
|
146
|
-
assert.ok(!joined.includes('token') && !joined.includes('@'), '命令模板不应包含任何凭据/用户名')
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
/* ---------------------------------------------------------------- index 收录片段 */
|
|
150
|
-
|
|
151
|
-
test('market-publish: buildIndexEntrySnippet 输出合法 JSON(JSON.parse 可过)且含必填字段', () => {
|
|
152
|
-
const text = buildIndexEntrySnippet({
|
|
153
|
-
id: 'my-settings',
|
|
154
|
-
name: '我的设置包',
|
|
155
|
-
repo: 'https://github.com/alice/dsh-items.git',
|
|
156
|
-
})
|
|
157
|
-
const parsed = JSON.parse(text) as Record<string, unknown>
|
|
158
|
-
assert.equal(parsed['id'], 'my-settings')
|
|
159
|
-
assert.equal(parsed['name'], '我的设置包')
|
|
160
|
-
assert.equal(parsed['repo'], 'https://github.com/alice/dsh-items.git')
|
|
161
|
-
})
|
|
162
|
-
|
|
163
|
-
test('market-publish: buildIndexEntrySnippet 可选字段按填入选入、空白省略', () => {
|
|
164
|
-
const text = buildIndexEntrySnippet({
|
|
165
|
-
id: 'a',
|
|
166
|
-
name: 'x',
|
|
167
|
-
author: 'alice',
|
|
168
|
-
version: '2.0.0',
|
|
169
|
-
updatedAt: '2026-08-19T00:00:00.000Z',
|
|
170
|
-
categories: ['settings', 'plugins'],
|
|
171
|
-
repo: 'https://github.com/alice/items.git',
|
|
172
|
-
description: ' 描述 ',
|
|
173
|
-
})
|
|
174
|
-
const parsed = JSON.parse(text) as Record<string, unknown>
|
|
175
|
-
assert.deepEqual(parsed['categories'], ['settings', 'plugins'])
|
|
176
|
-
assert.equal(parsed['author'], 'alice')
|
|
177
|
-
assert.equal(parsed['description'], '描述', 'description 应 trim')
|
|
178
|
-
assert.equal(parsed['version'], '2.0.0')
|
|
179
|
-
assert.equal(parsed['updatedAt'], '2026-08-19T00:00:00.000Z')
|
|
180
|
-
const minimal = JSON.parse(
|
|
181
|
-
buildIndexEntrySnippet({
|
|
182
|
-
id: 'b',
|
|
183
|
-
name: 'y',
|
|
184
|
-
description: ' ',
|
|
185
|
-
version: '',
|
|
186
|
-
repo: 'https://github.com/alice/items.git',
|
|
187
|
-
}),
|
|
188
|
-
) as Record<string, unknown>
|
|
189
|
-
assert.equal(minimal['description'], undefined, '空白 description 不写入')
|
|
190
|
-
assert.equal(minimal['version'], undefined, '空 version 不写入')
|
|
191
|
-
})
|
|
192
|
-
|
|
193
|
-
/* ---------------------------------------------------------------- 步骤状态机 */
|
|
194
|
-
|
|
195
|
-
test('market-publish: nextStepId/prevStepId 线性导航(端点返回 null)', () => {
|
|
196
|
-
assert.equal(nextStepId('select'), 'validate')
|
|
197
|
-
assert.equal(nextStepId('validate'), 'prepare')
|
|
198
|
-
assert.equal(nextStepId('prepare'), 'push')
|
|
199
|
-
assert.equal(nextStepId('push'), 'submit')
|
|
200
|
-
assert.equal(nextStepId('submit'), null)
|
|
201
|
-
assert.equal(prevStepId('submit'), 'push')
|
|
202
|
-
assert.equal(prevStepId('select'), null)
|
|
203
|
-
})
|
|
204
|
-
|
|
205
|
-
test('market-publish: canProceed 按进度标记门控(select 须选 zip / validate 须过校验 / prepare 须已生成)', () => {
|
|
206
|
-
assert.equal(canProceed({ ...INITIAL_PUBLISH_STATE, step: 'select', zipSelected: false }), false)
|
|
207
|
-
assert.equal(canProceed({ ...INITIAL_PUBLISH_STATE, step: 'select', zipSelected: true }), true)
|
|
208
|
-
assert.equal(canProceed({ ...INITIAL_PUBLISH_STATE, step: 'validate', validated: false }), false)
|
|
209
|
-
assert.equal(canProceed({ ...INITIAL_PUBLISH_STATE, step: 'validate', validated: true }), true)
|
|
210
|
-
assert.equal(canProceed({ ...INITIAL_PUBLISH_STATE, step: 'prepare', prepared: false }), false)
|
|
211
|
-
assert.equal(canProceed({ ...INITIAL_PUBLISH_STATE, step: 'prepare', prepared: true }), true)
|
|
212
|
-
})
|
|
213
|
-
|
|
214
|
-
test('market-publish: canProceed push 默认可前进(引导页无硬性前置)、submit 恒 false', () => {
|
|
215
|
-
const push: PublishProgressState = { ...INITIAL_PUBLISH_STATE, step: 'push' }
|
|
216
|
-
assert.equal(canProceed(push), true)
|
|
217
|
-
const submit: PublishProgressState = { ...INITIAL_PUBLISH_STATE, step: 'submit' }
|
|
218
|
-
assert.equal(canProceed(submit), false)
|
|
219
|
-
})
|
package/src/ui/market-publish.ts
DELETED
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 配置市场「发布到市场」向导的框架无关渲染/校验模型(m-market-publish,node 可测)。
|
|
3
|
-
*
|
|
4
|
-
* 设计纪律(docs/design/2026-08-19-market-publish-design.md §3.4):
|
|
5
|
-
* - 全部无副作用纯函数,React 壳(PublishView)只装配,不承载业务逻辑;
|
|
6
|
-
* - 5 步流程:选择配置包 → 本地校验 → 生成条目包 → 推送作者仓库 → 提交收录申请;
|
|
7
|
-
* - 状态组件内自持(同 MarketPanel 策略,不进 sessionStorage)。
|
|
8
|
-
*
|
|
9
|
-
* 安全硬约束(与安全不变量同款):
|
|
10
|
-
* - itemId 须过 SAFE_ITEM_ID_RE(防 items/<id>/ 路径越界,assertSafeItemId 同源正则);
|
|
11
|
-
* - repoUrl 可选但若填必须为 http(s) 且无 userinfo(轻量等价实现 sync validateRepoUrl 的
|
|
12
|
-
* 语义,不 import node 模块、浏览器/node 双端可跑;凭据永不拼入 URL);
|
|
13
|
-
* - 本层只生成 git 命令模板与 index.json 收录片段**文本**,不做任何 git 写操作、
|
|
14
|
-
* 不持有凭据(与 About 页「Star 由用户在 GitHub 完成」同款产品纪律);
|
|
15
|
-
* - 内容校验(zip 加固解包 / containsSecrets / SHA-256)在 Host 侧 prepare 端点,本层不管。
|
|
16
|
-
*/
|
|
17
|
-
import { zhUiT, type UiT } from './i18n.ts'
|
|
18
|
-
import { SAFE_ITEM_ID_RE } from '../market/types.ts'
|
|
19
|
-
|
|
20
|
-
/* ---------------------------------------------------------------- 步骤模型 */
|
|
21
|
-
|
|
22
|
-
/** 发布向导 5 步(设计文档 §3.4:选择配置包 / 本地校验 / 生成条目包 / 推送作者仓库 / 提交收录申请) */
|
|
23
|
-
export const PUBLISH_STEP_IDS = ['select', 'validate', 'prepare', 'push', 'submit'] as const
|
|
24
|
-
export type PublishStepId = (typeof PUBLISH_STEP_IDS)[number]
|
|
25
|
-
|
|
26
|
-
/** 发布向导步骤信息(标题已翻译;React 壳只渲染)。 */
|
|
27
|
-
export interface PublishStepInfo {
|
|
28
|
-
id: PublishStepId
|
|
29
|
-
/** 步骤标题(经 UiT 翻译) */
|
|
30
|
-
title: string
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** 5 步模型(顺序即流程;文案走 i18n 字典,不硬编码中文)。 */
|
|
34
|
-
export function publishSteps(t: UiT = zhUiT): PublishStepInfo[] {
|
|
35
|
-
return [
|
|
36
|
-
{ id: 'select', title: t('marketPublish.stepSelect') },
|
|
37
|
-
{ id: 'validate', title: t('marketPublish.stepValidate') },
|
|
38
|
-
{ id: 'prepare', title: t('marketPublish.stepPrepare') },
|
|
39
|
-
{ id: 'push', title: t('marketPublish.stepPush') },
|
|
40
|
-
{ id: 'submit', title: t('marketPublish.stepSubmit') },
|
|
41
|
-
]
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/* ---------------------------------------------------------------- 字段校验 */
|
|
45
|
-
|
|
46
|
-
/** 发布向导表单字段(用户填写;全部纯字符串,UI 按需组装)。 */
|
|
47
|
-
export interface PublishFormFields {
|
|
48
|
-
/** 条目 id(须过 SAFE_ITEM_ID_RE:字母数字开头,仅 . _ -,最长 128) */
|
|
49
|
-
itemId: string
|
|
50
|
-
/** 条目标题(必填非空) */
|
|
51
|
-
name: string
|
|
52
|
-
/** 条目版本(展示用;空则由 Host prepare 缺省 '1.0.0') */
|
|
53
|
-
version: string
|
|
54
|
-
description: string
|
|
55
|
-
author: string
|
|
56
|
-
/** 类别(逗号分隔文本;UI 解析为数组,空串 = 无类别) */
|
|
57
|
-
categories: string
|
|
58
|
-
/** 作者托管仓库 URL(**可选**;非空须 http(s) 且无 userinfo,凭据绝不拼入) */
|
|
59
|
-
repoUrl: string
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** 空表单初值(React 壳 useState 初始 + 测试用)。 */
|
|
63
|
-
export const EMPTY_PUBLISH_FORM: PublishFormFields = {
|
|
64
|
-
itemId: '',
|
|
65
|
-
name: '',
|
|
66
|
-
version: '',
|
|
67
|
-
description: '',
|
|
68
|
-
author: '',
|
|
69
|
-
categories: '',
|
|
70
|
-
repoUrl: '',
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/** 表单字段错误(null = 该字段合法;文案已翻译)。 */
|
|
74
|
-
export interface PublishFieldErrors {
|
|
75
|
-
itemId: string | null
|
|
76
|
-
name: string | null
|
|
77
|
-
repoUrl: string | null
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* 发布仓库 URL 合法性校验(返回错误消息;null = 合法)。
|
|
82
|
-
* **可选字段**:空串/空白视为「未填」= 合法;非空须:
|
|
83
|
-
* - 不含空白字符(\s);
|
|
84
|
-
* - http(s) 开头(拒绝 git@ / ssh / ftp 等非 http(s) 形态,市场仓库只走 https clone);
|
|
85
|
-
* - authority 段不含 userinfo(`user[:password]@host`),凭据必须走 DSH credentials。
|
|
86
|
-
* 语义与 sync 的 validateRepoUrl 对齐(拒绝 userinfo / 空白),另按市场设计补强「非 http(s) 拒绝」。
|
|
87
|
-
*/
|
|
88
|
-
export function validatePublishRepoUrl(repoUrl: string, t: UiT = zhUiT): string | null {
|
|
89
|
-
if (typeof repoUrl !== 'string' || repoUrl.trim() === '') {
|
|
90
|
-
return null // 可选字段:未填 = 合法
|
|
91
|
-
}
|
|
92
|
-
const url = repoUrl.trim()
|
|
93
|
-
if (/\s/.test(url)) {
|
|
94
|
-
return t('marketPublish.repoWhitespace')
|
|
95
|
-
}
|
|
96
|
-
if (!/^https?:\/\//i.test(url)) {
|
|
97
|
-
return t('marketPublish.repoScheme')
|
|
98
|
-
}
|
|
99
|
-
const authority = url.replace(/^https?:\/\//i, '').split(/[/?#]/)[0] ?? ''
|
|
100
|
-
if (authority.includes('@')) {
|
|
101
|
-
return t('marketPublish.repoUserinfo')
|
|
102
|
-
}
|
|
103
|
-
return null
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/** 表单校验:itemId(SAFE_ITEM_ID_RE)+ name 必填 + repoUrl 可选校验。返回逐字段错误。 */
|
|
107
|
-
export function validatePublishForm(form: PublishFormFields, t: UiT = zhUiT): PublishFieldErrors {
|
|
108
|
-
const errors: PublishFieldErrors = { itemId: null, name: null, repoUrl: null }
|
|
109
|
-
if (!SAFE_ITEM_ID_RE.test(form.itemId)) {
|
|
110
|
-
errors.itemId = t('marketPublish.errorItemId')
|
|
111
|
-
}
|
|
112
|
-
if (form.name.trim() === '') {
|
|
113
|
-
errors.name = t('marketPublish.errorName')
|
|
114
|
-
}
|
|
115
|
-
const repoErr = validatePublishRepoUrl(form.repoUrl, t)
|
|
116
|
-
if (repoErr !== null) errors.repoUrl = repoErr
|
|
117
|
-
return errors
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/** 表单是否全部合法(generate 按钮可用性 / canProceed 的 prepare 前置)。 */
|
|
121
|
-
export function publishFormValid(errors: PublishFieldErrors): boolean {
|
|
122
|
-
return errors.itemId === null && errors.name === null && errors.repoUrl === null
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/* ---------------------------------------------------------------- git 命令模板 */
|
|
126
|
-
|
|
127
|
-
export interface GitPushCommandsInput {
|
|
128
|
-
/** 作者公开仓库 URL(调用方应先过 validatePublishRepoUrl;本函数不再校验,纯模板渲染) */
|
|
129
|
-
repoUrl: string
|
|
130
|
-
/** 条目 id(调用方应先过 SAFE_ITEM_ID_RE;本函数不再校验) */
|
|
131
|
-
itemId: string
|
|
132
|
-
/** git clone 目标目录名(本地工作目录) */
|
|
133
|
-
dir: string
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* 生成「推送到作者仓库」的 git 命令模板(用户在**自己的公开仓库**里执行;
|
|
138
|
-
* 插件不做任何 git 写操作、不持有凭据)。
|
|
139
|
-
*
|
|
140
|
-
* 语义:clone 空仓库 → 进入 → 建 items/<id>/ → 从发布目录复制条目文件
|
|
141
|
-
* (prepare 产物解压为 `dist/`,含 dist/items/<id>/manifest.json + config.zip)→
|
|
142
|
-
* add → commit → push。
|
|
143
|
-
*/
|
|
144
|
-
export function buildGitPushCommands(input: GitPushCommandsInput): string[] {
|
|
145
|
-
const { repoUrl, itemId, dir } = input
|
|
146
|
-
return [
|
|
147
|
-
`git clone ${repoUrl} ${dir}`,
|
|
148
|
-
`cd ${dir}`,
|
|
149
|
-
`mkdir -p items/${itemId}`,
|
|
150
|
-
`cp -r ../dist/items/${itemId}/. items/${itemId}/`,
|
|
151
|
-
`git add items/${itemId}`,
|
|
152
|
-
`git commit -m "publish ${itemId}"`,
|
|
153
|
-
`git push origin HEAD`,
|
|
154
|
-
]
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/* ---------------------------------------------------------------- index 收录片段 */
|
|
158
|
-
|
|
159
|
-
export interface IndexEntrySnippetInput {
|
|
160
|
-
/** 条目 id(须已过 SAFE_ITEM_ID_RE) */
|
|
161
|
-
id: string
|
|
162
|
-
/** 条目标题(必填) */
|
|
163
|
-
name: string
|
|
164
|
-
description?: string
|
|
165
|
-
author?: string
|
|
166
|
-
version?: string
|
|
167
|
-
/** ISO-8601 时间(可选;缺省不写入) */
|
|
168
|
-
updatedAt?: string
|
|
169
|
-
categories?: string[]
|
|
170
|
-
/** 作者托管仓库 URL(收录引用必填;UI 传 form.repoUrl,未填时给出提示) */
|
|
171
|
-
repo: string
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* 生成「提交收录申请」(PR)时追加进官方 index.json `items[]` 的条目片段
|
|
176
|
-
* (pretty JSON 文本,`JSON.parse` 可直接通过;可选字段空值不写入)。
|
|
177
|
-
* 字段形状与 src/market/index-parser.ts 的白名单解析面一致。
|
|
178
|
-
*/
|
|
179
|
-
export function buildIndexEntrySnippet(item: IndexEntrySnippetInput): string {
|
|
180
|
-
const entry: Record<string, string | string[] | undefined> = {
|
|
181
|
-
id: item.id,
|
|
182
|
-
name: item.name,
|
|
183
|
-
}
|
|
184
|
-
if (item.description !== undefined && item.description.trim() !== '') {
|
|
185
|
-
entry.description = item.description.trim()
|
|
186
|
-
}
|
|
187
|
-
if (item.author !== undefined && item.author.trim() !== '') {
|
|
188
|
-
entry.author = item.author.trim()
|
|
189
|
-
}
|
|
190
|
-
if (item.version !== undefined && item.version.trim() !== '') {
|
|
191
|
-
entry.version = item.version.trim()
|
|
192
|
-
}
|
|
193
|
-
if (item.updatedAt !== undefined && item.updatedAt.trim() !== '') {
|
|
194
|
-
entry.updatedAt = item.updatedAt.trim()
|
|
195
|
-
}
|
|
196
|
-
if (item.categories !== undefined && item.categories.length > 0) {
|
|
197
|
-
entry.categories = item.categories
|
|
198
|
-
}
|
|
199
|
-
entry.repo = item.repo
|
|
200
|
-
return JSON.stringify(entry, null, 2)
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/* ---------------------------------------------------------------- 步骤状态机 */
|
|
204
|
-
|
|
205
|
-
/** 发布向导进度状态(组件内自持;纯函数推导导航)。 */
|
|
206
|
-
export interface PublishProgressState {
|
|
207
|
-
/** 当前步骤 */
|
|
208
|
-
step: PublishStepId
|
|
209
|
-
/** 步骤 1 完成:已选择配置 zip */
|
|
210
|
-
zipSelected: boolean
|
|
211
|
-
/** 步骤 2 完成:本地校验通过(dry-run 合法 + 无 secrets) */
|
|
212
|
-
validated: boolean
|
|
213
|
-
/** 步骤 3 完成:条目包已生成(prepare 结果就绪) */
|
|
214
|
-
prepared: boolean
|
|
215
|
-
/** 步骤 4 完成:用户已确认推送指引(可选标记,不阻塞前进) */
|
|
216
|
-
pushAcknowledged: boolean
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/** 初值(进入发布向导时的状态)。 */
|
|
220
|
-
export const INITIAL_PUBLISH_STATE: PublishProgressState = {
|
|
221
|
-
step: 'select',
|
|
222
|
-
zipSelected: false,
|
|
223
|
-
validated: false,
|
|
224
|
-
prepared: false,
|
|
225
|
-
pushAcknowledged: false,
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* 当前步骤是否可前进到下一步(纯函数推导,React 壳只装配):
|
|
230
|
-
* - `select` :须已选择配置 zip(zipSelected);
|
|
231
|
-
* - `validate`:须本地校验通过(validated,dry-run 合法 + 无 secrets);
|
|
232
|
-
* - `prepare` :须条目包已生成(prepared,含表单校验通过——生成动作本身以 publishFormValid 为前提);
|
|
233
|
-
* - `push` :引导页无硬性前置(复制命令即可前进到收录申请);
|
|
234
|
-
* - `submit` :最后一步,不可再前进。
|
|
235
|
-
*/
|
|
236
|
-
export function canProceed(state: PublishProgressState): boolean {
|
|
237
|
-
switch (state.step) {
|
|
238
|
-
case 'select': return state.zipSelected
|
|
239
|
-
case 'validate': return state.validated
|
|
240
|
-
case 'prepare': return state.prepared
|
|
241
|
-
case 'push': return true
|
|
242
|
-
case 'submit': return false
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/** 线性下一步(最后一步返回 null)。 */
|
|
247
|
-
export function nextStepId(step: PublishStepId): PublishStepId | null {
|
|
248
|
-
const i = PUBLISH_STEP_IDS.indexOf(step)
|
|
249
|
-
return i >= 0 && i < PUBLISH_STEP_IDS.length - 1 ? PUBLISH_STEP_IDS[i + 1] ?? null : null
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/** 线性上一步(第一步返回 null)。 */
|
|
253
|
-
export function prevStepId(step: PublishStepId): PublishStepId | null {
|
|
254
|
-
const i = PUBLISH_STEP_IDS.indexOf(step)
|
|
255
|
-
return i > 0 ? PUBLISH_STEP_IDS[i - 1] ?? null : null
|
|
256
|
-
}
|