openprototype 1.2.0 → 1.4.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 +38 -20
- package/README.zh-CN.md +38 -20
- package/bin/cli.js +12 -1
- package/image/README/core-loop.gif +0 -0
- package/lib/config.js +2 -1
- package/package.json +8 -3
- package/product/demo/pc/index.html +63 -18
- package/proto-kit.config.json +1 -1
- package/runtime/server.js +15 -0
- package/scripts/check/smoke-test.js +10 -2
- package/templates/product-shell/index.html +63 -18
package/README.md
CHANGED
|
@@ -1,28 +1,39 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<h1>OpenPrototype</h1>
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
<p><strong>English</strong> | <a href="README.zh-CN.md">简体中文</a></p>
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
<h2>Keep PRDs, HTML prototypes, and mock data in sync while AI edits them.</h2>
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
<p>OpenPrototype is a local workbench for technical PMs and small product teams. It gives the Agent the current page and its PRD, applies only the requirement delta you marked, and checks the result before review.</p>
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
<p>
|
|
12
|
+
<img src="https://img.shields.io/badge/license-MIT-blue" alt="MIT license">
|
|
13
|
+
<img src="https://img.shields.io/badge/node_core-%3E%3D16-brightgreen" alt="Node.js 16 or later">
|
|
14
|
+
<img src="https://img.shields.io/badge/PRs-welcome-orange" alt="Pull requests welcome">
|
|
15
|
+
<img src="https://img.shields.io/badge/platform-macOS%20%7C%20Windows%20%7C%20Linux-lightgrey" alt="macOS, Windows and Linux">
|
|
16
|
+
</p>
|
|
17
17
|
|
|
18
18
|
</div>
|
|
19
19
|
|
|
20
|
-
<
|
|
21
|
-
<
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
</
|
|
20
|
+
<p align="center">
|
|
21
|
+
<img src="image/README/core-loop.gif" alt="Mark a PRD change, apply only the delta, keep the prototype and mock data aligned, then verify with guardrails" width="100%">
|
|
22
|
+
</p>
|
|
23
|
+
|
|
24
|
+
<p align="center">
|
|
25
|
+
<a href="https://lightdoodleh.github.io/OpenPrototype/"><strong>Try the read-only demo</strong></a>
|
|
26
|
+
·
|
|
27
|
+
<a href="https://github.com/lightdoodleh/OpenPrototype/issues">Share feedback</a>
|
|
28
|
+
</p>
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npx openprototype create myapp
|
|
32
|
+
cd myapp
|
|
33
|
+
npm install
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
**The loop:** mark the PRD change → let the Agent update the relevant files → preview the real interaction → run the guardrail checks.
|
|
26
37
|
|
|
27
38
|
|
|
28
39
|
## Why it exists
|
|
@@ -33,13 +44,13 @@ The recurring pain points when a PM builds prototypes:
|
|
|
33
44
|
- **AI can write code, but doesn't know your rules** — hand a prototype to a general-purpose AI and it rewrites whole pages, names things inconsistently, hardcodes status labels, and breaks existing interactions.
|
|
34
45
|
- **Pages are scattered at review time** — dozens of prototype pages with no unified entry point; you find pages and track versions from memory.
|
|
35
46
|
|
|
36
|
-
`openprototype` folds these three things into **one
|
|
47
|
+
`openprototype` folds these three things into **one controlled loop**:
|
|
37
48
|
|
|
38
49
|
1. **PRD (`.md`) and prototype (`.html`) sit side by side in the same directory** — browse in one place, keep them aligned in one place.
|
|
39
50
|
2. **The AI Agent on the right automatically carries "current page + current PRD" context.** Say "change field X to XX" and it edits only the relevant part instead of rewriting the whole page; it can also pick up the **red-marked** incremental changes in the PRD and land them precisely.
|
|
40
51
|
3. **A built-in red-line checker** covers script order, the data layer, status constants, the font stack, and `mode=view` physical hiding. The companion `auto-test` skill tells the Agent to run it after prototype edits.
|
|
41
52
|
|
|
42
|
-
> In one sentence: **
|
|
53
|
+
> In one sentence: **AI can move fast without letting the PRD, prototype, and mock data drift apart.**
|
|
43
54
|
|
|
44
55
|
---
|
|
45
56
|
|
|
@@ -59,7 +70,7 @@ The recurring pain points when a PM builds prototypes:
|
|
|
59
70
|
## 🎯 Who it's for / Use cases
|
|
60
71
|
|
|
61
72
|
**A good fit for**
|
|
62
|
-
- **B2B / back-office product managers**:
|
|
73
|
+
- **Technical B2B / back-office product managers**: already use AI coding tools and need interactive prototypes without letting requirements and pages drift apart.
|
|
63
74
|
- **Small teams / solo developers**: want AI to speed up prototype iteration without letting it rewrite things randomly or drift in style.
|
|
64
75
|
- **Teams that want to codify their standards**: put your own PRD templates and UI guidelines into `rules/` and have the AI produce work to your standard.
|
|
65
76
|
|
|
@@ -139,6 +150,7 @@ You type in the panel ──▶ local server (/api/agent) ──▶ OpenCode
|
|
|
139
150
|
- **Context carried automatically**: click any page on the left and the top of the panel shows "This message will carry: page X / PRD Y" — no need to paste paths manually.
|
|
140
151
|
- **Incremental update per PRD red-marks**: one click sends the PRD content marked `<span style="color:red">…</span>` as the **only edit scope** to the Agent — it edits only the red-marked parts, treats un-marked history as background, and won't rewrite or "optimize on the side."
|
|
141
152
|
- **Local by default**: the server listens on `127.0.0.1` by default; all writes and the Agent interface (`/api/*`) accept local requests only.
|
|
153
|
+
- **No creation tools after publishing**: the product shell only exposes "New folder / New page" and per-folder creation controls after confirming a local openprototype service. On static SVN or similar published URLs, those controls and the creation dialog are absent from the DOM.
|
|
142
154
|
- **LAN exposure boundary**: with `--host 0.0.0.0`, LAN clients still cannot call write or Agent endpoints, but they can read non-hidden files that the static server can reach under the project root—not only prototype pages. Use this only on a trusted network and in a dedicated prototype project with no secrets or other sensitive files.
|
|
143
155
|
|
|
144
156
|
### Install OpenCode (prerequisite for the AI panel)
|
|
@@ -234,12 +246,17 @@ When Playwright or Chromium is missing, do not rely on browser-layer results; in
|
|
|
234
246
|
"startTimeoutMs": 15000
|
|
235
247
|
},
|
|
236
248
|
"products": [
|
|
237
|
-
{
|
|
249
|
+
{
|
|
250
|
+
"id": "demo",
|
|
251
|
+
"roots": ["pc"],
|
|
252
|
+
"lanAddress": "http://192.168.1.23:8082/product/demo/pc/index.html"
|
|
253
|
+
}
|
|
238
254
|
]
|
|
239
255
|
}
|
|
240
256
|
```
|
|
241
257
|
|
|
242
258
|
`host` defaults to `127.0.0.1`. Setting it to `0.0.0.0` exposes static file reads to the LAN, so review the security boundary above first. A long-running background service also requires an explicit `npx openprototype service install --allow-lan`.
|
|
259
|
+
“Copy LAN address” in the product navigator copies that product's `lanAddress` verbatim. The downstream business using openprototype owns this value; the framework does not infer it from the current browser URL. Restart the background service with `npx openprototype service restart` after changing it.
|
|
243
260
|
|
|
244
261
|
Environment variables can override temporarily: `PROTO_KIT_PORT` · `PROTO_KIT_HOST` · `OPENCODE_BIN` · `OPENCODE_MODEL` · `OPENCODE_PORT`.
|
|
245
262
|
You can also use `npx openprototype serve --port 9000 --host 0.0.0.0` to specify the port / listen address ad hoc.
|
|
@@ -260,6 +277,7 @@ The table uses `npx` for the default local-project installation. You can omit `n
|
|
|
260
277
|
| `npx openprototype check [--changed] [--static-only] [path]` | Check all pages, Git changes, or a path; optionally run static rules only |
|
|
261
278
|
| `npx openprototype nav:sync` | Scan product directories and rebuild `nav-tree.json` |
|
|
262
279
|
| `npx openprototype doctor` | Check Node / OpenCode / config / Playwright / background service health |
|
|
280
|
+
| `npx openprototype --version` | Print the installed openprototype version (also available as `-v` or `version`) |
|
|
263
281
|
| `npm update openprototype` | Upgrade the runtime package within the version range in `package.json` |
|
|
264
282
|
| `npx openprototype update` | Print manual editable-asset comparison and merge guidance; does not upgrade |
|
|
265
283
|
|
package/README.zh-CN.md
CHANGED
|
@@ -1,28 +1,39 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<h1>OpenPrototype</h1>
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
<p><a href="README.md">English</a> | <strong>简体中文</strong></p>
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
<h2>AI 改需求时,让 PRD、HTML 原型和 mock 数据始终一致。</h2>
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
<p>OpenPrototype 是面向技术型产品经理和小型产品团队的本地工作台。它把当前页面和对应 PRD 自动交给 Agent,只执行你标出的需求增量,并在评审前检查结果。</p>
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
<p>
|
|
12
|
+
<img src="https://img.shields.io/badge/license-MIT-blue" alt="MIT 许可证">
|
|
13
|
+
<img src="https://img.shields.io/badge/node_core-%3E%3D16-brightgreen" alt="Node.js 16 或更高版本">
|
|
14
|
+
<img src="https://img.shields.io/badge/PRs-welcome-orange" alt="欢迎提交 Pull Request">
|
|
15
|
+
<img src="https://img.shields.io/badge/platform-macOS%20%7C%20Windows%20%7C%20Linux-lightgrey" alt="macOS、Windows 与 Linux">
|
|
16
|
+
</p>
|
|
17
17
|
|
|
18
18
|
</div>
|
|
19
19
|
|
|
20
|
-
<
|
|
21
|
-
<
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
</
|
|
20
|
+
<p align="center">
|
|
21
|
+
<img src="image/README/core-loop.gif" alt="标出 PRD 增量、精准更新相关文件、同步原型与 mock 数据并通过红线检查" width="100%">
|
|
22
|
+
</p>
|
|
23
|
+
|
|
24
|
+
<p align="center">
|
|
25
|
+
<a href="https://lightdoodleh.github.io/OpenPrototype/"><strong>在线体验只读 Demo</strong></a>
|
|
26
|
+
·
|
|
27
|
+
<a href="https://github.com/lightdoodleh/OpenPrototype/issues">提交反馈</a>
|
|
28
|
+
</p>
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npx openprototype create myapp
|
|
32
|
+
cd myapp
|
|
33
|
+
npm install
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
**核心闭环:**标出 PRD 增量 → Agent 更新相关文件 → 预览真实交互 → 运行红线检查。
|
|
26
37
|
|
|
27
38
|
|
|
28
39
|
## 为什么要有它
|
|
@@ -33,13 +44,13 @@
|
|
|
33
44
|
- **AI 会写代码,但不懂你的规矩** —— 直接让通用 AI 改原型,它会整页重写、命名混乱、把状态文案写死、破坏既有交互。
|
|
34
45
|
- **评审时页面散落各处** —— 几十个原型页没有统一入口,找页面、对版本靠记忆。
|
|
35
46
|
|
|
36
|
-
`openprototype`
|
|
47
|
+
`openprototype` 把这三件事收进**一个受控闭环**:
|
|
37
48
|
|
|
38
49
|
1. **PRD(`.md`)和原型(`.html`)同目录并排放**,一处浏览、一处对齐。
|
|
39
50
|
2. **右侧 AI Agent 自动携带「当前页面 + 当前 PRD」上下文**,你说"把某字段改成 XX",它只改相关部分、不整页重写;还能识别 PRD 里**标红**的增量改动精准落地。
|
|
40
51
|
3. **内置红线检查器**覆盖脚本顺序、数据层、状态常量化、字体栈与 `mode=view` 物理隐藏;配套 `auto-test` skill 会要求 Agent 在改完原型后执行检查。
|
|
41
52
|
|
|
42
|
-
>
|
|
53
|
+
> 一句话:**让 AI 快速改原型,同时不让 PRD、页面和 mock 数据互相漂移。**
|
|
43
54
|
|
|
44
55
|
---
|
|
45
56
|
|
|
@@ -59,7 +70,7 @@
|
|
|
59
70
|
## 🎯 适合谁 / 使用场景
|
|
60
71
|
|
|
61
72
|
**适合**
|
|
62
|
-
-
|
|
73
|
+
- **会使用 AI 编码工具的 B 端 / 中后台产品经理**:需要快速做可交互原型,又不希望需求、页面和数据越改越散。
|
|
63
74
|
- **小团队 / 独立开发**:想用 AI 加速原型迭代,又不希望 AI 每次乱改、风格漂移。
|
|
64
75
|
- **需要沉淀规范的团队**:把自己的 PRD 模板、UI 规范放进 `rules/`,让 AI 按你的标准产出。
|
|
65
76
|
|
|
@@ -139,6 +150,7 @@ npx openprototype service uninstall
|
|
|
139
150
|
- **自动带上下文**:点左侧任一页面,面板顶部就显示「本条消息将携带:页面 X / PRD Y」,无需你手动贴路径。
|
|
140
151
|
- **按 PRD 标红增量更新**:一键把 PRD 里 `<span style="color:red">…</span>` 标红的内容作为**唯一改动范围**发给 Agent —— 只改标红处,未标红的历史内容当背景,不重写、不"顺手优化"。
|
|
141
152
|
- **默认仅本机访问**:服务器默认只监听 `127.0.0.1`;所有写入与 Agent 接口(`/api/*`)只接受本机请求。
|
|
153
|
+
- **发布态不提供创建能力**:产品壳仅在确认连接到本机 openprototype 服务后显示“新建文件夹 / 新建页面”及目录内新增入口;发布到 SVN 等静态地址后,这些入口和创建弹窗不会进入页面 DOM。
|
|
142
154
|
- **局域网开放边界**:使用 `--host 0.0.0.0` 后,局域网设备虽然不能调用写入与 Agent 接口,但能读取项目根目录下服务器可访问的非隐藏文件,不仅是原型页面。只应在可信网络和专用原型项目中使用,并确保项目中没有密钥或其他敏感文件。
|
|
143
155
|
|
|
144
156
|
### 安装 OpenCode(AI 面板前置)
|
|
@@ -236,12 +248,17 @@ npx playwright install chromium
|
|
|
236
248
|
"startTimeoutMs": 15000
|
|
237
249
|
},
|
|
238
250
|
"products": [
|
|
239
|
-
{
|
|
251
|
+
{
|
|
252
|
+
"id": "demo",
|
|
253
|
+
"roots": ["pc"],
|
|
254
|
+
"lanAddress": "http://192.168.1.23:8082/product/demo/pc/index.html"
|
|
255
|
+
}
|
|
240
256
|
]
|
|
241
257
|
}
|
|
242
258
|
```
|
|
243
259
|
|
|
244
260
|
`host` 默认为 `127.0.0.1`。设为 `0.0.0.0` 会向局域网开放静态文件读取,请先阅读上面的安全边界;长期运行的常驻服务还需显式执行 `npx openprototype service install --allow-lan`。
|
|
261
|
+
产品导航中的“复制局域网地址”会原样复制该产品的 `lanAddress`;地址由引用 openprototype 的业务配置,框架不会根据当前浏览器地址自动推断。修改后,常驻服务需执行一次 `npx openprototype service restart`。
|
|
245
262
|
|
|
246
263
|
环境变量可临时覆盖:`PROTO_KIT_PORT` · `PROTO_KIT_HOST` · `OPENCODE_BIN` · `OPENCODE_MODEL` · `OPENCODE_PORT`。
|
|
247
264
|
也可用 `npx openprototype serve --port 9000 --host 0.0.0.0` 临时指定端口 / 监听地址。
|
|
@@ -262,6 +279,7 @@ npx playwright install chromium
|
|
|
262
279
|
| `npx openprototype check [--changed] [--static-only] [路径]` | 检查全部、Git 改动或指定范围;可只跑静态规则 |
|
|
263
280
|
| `npx openprototype nav:sync` | 扫描产品目录并重建 `nav-tree.json` |
|
|
264
281
|
| `npx openprototype doctor` | 体检 Node / OpenCode / 配置 / Playwright / 常驻服务 |
|
|
282
|
+
| `npx openprototype --version` | 查看当前安装的 openprototype 版本号(也可使用 `-v` 或 `version`) |
|
|
265
283
|
| `npm update openprototype` | 按 `package.json` 的版本范围升级框架运行时包 |
|
|
266
284
|
| `npx openprototype update` | 仅打印可编辑资产的手工对比与合并指引,不执行升级 |
|
|
267
285
|
|
package/bin/cli.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* openprototype nav:sync 重建各产品 nav-tree.json
|
|
14
14
|
* openprototype doctor 体检:Node / OpenCode / 配置 / Playwright
|
|
15
15
|
* openprototype update 提示如何更新框架(运行时随 npm,可编辑资产按需覆盖)
|
|
16
|
+
* openprototype --version 查看当前版本号
|
|
16
17
|
*/
|
|
17
18
|
|
|
18
19
|
const fs = require('fs');
|
|
@@ -311,7 +312,7 @@ function cmdAddProduct(argv) {
|
|
|
311
312
|
const config = loadOrInitConfig(root);
|
|
312
313
|
config.products = config.products || [];
|
|
313
314
|
if (!config.products.some((p) => p.id === id)) {
|
|
314
|
-
config.products.push({ id, roots: ['pc'] });
|
|
315
|
+
config.products.push({ id, roots: ['pc'], lanAddress: '' });
|
|
315
316
|
saveConfig(root, config);
|
|
316
317
|
ok(`已在 ${CONFIG_FILENAME} 注册产品 ${id}`);
|
|
317
318
|
} else info(C.dim(` 产品 ${id} 已在配置中`));
|
|
@@ -470,6 +471,12 @@ function cmdUpdate() {
|
|
|
470
471
|
info(C.dim(' (建议先 git commit,再用 diff 工具挑选要更新的内容,保护你的本地改动)\n'));
|
|
471
472
|
}
|
|
472
473
|
|
|
474
|
+
function cmdVersion() {
|
|
475
|
+
const pkg = readJson(path.join(PKG_ROOT, 'package.json'), {});
|
|
476
|
+
if (!pkg.version) die('无法读取 openprototype 版本号');
|
|
477
|
+
info(pkg.version);
|
|
478
|
+
}
|
|
479
|
+
|
|
473
480
|
// ── 入口 ────────────────────────────────────────────────
|
|
474
481
|
function help() {
|
|
475
482
|
info(`
|
|
@@ -485,6 +492,7 @@ ${C.b('openprototype')} — 本地原型工作台脚手架
|
|
|
485
492
|
${C.g('openprototype nav:sync')} 重建各产品 nav-tree.json
|
|
486
493
|
${C.g('openprototype doctor')} 体检(Node / OpenCode / 配置 / Playwright)
|
|
487
494
|
${C.g('openprototype update')} 如何更新框架
|
|
495
|
+
${C.g('openprototype --version')} 查看当前版本号(也可使用 -v 或 version)
|
|
488
496
|
`);
|
|
489
497
|
}
|
|
490
498
|
|
|
@@ -501,6 +509,9 @@ async function main() {
|
|
|
501
509
|
case 'nav-sync': return runNode('scripts/check/sync-nav-tree.js', argv);
|
|
502
510
|
case 'doctor': return cmdDoctor();
|
|
503
511
|
case 'update': return cmdUpdate();
|
|
512
|
+
case '-v':
|
|
513
|
+
case '--version':
|
|
514
|
+
case 'version': return cmdVersion();
|
|
504
515
|
case undefined:
|
|
505
516
|
case '-h':
|
|
506
517
|
case '--help':
|
|
Binary file
|
package/lib/config.js
CHANGED
|
@@ -29,8 +29,9 @@ const DEFAULTS = {
|
|
|
29
29
|
port: 4097,
|
|
30
30
|
startTimeoutMs: 15000
|
|
31
31
|
},
|
|
32
|
+
// lanAddress 由引用 openprototype 的业务配置,导航壳的“复制局域网地址”会原样复制该值。
|
|
32
33
|
// 每个产品一个入口目录;roots 目前只支持 'pc'('h5' 后续再加)
|
|
33
|
-
products: [{ id: 'demo', roots: ['pc'] }]
|
|
34
|
+
products: [{ id: 'demo', roots: ['pc'], lanAddress: '' }]
|
|
34
35
|
};
|
|
35
36
|
|
|
36
37
|
function deepMerge(base, override) {
|
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openprototype",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "本地原型工作台:左侧树形导航 + 中间原型预览 + 右侧 AI Agent(OpenCode)。PRD 与 HTML/JS 原型协作,含自动化检查。",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"prototype",
|
|
7
|
+
"ai-prototyping",
|
|
7
8
|
"prd",
|
|
9
|
+
"product-management",
|
|
10
|
+
"html-prototype",
|
|
11
|
+
"local-first",
|
|
8
12
|
"opencode",
|
|
9
13
|
"agent",
|
|
10
14
|
"scaffold",
|
|
@@ -16,7 +20,7 @@
|
|
|
16
20
|
"type": "git",
|
|
17
21
|
"url": "git+https://github.com/lightdoodleh/openprototype.git"
|
|
18
22
|
},
|
|
19
|
-
"homepage": "https://github.
|
|
23
|
+
"homepage": "https://lightdoodleh.github.io/OpenPrototype/",
|
|
20
24
|
"bugs": "https://github.com/lightdoodleh/openprototype/issues",
|
|
21
25
|
"engines": {
|
|
22
26
|
"node": ">=16"
|
|
@@ -48,7 +52,8 @@
|
|
|
48
52
|
"proto-kit.config.json",
|
|
49
53
|
"AGENTS.md",
|
|
50
54
|
"CONVENTIONS.md",
|
|
51
|
-
"README.md"
|
|
55
|
+
"README.md",
|
|
56
|
+
"image/README/core-loop.gif"
|
|
52
57
|
],
|
|
53
58
|
"devDependencies": {
|
|
54
59
|
"playwright": "^1.49.0"
|
|
@@ -553,7 +553,7 @@ body.is-resizing-sidebar .preview-frame {
|
|
|
553
553
|
<div class="sidebar-header">
|
|
554
554
|
<div class="sidebar-title-row">
|
|
555
555
|
<div class="sidebar-title">Demo 原型导航</div>
|
|
556
|
-
<button class="copy-address-btn" id="copyAddressBtn" type="button"
|
|
556
|
+
<button class="copy-address-btn" id="copyAddressBtn" type="button">复制局域网地址</button>
|
|
557
557
|
</div>
|
|
558
558
|
<div class="version-row">
|
|
559
559
|
<span class="version-label">版本</span>
|
|
@@ -577,8 +577,8 @@ body.is-resizing-sidebar .preview-frame {
|
|
|
577
577
|
</label>
|
|
578
578
|
<button class="btn" id="expandAllBtn">全部展开</button>
|
|
579
579
|
<button class="btn" id="collapseAllBtn">全部折叠</button>
|
|
580
|
-
<button class="btn" id="newFolderBtn">新建文件夹</button>
|
|
581
|
-
<button class="btn" id="newPageBtn">新建页面</button>
|
|
580
|
+
<button class="btn" id="newFolderBtn" hidden>新建文件夹</button>
|
|
581
|
+
<button class="btn" id="newPageBtn" hidden>新建页面</button>
|
|
582
582
|
</div>
|
|
583
583
|
</div>
|
|
584
584
|
|
|
@@ -638,8 +638,31 @@ const VERSION_KEY = NAV_NS + '-version';
|
|
|
638
638
|
const VERSION_HISTORY_KEY = NAV_NS + '-version-history';
|
|
639
639
|
const REVIEW_KEY = NAV_NS + '-review-status';
|
|
640
640
|
const SIDEBAR_WIDTH_KEY = NAV_NS + '-sidebar-width';
|
|
641
|
-
// 复制当前页面地址(供分享本地/局域网预览地址)
|
|
642
641
|
const navStorage = window['localStorage'];
|
|
642
|
+
let localEditingEnabled = false;
|
|
643
|
+
|
|
644
|
+
async function detectLocalEditing() {
|
|
645
|
+
try {
|
|
646
|
+
const res = await fetch('/api/health', { cache: 'no-store' });
|
|
647
|
+
const data = await res.json().catch(() => ({}));
|
|
648
|
+
return res.ok && data.ok === true && typeof data.version === 'string' && Number.isFinite(data.port);
|
|
649
|
+
} catch {
|
|
650
|
+
return false;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
function applyLocalEditingState() {
|
|
655
|
+
const createControls = ['newFolderBtn', 'newPageBtn']
|
|
656
|
+
.map(id => document.getElementById(id))
|
|
657
|
+
.filter(Boolean);
|
|
658
|
+
if (localEditingEnabled) {
|
|
659
|
+
createControls.forEach(control => { control.hidden = false; });
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
createControls.forEach(control => control.remove());
|
|
663
|
+
const createModal = document.getElementById('createModalMask');
|
|
664
|
+
if (createModal) createModal.remove();
|
|
665
|
+
}
|
|
643
666
|
|
|
644
667
|
function loadReviewStatus() {
|
|
645
668
|
try { return JSON.parse(navStorage.getItem(REVIEW_KEY) || '{}'); } catch { return {}; }
|
|
@@ -1289,7 +1312,10 @@ function renderNodes(nodes, depth, trail) {
|
|
|
1289
1312
|
const head = document.createElement('div');
|
|
1290
1313
|
head.className = 'folder-head';
|
|
1291
1314
|
setupTreeDrag(head, trail, navNodeKey(node), folderKey);
|
|
1292
|
-
|
|
1315
|
+
const createActions = localEditingEnabled
|
|
1316
|
+
? '<button type="button" class="tree-add-btn" data-create="page" title="在此文件夹新建页面">+页</button><button type="button" class="tree-add-btn" data-create="folder" title="在此文件夹新建子文件夹">+夹</button>'
|
|
1317
|
+
: '';
|
|
1318
|
+
head.innerHTML = `<span class="folder-arrow">${I_ARROW}</span><span class="folder-icon">${I_FOLDER}</span><span class="folder-name">${node.name}</span>${createActions}`;
|
|
1293
1319
|
head.addEventListener('click', () => {
|
|
1294
1320
|
if (Date.now() >= suppressTreeClickUntil) folder.classList.toggle('collapsed');
|
|
1295
1321
|
});
|
|
@@ -1439,11 +1465,22 @@ function copyText(text, successMsg) {
|
|
|
1439
1465
|
});
|
|
1440
1466
|
}
|
|
1441
1467
|
|
|
1468
|
+
async function loadLanAddress() {
|
|
1469
|
+
const productId = window.PROTO_KIT && window.PROTO_KIT.productId;
|
|
1470
|
+
const params = new URLSearchParams({ productId: productId || '' });
|
|
1471
|
+
const res = await fetch('/api/lan-address?' + params.toString(), { cache: 'no-store' });
|
|
1472
|
+
const data = await res.json().catch(() => ({}));
|
|
1473
|
+
if (!res.ok || !data.ok) throw new Error(data.error || '局域网地址读取失败');
|
|
1474
|
+
return String(data.lanAddress || '').trim();
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1442
1477
|
// ─────────────────────────────────────────────
|
|
1443
1478
|
// Init
|
|
1444
1479
|
// ─────────────────────────────────────────────
|
|
1445
1480
|
window.addEventListener('DOMContentLoaded', async () => {
|
|
1446
1481
|
initSidebarResize();
|
|
1482
|
+
localEditingEnabled = await detectLocalEditing();
|
|
1483
|
+
applyLocalEditingState();
|
|
1447
1484
|
try {
|
|
1448
1485
|
await loadTree();
|
|
1449
1486
|
} catch (e) {
|
|
@@ -1496,24 +1533,32 @@ window.addEventListener('DOMContentLoaded', async () => {
|
|
|
1496
1533
|
document.getElementById('collapseAllBtn').addEventListener('click', () => {
|
|
1497
1534
|
treeWrap.querySelectorAll('.folder').forEach(f => f.classList.add('collapsed'));
|
|
1498
1535
|
});
|
|
1499
|
-
document.getElementById('copyAddressBtn').addEventListener('click', () => {
|
|
1500
|
-
|
|
1536
|
+
document.getElementById('copyAddressBtn').addEventListener('click', async () => {
|
|
1537
|
+
try {
|
|
1538
|
+
const lanAddress = await loadLanAddress();
|
|
1539
|
+
if (!lanAddress) {
|
|
1540
|
+
showToast('请先在 proto-kit.config.json 配置该产品的 lanAddress');
|
|
1541
|
+
return;
|
|
1542
|
+
}
|
|
1543
|
+
copyText(lanAddress, '局域网地址已复制到剪贴板');
|
|
1544
|
+
} catch (err) {
|
|
1545
|
+
showToast(err.message || '局域网地址读取失败');
|
|
1546
|
+
}
|
|
1501
1547
|
});
|
|
1502
1548
|
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
input.addEventListener('keydown', e => {
|
|
1549
|
+
if (localEditingEnabled) {
|
|
1550
|
+
document.getElementById('newFolderBtn').addEventListener('click', () => openCreateModal('folder', ''));
|
|
1551
|
+
document.getElementById('newPageBtn').addEventListener('click', () => openCreateModal('page', ''));
|
|
1552
|
+
document.getElementById('createCancelBtn').addEventListener('click', closeCreateModal);
|
|
1553
|
+
document.getElementById('createConfirmBtn').addEventListener('click', submitCreateModal);
|
|
1554
|
+
document.getElementById('createModalMask').addEventListener('click', e => {
|
|
1555
|
+
if (e.target === e.currentTarget) closeCreateModal();
|
|
1556
|
+
});
|
|
1557
|
+
document.getElementById('createNameInput').addEventListener('keydown', e => {
|
|
1513
1558
|
if (e.key === 'Enter') { e.preventDefault(); submitCreateModal(); }
|
|
1514
1559
|
else if (e.key === 'Escape') closeCreateModal();
|
|
1515
1560
|
});
|
|
1516
|
-
}
|
|
1561
|
+
}
|
|
1517
1562
|
|
|
1518
1563
|
});
|
|
1519
1564
|
</script>
|
package/proto-kit.config.json
CHANGED
package/runtime/server.js
CHANGED
|
@@ -136,6 +136,17 @@ function requireLoopback(req, res) {
|
|
|
136
136
|
return false;
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
+
function handleLanAddress(req, res) {
|
|
140
|
+
const requestUrl = new URL(req.url, 'http://localhost');
|
|
141
|
+
const productId = String(requestUrl.searchParams.get('productId') || '').trim();
|
|
142
|
+
const product = CONFIG.products.find((item) => item.id === productId);
|
|
143
|
+
if (!product) return sendJson(res, 404, { ok: false, error: '未找到对应产品的局域网地址配置' });
|
|
144
|
+
return sendJson(res, 200, {
|
|
145
|
+
ok: true,
|
|
146
|
+
lanAddress: typeof product.lanAddress === 'string' ? product.lanAddress.trim() : ''
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
139
150
|
// ── PRD 保存 ───────────────────────────────────────────
|
|
140
151
|
function handleSavePrd(req, res) {
|
|
141
152
|
readJsonBody(req, 5 * 1024 * 1024, (parseErr, data) => {
|
|
@@ -944,6 +955,10 @@ const server = http.createServer(async (req, res) => {
|
|
|
944
955
|
});
|
|
945
956
|
}
|
|
946
957
|
|
|
958
|
+
if (req.method === 'GET' && urlPath === '/api/lan-address') {
|
|
959
|
+
return handleLanAddress(req, res);
|
|
960
|
+
}
|
|
961
|
+
|
|
947
962
|
if (await handleAgentApi(req, res, urlPath)) return;
|
|
948
963
|
|
|
949
964
|
if (req.method === 'POST' && urlPath === '/api/save-prd') return requireLoopback(req, res) && handleSavePrd(req, res);
|
|
@@ -35,8 +35,16 @@ let chromium;
|
|
|
35
35
|
try {
|
|
36
36
|
({ chromium } = require('playwright'));
|
|
37
37
|
} catch {
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
const result = {
|
|
39
|
+
scanned: 0,
|
|
40
|
+
errors: [],
|
|
41
|
+
warns: [{ file: '-', rule: '环境', msg: 'Playwright 未安装,已跳过运行时层;安装:npm i -D playwright && npx playwright install chromium' }]
|
|
42
|
+
};
|
|
43
|
+
if (process.argv.includes('--json')) process.stdout.write(JSON.stringify(result));
|
|
44
|
+
else {
|
|
45
|
+
console.error('\n⚠️ 未安装 Playwright,跳过运行时冒烟测试。');
|
|
46
|
+
console.error(' 安装:npm i -D playwright && npx playwright install chromium\n');
|
|
47
|
+
}
|
|
40
48
|
process.exit(0);
|
|
41
49
|
}
|
|
42
50
|
|
|
@@ -553,7 +553,7 @@ body.is-resizing-sidebar .preview-frame {
|
|
|
553
553
|
<div class="sidebar-header">
|
|
554
554
|
<div class="sidebar-title-row">
|
|
555
555
|
<div class="sidebar-title">{{PRODUCT_TITLE}} 原型导航</div>
|
|
556
|
-
<button class="copy-address-btn" id="copyAddressBtn" type="button"
|
|
556
|
+
<button class="copy-address-btn" id="copyAddressBtn" type="button">复制局域网地址</button>
|
|
557
557
|
</div>
|
|
558
558
|
<div class="version-row">
|
|
559
559
|
<span class="version-label">版本</span>
|
|
@@ -577,8 +577,8 @@ body.is-resizing-sidebar .preview-frame {
|
|
|
577
577
|
</label>
|
|
578
578
|
<button class="btn" id="expandAllBtn">全部展开</button>
|
|
579
579
|
<button class="btn" id="collapseAllBtn">全部折叠</button>
|
|
580
|
-
<button class="btn" id="newFolderBtn">新建文件夹</button>
|
|
581
|
-
<button class="btn" id="newPageBtn">新建页面</button>
|
|
580
|
+
<button class="btn" id="newFolderBtn" hidden>新建文件夹</button>
|
|
581
|
+
<button class="btn" id="newPageBtn" hidden>新建页面</button>
|
|
582
582
|
</div>
|
|
583
583
|
</div>
|
|
584
584
|
|
|
@@ -638,8 +638,31 @@ const VERSION_KEY = NAV_NS + '-version';
|
|
|
638
638
|
const VERSION_HISTORY_KEY = NAV_NS + '-version-history';
|
|
639
639
|
const REVIEW_KEY = NAV_NS + '-review-status';
|
|
640
640
|
const SIDEBAR_WIDTH_KEY = NAV_NS + '-sidebar-width';
|
|
641
|
-
// 复制当前页面地址(供分享本地/局域网预览地址)
|
|
642
641
|
const navStorage = window['localStorage'];
|
|
642
|
+
let localEditingEnabled = false;
|
|
643
|
+
|
|
644
|
+
async function detectLocalEditing() {
|
|
645
|
+
try {
|
|
646
|
+
const res = await fetch('/api/health', { cache: 'no-store' });
|
|
647
|
+
const data = await res.json().catch(() => ({}));
|
|
648
|
+
return res.ok && data.ok === true && typeof data.version === 'string' && Number.isFinite(data.port);
|
|
649
|
+
} catch {
|
|
650
|
+
return false;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
function applyLocalEditingState() {
|
|
655
|
+
const createControls = ['newFolderBtn', 'newPageBtn']
|
|
656
|
+
.map(id => document.getElementById(id))
|
|
657
|
+
.filter(Boolean);
|
|
658
|
+
if (localEditingEnabled) {
|
|
659
|
+
createControls.forEach(control => { control.hidden = false; });
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
createControls.forEach(control => control.remove());
|
|
663
|
+
const createModal = document.getElementById('createModalMask');
|
|
664
|
+
if (createModal) createModal.remove();
|
|
665
|
+
}
|
|
643
666
|
|
|
644
667
|
function loadReviewStatus() {
|
|
645
668
|
try { return JSON.parse(navStorage.getItem(REVIEW_KEY) || '{}'); } catch { return {}; }
|
|
@@ -1289,7 +1312,10 @@ function renderNodes(nodes, depth, trail) {
|
|
|
1289
1312
|
const head = document.createElement('div');
|
|
1290
1313
|
head.className = 'folder-head';
|
|
1291
1314
|
setupTreeDrag(head, trail, navNodeKey(node), folderKey);
|
|
1292
|
-
|
|
1315
|
+
const createActions = localEditingEnabled
|
|
1316
|
+
? '<button type="button" class="tree-add-btn" data-create="page" title="在此文件夹新建页面">+页</button><button type="button" class="tree-add-btn" data-create="folder" title="在此文件夹新建子文件夹">+夹</button>'
|
|
1317
|
+
: '';
|
|
1318
|
+
head.innerHTML = `<span class="folder-arrow">${I_ARROW}</span><span class="folder-icon">${I_FOLDER}</span><span class="folder-name">${node.name}</span>${createActions}`;
|
|
1293
1319
|
head.addEventListener('click', () => {
|
|
1294
1320
|
if (Date.now() >= suppressTreeClickUntil) folder.classList.toggle('collapsed');
|
|
1295
1321
|
});
|
|
@@ -1439,11 +1465,22 @@ function copyText(text, successMsg) {
|
|
|
1439
1465
|
});
|
|
1440
1466
|
}
|
|
1441
1467
|
|
|
1468
|
+
async function loadLanAddress() {
|
|
1469
|
+
const productId = window.PROTO_KIT && window.PROTO_KIT.productId;
|
|
1470
|
+
const params = new URLSearchParams({ productId: productId || '' });
|
|
1471
|
+
const res = await fetch('/api/lan-address?' + params.toString(), { cache: 'no-store' });
|
|
1472
|
+
const data = await res.json().catch(() => ({}));
|
|
1473
|
+
if (!res.ok || !data.ok) throw new Error(data.error || '局域网地址读取失败');
|
|
1474
|
+
return String(data.lanAddress || '').trim();
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1442
1477
|
// ─────────────────────────────────────────────
|
|
1443
1478
|
// Init
|
|
1444
1479
|
// ─────────────────────────────────────────────
|
|
1445
1480
|
window.addEventListener('DOMContentLoaded', async () => {
|
|
1446
1481
|
initSidebarResize();
|
|
1482
|
+
localEditingEnabled = await detectLocalEditing();
|
|
1483
|
+
applyLocalEditingState();
|
|
1447
1484
|
try {
|
|
1448
1485
|
await loadTree();
|
|
1449
1486
|
} catch (e) {
|
|
@@ -1496,24 +1533,32 @@ window.addEventListener('DOMContentLoaded', async () => {
|
|
|
1496
1533
|
document.getElementById('collapseAllBtn').addEventListener('click', () => {
|
|
1497
1534
|
treeWrap.querySelectorAll('.folder').forEach(f => f.classList.add('collapsed'));
|
|
1498
1535
|
});
|
|
1499
|
-
document.getElementById('copyAddressBtn').addEventListener('click', () => {
|
|
1500
|
-
|
|
1536
|
+
document.getElementById('copyAddressBtn').addEventListener('click', async () => {
|
|
1537
|
+
try {
|
|
1538
|
+
const lanAddress = await loadLanAddress();
|
|
1539
|
+
if (!lanAddress) {
|
|
1540
|
+
showToast('请先在 proto-kit.config.json 配置该产品的 lanAddress');
|
|
1541
|
+
return;
|
|
1542
|
+
}
|
|
1543
|
+
copyText(lanAddress, '局域网地址已复制到剪贴板');
|
|
1544
|
+
} catch (err) {
|
|
1545
|
+
showToast(err.message || '局域网地址读取失败');
|
|
1546
|
+
}
|
|
1501
1547
|
});
|
|
1502
1548
|
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
input.addEventListener('keydown', e => {
|
|
1549
|
+
if (localEditingEnabled) {
|
|
1550
|
+
document.getElementById('newFolderBtn').addEventListener('click', () => openCreateModal('folder', ''));
|
|
1551
|
+
document.getElementById('newPageBtn').addEventListener('click', () => openCreateModal('page', ''));
|
|
1552
|
+
document.getElementById('createCancelBtn').addEventListener('click', closeCreateModal);
|
|
1553
|
+
document.getElementById('createConfirmBtn').addEventListener('click', submitCreateModal);
|
|
1554
|
+
document.getElementById('createModalMask').addEventListener('click', e => {
|
|
1555
|
+
if (e.target === e.currentTarget) closeCreateModal();
|
|
1556
|
+
});
|
|
1557
|
+
document.getElementById('createNameInput').addEventListener('keydown', e => {
|
|
1513
1558
|
if (e.key === 'Enter') { e.preventDefault(); submitCreateModal(); }
|
|
1514
1559
|
else if (e.key === 'Escape') closeCreateModal();
|
|
1515
1560
|
});
|
|
1516
|
-
}
|
|
1561
|
+
}
|
|
1517
1562
|
|
|
1518
1563
|
});
|
|
1519
1564
|
</script>
|