@joplo-app/server 0.2.10 → 0.2.13
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/dist/build.d.ts +3 -2
- package/dist/build.js +19 -7
- package/dist/cloud.d.ts +85 -0
- package/dist/cloud.js +110 -0
- package/dist/contract.d.ts +17 -2
- package/dist/dev.d.ts +5 -1
- package/dist/dev.js +57 -5
- package/dist/feature-diff-locales.json +882 -0
- package/dist/feature-diff-runtime.js +427 -0
- package/dist/feature-diff-viewer.d.ts +3 -0
- package/dist/feature-diff-viewer.js +130 -0
- package/dist/feature-diff.d.ts +14 -0
- package/dist/feature-diff.js +56 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/local-review.d.ts +18 -0
- package/dist/local-review.js +133 -0
- package/dist/render.js +6 -3
- package/dist/voice-http.d.ts +10 -1
- package/dist/voice-http.js +25 -10
- package/dist/voice.d.ts +16 -6
- package/dist/voice.js +21 -1
- package/package.json +5 -4
package/dist/build.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Project } from '@joplo-app/core';
|
|
1
|
+
import { type StepIdentity, type Project } from '@joplo-app/core';
|
|
2
2
|
import type { BuildOptions, BuildResult } from './contract.js';
|
|
3
3
|
import type { DistWeb } from './web-assets.js';
|
|
4
4
|
/** 发布站只需要的 IR:去掉创作侧字段(publish 模式下它们本来就为空)。层级、镜头、角色(说话人、过渡卡、层级的 role)与 featureIds 顺序属于演示,保留(D43 / D56 / D61)。 */
|
|
@@ -12,7 +12,8 @@ export declare const jsonForHtml: (v: unknown) => string;
|
|
|
12
12
|
export declare function finalizeHtml(html: string, readAsset: (rel: string) => string, inline: {
|
|
13
13
|
project: unknown;
|
|
14
14
|
home: string | null;
|
|
15
|
-
|
|
15
|
+
scoped?: true;
|
|
16
|
+
}, identity?: StepIdentity): {
|
|
16
17
|
html: string;
|
|
17
18
|
inlined: string[];
|
|
18
19
|
};
|
package/dist/build.js
CHANGED
|
@@ -19,7 +19,7 @@ import os from 'node:os';
|
|
|
19
19
|
import path from 'node:path';
|
|
20
20
|
import tailwindcss from '@tailwindcss/vite';
|
|
21
21
|
import { build as viteBuild, createServer } from 'vite';
|
|
22
|
-
import { JoploError, orderedFeatures } from '@joplo-app/core';
|
|
22
|
+
import { stepIdentity, hasScope, JoploError, orderedFeatures, resolveScope, scopeProject } from '@joplo-app/core';
|
|
23
23
|
import { compileProject } from "./project.js";
|
|
24
24
|
import { joploProjectPlugin, kitAliases, locateWebAssets, realProjectDir } from "./vite-shared.js";
|
|
25
25
|
import { subsetSiteFonts } from "./site-fonts.js";
|
|
@@ -33,14 +33,14 @@ export function publishPayload(project, home) {
|
|
|
33
33
|
const options = Object.fromEntries(Object.entries(project.options).map(([id, o]) => [id, { id: o.id, featureId: o.featureId, key: o.key, name: o.name, idea: o.idea, routes: o.routes, coverage: {}, layers: o.layers ?? {} }]));
|
|
34
34
|
const scenarios = Object.fromEntries(Object.entries(project.scenarios).map(([id, s]) => {
|
|
35
35
|
const { caseIds: _ci, ...sr } = s;
|
|
36
|
-
return [id, { ...sr, caseIds: [], steps: s.steps.map(({ ruleIds: _ri, ...st }) => ({ ...st, ruleIds: [] })) }];
|
|
36
|
+
return [id, { ...sr, caseIds: [], steps: s.steps.map(({ ruleIds: _ri, key: _key, ...st }) => ({ ...st, ruleIds: [] })) }];
|
|
37
37
|
}));
|
|
38
38
|
return { project: { ...rest, features, options, scenarios }, home: home && project.routes[home] ? home : null };
|
|
39
39
|
}
|
|
40
40
|
/** 把 JSON 安全地放进 <script type="application/json">。 */
|
|
41
41
|
export const jsonForHtml = (v) => JSON.stringify(v).replace(/</g, '\\u003c').replace(/>/g, '\\u003e').replace(/&/g, '\\u0026').replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029');
|
|
42
42
|
/** 后处理 vite 产出的 HTML:内联 IR、内联入口脚本、去掉 crossorigin(file:// 下 CORS 会失败)。 */
|
|
43
|
-
export function finalizeHtml(html, readAsset, inline) {
|
|
43
|
+
export function finalizeHtml(html, readAsset, inline, identity) {
|
|
44
44
|
const inlined = [];
|
|
45
45
|
let out = html.replace(/\s+crossorigin(?:="[^"]*")?/g, '');
|
|
46
46
|
out = out.replace(/<link rel="modulepreload"[^>]*>\s*/g, '');
|
|
@@ -49,7 +49,7 @@ export function finalizeHtml(html, readAsset, inline) {
|
|
|
49
49
|
const code = readAsset(rel).replace(/<\/script/gi, '<\\/script');
|
|
50
50
|
return `<script type="module">${code}</script>`;
|
|
51
51
|
});
|
|
52
|
-
const data = `<script type="application/json" id="joplo-ir">${jsonForHtml(inline)}</script
|
|
52
|
+
const data = `<meta name="joplo-feature-diff-player" content="1"><script type="application/json" id="joplo-ir">${jsonForHtml(inline)}</script>` + (identity ? `\n<script type="application/json" id="joplo-step-keys">${jsonForHtml(identity)}</script>` : '');
|
|
53
53
|
out = out.replace('</head>', ` ${data}\n </head>`);
|
|
54
54
|
return { html: out, inlined };
|
|
55
55
|
}
|
|
@@ -120,8 +120,18 @@ export async function buildSite(opts) {
|
|
|
120
120
|
const errs = compiled.diagnostics.filter((d) => d.severity === 'error');
|
|
121
121
|
throw new JoploError('EXPORT_FAILED', `Project compilation failed; no published site was generated: \n${errs.map((d) => `${d.at ?? ''} ${d.message}`).join('\n')}`, { diagnostics: compiled.diagnostics });
|
|
122
122
|
}
|
|
123
|
-
|
|
123
|
+
// 按场景保密分享(D75):先裁剪 IR,再生成产物;写错范围在写任何文件之前报错
|
|
124
|
+
let project = compiled.project;
|
|
125
|
+
let scope;
|
|
126
|
+
if (hasScope(opts.scope)) {
|
|
127
|
+
const mode = opts.review === true ? 'review' : 'publish';
|
|
128
|
+
const r = scopeProject(project, resolveScope(project, opts.scope, mode), mode);
|
|
129
|
+
project = r.project;
|
|
130
|
+
scope = r.info;
|
|
131
|
+
}
|
|
124
132
|
const inline = publishPayload(project, compiled.home);
|
|
133
|
+
if (scope)
|
|
134
|
+
inline.scoped = true;
|
|
125
135
|
// 2. vite build 到临时目录
|
|
126
136
|
const staging = fs.mkdtempSync(path.join(os.tmpdir(), 'joplo-build-'));
|
|
127
137
|
let voiceReport;
|
|
@@ -135,12 +145,13 @@ export async function buildSite(opts) {
|
|
|
135
145
|
await buildSourceSite(web, projectDir, staging);
|
|
136
146
|
// 朗读(D74):当前声音已生成的音频拷进 voice/,IR 带上 voiceIndex;Key 不进产物
|
|
137
147
|
const voice = bundleVoice(projectDir, project, staging, new ProfileStore(opts.home ?? joploHome()));
|
|
148
|
+
// 朗读角色只留范围内功能的(scopeProject 对 voiceIndex 的同一规则;bundleVoice 按声音配置生成全部角色)
|
|
138
149
|
if (voice.index)
|
|
139
|
-
inline.project.voiceIndex = voice.index;
|
|
150
|
+
inline.project.voiceIndex = scope ? scopeProject({ ...project, voiceIndex: voice.index }, scope.scenarios).project.voiceIndex : voice.index;
|
|
140
151
|
voiceReport = voice.report;
|
|
141
152
|
// 3. 后处理
|
|
142
153
|
const siteHtml = path.join(staging, 'site.html');
|
|
143
|
-
const { html, inlined } = finalizeHtml(fs.readFileSync(siteHtml, 'utf8'), (rel) => fs.readFileSync(path.join(staging, rel), 'utf8'), inline);
|
|
154
|
+
const { html, inlined } = finalizeHtml(fs.readFileSync(siteHtml, 'utf8'), (rel) => fs.readFileSync(path.join(staging, rel), 'utf8'), inline, stepIdentity(project));
|
|
144
155
|
fs.rmSync(siteHtml);
|
|
145
156
|
for (const rel of inlined)
|
|
146
157
|
fs.rmSync(path.join(staging, rel));
|
|
@@ -167,6 +178,7 @@ export async function buildSite(opts) {
|
|
|
167
178
|
scenarios: Object.keys(project.scenarios),
|
|
168
179
|
diagnostics: compiled.diagnostics,
|
|
169
180
|
...(voiceReport && (voiceReport.clips || voiceReport.profile) ? { voice: voiceReport } : {}),
|
|
181
|
+
...(scope ? { scope } : {}),
|
|
170
182
|
};
|
|
171
183
|
}
|
|
172
184
|
/** 仓库里:直接编译 packages/web 的发布站入口。 */
|
package/dist/cloud.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 看板直接发布到云端(D76)。云端能力(登录、构建、上传)在 CLI 里,由 `joplo dev` 启动看板时注入(CloudBridge);
|
|
3
|
+
* 看板只转发请求、记录发布任务、把进度推给页面。令牌只在本机进程里,页面只拿到账号邮箱和套餐。
|
|
4
|
+
*
|
|
5
|
+
* 数据流:
|
|
6
|
+
* - 账号:`GET /__joplo/cloud/account`(本机令牌)→ bridge.account() → 浮层的“已登录 / 需要登录(可复制的登录命令)”。
|
|
7
|
+
* - 发布:`POST /__joplo/p/<id>/cloud/publish`(令牌 + Origin + JSON,body = 范围)→ bridge.publish()(即 CLI 的 share())
|
|
8
|
+
* → 任务状态(running → done / failed)存在 CloudHub,变化时推 `joplo:cloud`;`GET …/cloud/publish` 读当前任务。
|
|
9
|
+
* - 同一项目同时只有一个发布任务:再次 POST 返回正在进行的那个,不另起。
|
|
10
|
+
* - 旧版 CLI 启动的看板没有 bridge:account 返回 available: false,页面禁用这一项并提示重启 joplo dev。
|
|
11
|
+
*/
|
|
12
|
+
import type http from 'node:http';
|
|
13
|
+
import type { ScopeInfo } from '@joplo-app/core';
|
|
14
|
+
export declare const CLOUD_EVENT = "joplo:cloud";
|
|
15
|
+
export type CloudAccount = {
|
|
16
|
+
signedIn: true;
|
|
17
|
+
server: string;
|
|
18
|
+
email: string;
|
|
19
|
+
plan: 'free' | 'pro' | null;
|
|
20
|
+
} | {
|
|
21
|
+
signedIn: false;
|
|
22
|
+
server: string;
|
|
23
|
+
loginCommand: string;
|
|
24
|
+
message?: string;
|
|
25
|
+
};
|
|
26
|
+
/** 范围:都为空 = 整个项目(D75)。 */
|
|
27
|
+
export type CloudPublishRequest = {
|
|
28
|
+
scenarios?: string[];
|
|
29
|
+
features?: string[];
|
|
30
|
+
};
|
|
31
|
+
export type CloudPublishResult = {
|
|
32
|
+
shareId: string;
|
|
33
|
+
url: string;
|
|
34
|
+
expiresAt: string | null;
|
|
35
|
+
version: number;
|
|
36
|
+
plan: 'free' | 'pro';
|
|
37
|
+
scope?: ScopeInfo;
|
|
38
|
+
};
|
|
39
|
+
/** CLI 实现:account 只读本机登录(必要时问一次云端套餐);publish 就是 share(),progress 是它写给终端的每一行。 */
|
|
40
|
+
export type CloudBridge = {
|
|
41
|
+
account(): Promise<CloudAccount>;
|
|
42
|
+
publish(projectDir: string, request: CloudPublishRequest, progress: (line: string) => void): Promise<CloudPublishResult>;
|
|
43
|
+
};
|
|
44
|
+
/** 发布失败:code 来自 CLI(AUTH_REQUIRED、NOT_FOUND、NETWORK…);需要登录时带 loginCommand。 */
|
|
45
|
+
export type CloudJobError = {
|
|
46
|
+
code: string;
|
|
47
|
+
message: string;
|
|
48
|
+
loginCommand?: string;
|
|
49
|
+
};
|
|
50
|
+
export type CloudJob = {
|
|
51
|
+
id: string;
|
|
52
|
+
state: 'running' | 'done' | 'failed';
|
|
53
|
+
request: CloudPublishRequest;
|
|
54
|
+
startedAt: number;
|
|
55
|
+
/** 进度:CLI 写给终端的行(英文,页面按开头识别阶段)。 */
|
|
56
|
+
lines: string[];
|
|
57
|
+
result?: CloudPublishResult;
|
|
58
|
+
error?: CloudJobError;
|
|
59
|
+
};
|
|
60
|
+
type Ctx = {
|
|
61
|
+
guardWrite: (needJson?: boolean) => boolean;
|
|
62
|
+
jsonBody: () => Promise<{
|
|
63
|
+
ok: true;
|
|
64
|
+
body: unknown;
|
|
65
|
+
} | {
|
|
66
|
+
ok: false;
|
|
67
|
+
}>;
|
|
68
|
+
send: (status: number, body: unknown) => void;
|
|
69
|
+
};
|
|
70
|
+
export declare class CloudHub {
|
|
71
|
+
private readonly bridge;
|
|
72
|
+
private readonly emit;
|
|
73
|
+
private jobs;
|
|
74
|
+
private seq;
|
|
75
|
+
constructor(bridge: CloudBridge | undefined, emit: (projectId: string, job: CloudJob) => void);
|
|
76
|
+
get available(): boolean;
|
|
77
|
+
/** `/__joplo/cloud/<sub>`:sub = 'account'。 */
|
|
78
|
+
handleGlobal(sub: string, req: http.IncomingMessage, ctx: Ctx): Promise<boolean>;
|
|
79
|
+
/** `/__joplo/p/<id>/cloud/<sub>`:sub = 'publish'(GET 读任务,POST 开始发布)。 */
|
|
80
|
+
handleProject(projectId: string, dir: string, sub: string, req: http.IncomingMessage, ctx: Ctx): Promise<boolean>;
|
|
81
|
+
private start;
|
|
82
|
+
/** 测试:等当前任务结束。 */
|
|
83
|
+
settled(projectId: string): Promise<CloudJob | null>;
|
|
84
|
+
}
|
|
85
|
+
export {};
|
package/dist/cloud.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
export const CLOUD_EVENT = 'joplo:cloud';
|
|
2
|
+
const MAX_LINES = 40;
|
|
3
|
+
const strings = (v, name) => {
|
|
4
|
+
if (v === undefined)
|
|
5
|
+
return undefined;
|
|
6
|
+
if (!Array.isArray(v) || v.length > 200 || v.some((x) => typeof x !== 'string' || !x || x.length > 512))
|
|
7
|
+
throw new Error(`${name} must be an array of non-empty strings`);
|
|
8
|
+
return v;
|
|
9
|
+
};
|
|
10
|
+
export class CloudHub {
|
|
11
|
+
bridge;
|
|
12
|
+
emit;
|
|
13
|
+
jobs = new Map();
|
|
14
|
+
seq = 0;
|
|
15
|
+
constructor(bridge, emit) {
|
|
16
|
+
this.bridge = bridge;
|
|
17
|
+
this.emit = emit;
|
|
18
|
+
}
|
|
19
|
+
get available() {
|
|
20
|
+
return !!this.bridge;
|
|
21
|
+
}
|
|
22
|
+
/** `/__joplo/cloud/<sub>`:sub = 'account'。 */
|
|
23
|
+
async handleGlobal(sub, req, ctx) {
|
|
24
|
+
if (sub !== 'account' || (req.method ?? 'GET') !== 'GET')
|
|
25
|
+
return false;
|
|
26
|
+
if (!ctx.guardWrite(false))
|
|
27
|
+
return true;
|
|
28
|
+
if (!this.bridge)
|
|
29
|
+
return ctx.send(200, { available: false }), true;
|
|
30
|
+
try {
|
|
31
|
+
ctx.send(200, { available: true, account: await this.bridge.account() });
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
ctx.send(500, { error: { code: 'INTERNAL', message: e instanceof Error ? e.message : String(e) } });
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
/** `/__joplo/p/<id>/cloud/<sub>`:sub = 'publish'(GET 读任务,POST 开始发布)。 */
|
|
39
|
+
async handleProject(projectId, dir, sub, req, ctx) {
|
|
40
|
+
if (sub !== 'publish')
|
|
41
|
+
return false;
|
|
42
|
+
const method = req.method ?? 'GET';
|
|
43
|
+
if (method === 'GET') {
|
|
44
|
+
if (!ctx.guardWrite(false))
|
|
45
|
+
return true;
|
|
46
|
+
ctx.send(200, { available: this.available, job: this.jobs.get(projectId) ?? null });
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
if (method !== 'POST')
|
|
50
|
+
return false;
|
|
51
|
+
if (!ctx.guardWrite())
|
|
52
|
+
return true;
|
|
53
|
+
if (!this.bridge)
|
|
54
|
+
return ctx.send(409, { error: { code: 'UNSUPPORTED_ACTION', message: 'This board process cannot publish to the cloud. Stop it and run joplo dev again' } }), true;
|
|
55
|
+
const b = await ctx.jsonBody();
|
|
56
|
+
if (!b.ok)
|
|
57
|
+
return true;
|
|
58
|
+
let request;
|
|
59
|
+
try {
|
|
60
|
+
const body = (b.body ?? {});
|
|
61
|
+
const scenarios = strings(body.scenarios, 'scenarios');
|
|
62
|
+
const features = strings(body.features, 'features');
|
|
63
|
+
request = { ...(scenarios?.length ? { scenarios } : {}), ...(features?.length ? { features } : {}) };
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
return ctx.send(400, { error: { code: 'USAGE', message: e instanceof Error ? e.message : String(e) } }), true;
|
|
67
|
+
}
|
|
68
|
+
const running = this.jobs.get(projectId);
|
|
69
|
+
if (running?.state === 'running')
|
|
70
|
+
return ctx.send(200, { job: running }), true;
|
|
71
|
+
ctx.send(202, { job: this.start(projectId, dir, request) });
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
start(projectId, dir, request) {
|
|
75
|
+
const job = { id: `c${++this.seq}`, state: 'running', request, startedAt: Date.now(), lines: [] };
|
|
76
|
+
this.jobs.set(projectId, job);
|
|
77
|
+
const push = () => this.emit(projectId, job);
|
|
78
|
+
push();
|
|
79
|
+
void this.bridge
|
|
80
|
+
.publish(dir, request, (line) => {
|
|
81
|
+
job.lines = [...job.lines, line].slice(-MAX_LINES);
|
|
82
|
+
push();
|
|
83
|
+
})
|
|
84
|
+
.then((result) => {
|
|
85
|
+
job.state = 'done';
|
|
86
|
+
job.result = result;
|
|
87
|
+
})
|
|
88
|
+
.catch((e) => {
|
|
89
|
+
const err = e;
|
|
90
|
+
job.state = 'failed';
|
|
91
|
+
job.error = {
|
|
92
|
+
code: typeof err.code === 'string' ? err.code : 'INTERNAL',
|
|
93
|
+
message: typeof err.message === 'string' ? err.message : String(e),
|
|
94
|
+
...(typeof err.loginCommand === 'string' ? { loginCommand: err.loginCommand } : {}),
|
|
95
|
+
};
|
|
96
|
+
})
|
|
97
|
+
.finally(push);
|
|
98
|
+
return job;
|
|
99
|
+
}
|
|
100
|
+
/** 测试:等当前任务结束。 */
|
|
101
|
+
async settled(projectId) {
|
|
102
|
+
for (let i = 0; i < 2000; i++) {
|
|
103
|
+
const j = this.jobs.get(projectId);
|
|
104
|
+
if (!j || j.state !== 'running')
|
|
105
|
+
return j ?? null;
|
|
106
|
+
await new Promise((r) => setTimeout(r, 5));
|
|
107
|
+
}
|
|
108
|
+
return this.jobs.get(projectId) ?? null;
|
|
109
|
+
}
|
|
110
|
+
}
|
package/dist/contract.d.ts
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* v2 接口(ADR-0002):CLI 只依赖这里导出的三个函数。由 T-board 实现,届时 index.ts 改为导出它们。
|
|
3
3
|
*/
|
|
4
|
-
import type { AppearanceFont, AppearanceStroke, Diagnostic } from '@joplo-app/core';
|
|
4
|
+
import type { AppearanceFont, AppearanceStroke, Diagnostic, ScopeInfo, ScopeRequest } from '@joplo-app/core';
|
|
5
|
+
import type { CloudBridge } from './cloud.js';
|
|
6
|
+
export type { CloudAccount, CloudBridge, CloudJob, CloudJobError, CloudPublishRequest, CloudPublishResult } from './cloud.js';
|
|
5
7
|
export type DevOptions = {
|
|
6
8
|
projectDir: string;
|
|
7
9
|
/** 缺省 4790;被占用时报错,不静默换端口。 */
|
|
8
10
|
port?: number;
|
|
9
11
|
open?: boolean;
|
|
10
12
|
log?: (line: string) => void;
|
|
13
|
+
/**
|
|
14
|
+
* 直接发布到云端(D76):CLI 注入登录与 share();看板「导出 ▾」里的「发布到 Joplo Cloud」用它。
|
|
15
|
+
* 只在本进程启动看板时生效(加入已有看板时,那个进程用它自己的)。
|
|
16
|
+
*/
|
|
17
|
+
cloud?: CloudBridge;
|
|
11
18
|
};
|
|
12
19
|
/** 单进程:同一个 JOPLO_HOME 下只有一个看板进程,同时服务多个项目(编译、热更新、选中、导出)。 */
|
|
13
20
|
/**
|
|
@@ -32,6 +39,11 @@ export type BuildOptions = {
|
|
|
32
39
|
review?: boolean;
|
|
33
40
|
/** 本机目录(缺省 JOPLO_HOME 或 ~/.joplo):读声音供应商 profile(D74);测试指向临时目录。 */
|
|
34
41
|
home?: string;
|
|
42
|
+
/**
|
|
43
|
+
* 按场景保密分享(D75,`--scenario` / `--feature`):构建时把 IR 裁剪到这些场景,产物里不出现范围外的功能、方案、场景。
|
|
44
|
+
* 缺省(或两个数组都为空)时与原来完全一致。写错场景 / 功能时报错,不写任何文件。
|
|
45
|
+
*/
|
|
46
|
+
scope?: ScopeRequest;
|
|
35
47
|
};
|
|
36
48
|
/** 静态发布站:只含选定方案(compile 的 publish 模式),离线可打开,可直接 `wrangler deploy`。 */
|
|
37
49
|
/**
|
|
@@ -49,7 +61,8 @@ export type BuildResult = {
|
|
|
49
61
|
bytes: number;
|
|
50
62
|
missing: number;
|
|
51
63
|
profile: string | null;
|
|
52
|
-
};
|
|
64
|
+
}; /** 有 scope 时:范围与借用了哪些别的功能的内容(D75)。 */
|
|
65
|
+
scope?: ScopeInfo;
|
|
53
66
|
};
|
|
54
67
|
export declare function buildSite(opts: BuildOptions): Promise<BuildResult>;
|
|
55
68
|
export type RenderOptions = {
|
|
@@ -73,6 +86,8 @@ export type RenderOptions = {
|
|
|
73
86
|
height: number;
|
|
74
87
|
};
|
|
75
88
|
scale?: number;
|
|
89
|
+
/** 按场景保密分享(D75):只用这些场景裁剪后的 IR 渲染(share 的预览图),画面上不出现范围外功能堆进来的元素。 */
|
|
90
|
+
scope?: string[];
|
|
76
91
|
};
|
|
77
92
|
export type RenderedElement = {
|
|
78
93
|
id: string;
|
package/dist/dev.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { type ViteDevServer } from 'vite';
|
|
|
3
3
|
import { type Diagnostic, type Project } from '@joplo-app/core';
|
|
4
4
|
import type { DevHandle, DevOptions } from './contract.js';
|
|
5
5
|
import { type ExportDeps } from './export.js';
|
|
6
|
+
import { CLOUD_EVENT, type CloudBridge } from './cloud.js';
|
|
6
7
|
import type { DistWeb } from './web-assets.js';
|
|
7
8
|
/** 推给看板的编译结果。`project` 始终是最近一次成功的 IR;`ok=false` 时看板显示错误列表、保留画面。 */
|
|
8
9
|
export type DevPayload = {
|
|
@@ -26,6 +27,7 @@ export declare const IR_EVENT = "joplo:ir";
|
|
|
26
27
|
export declare const PROJECTS_EVENT = "joplo:projects";
|
|
27
28
|
/** 朗读状态变化(D74):{ projectId, state }。 */
|
|
28
29
|
export declare const VOICE_EVENT = "joplo:voice";
|
|
30
|
+
export { CLOUD_EVENT };
|
|
29
31
|
export declare function sendJson(res: http.ServerResponse, status: number, body: unknown): void;
|
|
30
32
|
/** Content-Type 必须是 application/json,只允许附带 charset=utf-8 参数。 */
|
|
31
33
|
export declare function isJsonContentType(ct: string | undefined): boolean;
|
|
@@ -56,6 +58,8 @@ export type HubOptions = {
|
|
|
56
58
|
exportDeps?: Partial<ExportDeps>;
|
|
57
59
|
/** 启动这个看板的项目目录(写进 server.json,后来加入的 joplo dev 会说明)。 */
|
|
58
60
|
startedIn?: string;
|
|
61
|
+
/** 直接发布到云端(D76):由 CLI 注入;没有时看板禁用「发布到 Joplo Cloud」。 */
|
|
62
|
+
cloud?: CloudBridge;
|
|
59
63
|
};
|
|
60
64
|
export declare function serverVersion(): string;
|
|
61
65
|
export type Hub = {
|
|
@@ -77,7 +81,7 @@ export type Hub = {
|
|
|
77
81
|
close(): Promise<void>;
|
|
78
82
|
};
|
|
79
83
|
export declare function createHub(opts?: HubOptions): Promise<Hub>;
|
|
80
|
-
export type InternalDevOptions = DevOptions & Pick<HubOptions, 'watch' | 'home' | 'exportDeps'>;
|
|
84
|
+
export type InternalDevOptions = DevOptions & Pick<HubOptions, 'watch' | 'home' | 'exportDeps' | 'cloud'>;
|
|
81
85
|
export type InternalDevHandle = DevHandle & {
|
|
82
86
|
token: string;
|
|
83
87
|
port: number;
|
package/dist/dev.js
CHANGED
|
@@ -18,9 +18,11 @@ import fs from 'node:fs';
|
|
|
18
18
|
import path from 'node:path';
|
|
19
19
|
import tailwindcss from '@tailwindcss/vite';
|
|
20
20
|
import { createLogger, createServer } from 'vite';
|
|
21
|
-
import { JoploError } from '@joplo-app/core';
|
|
21
|
+
import { JoploError, LocalReviewWrite } from '@joplo-app/core';
|
|
22
|
+
import { LocalReviewHub } from "./local-review.js";
|
|
22
23
|
import { ExportHub } from "./export.js";
|
|
23
24
|
import { VoiceHub } from "./voice-http.js";
|
|
25
|
+
import { CLOUD_EVENT, CloudHub } from "./cloud.js";
|
|
24
26
|
import { Registry, clearServerInfo, joploHome, normalizeSettings, pidAlive, projectIdOf, readServerInfo, readSettings, writeServerInfo, writeSettings } from "./home.js";
|
|
25
27
|
import { compileProject, invalidateProjectModules } from "./project.js";
|
|
26
28
|
import { SelectionBody, readSelection, resolveSelection, writeSelection } from "./selection.js";
|
|
@@ -29,6 +31,7 @@ export const IR_EVENT = 'joplo:ir';
|
|
|
29
31
|
export const PROJECTS_EVENT = 'joplo:projects';
|
|
30
32
|
/** 朗读状态变化(D74):{ projectId, state }。 */
|
|
31
33
|
export const VOICE_EVENT = 'joplo:voice';
|
|
34
|
+
export { CLOUD_EVENT };
|
|
32
35
|
const MAX_BODY = 64 * 1024;
|
|
33
36
|
const SECURITY_HEADERS = {
|
|
34
37
|
'x-content-type-options': 'nosniff',
|
|
@@ -174,6 +177,7 @@ export async function createHub(opts = {}) {
|
|
|
174
177
|
const allowedHosts = () => new Set([`127.0.0.1:${actualPort}`, `localhost:${actualPort}`]);
|
|
175
178
|
const allowedOrigins = () => new Set([`http://127.0.0.1:${actualPort}`, `http://localhost:${actualPort}`]);
|
|
176
179
|
const baseUrl = () => `http://127.0.0.1:${actualPort}/`;
|
|
180
|
+
const reviewHub = new LocalReviewHub(baseUrl);
|
|
177
181
|
const activeDirs = () => [...slots.values()].filter((s) => !s.closed).map((s) => s.dir);
|
|
178
182
|
const slotOfFile = (file) => [...slots.values()].find((s) => !s.closed && isProjectSource(s.dir, file)) ?? null;
|
|
179
183
|
const recordOf = (id) => registry.list().find((r) => projectIdOf(r.dir) === id) ?? null;
|
|
@@ -216,6 +220,10 @@ export async function createHub(opts = {}) {
|
|
|
216
220
|
log(`[joplo] ${path.basename(slot.dir)} compilation failed (${errors.length}): ${errors.map((d) => `${d.at ?? ''} ${d.message}`).join('; ').slice(0, 400)}`);
|
|
217
221
|
if (out.project && out.project.name)
|
|
218
222
|
registry.rename(slot.dir, out.project.name);
|
|
223
|
+
if (out.project && !errors.length)
|
|
224
|
+
reviewHub.sync(slot.dir, slot.id, out.project);
|
|
225
|
+
else
|
|
226
|
+
reviewHub.invalidate(slot.dir, 'compile_error');
|
|
219
227
|
if (!closed)
|
|
220
228
|
server?.ws.send({ type: 'custom', event: IR_EVENT, data: { projectId: slot.id, ...slot.payload } });
|
|
221
229
|
broadcastProjects();
|
|
@@ -236,6 +244,7 @@ export async function createHub(opts = {}) {
|
|
|
236
244
|
await recompile(slot);
|
|
237
245
|
}
|
|
238
246
|
catch (e) {
|
|
247
|
+
reviewHub.invalidate(slot.dir, 'compile_error');
|
|
239
248
|
log(`[joplo] Compilation exception: ${e instanceof Error ? e.message : String(e)}`);
|
|
240
249
|
}
|
|
241
250
|
} while (slot.dirty && !slot.closed);
|
|
@@ -277,6 +286,7 @@ export async function createHub(opts = {}) {
|
|
|
277
286
|
if (slot.timer)
|
|
278
287
|
clearTimeout(slot.timer);
|
|
279
288
|
await slot.running?.catch(() => undefined);
|
|
289
|
+
reviewHub.invalidate(slot.dir, 'server_stopped');
|
|
280
290
|
await slot.loader?.close().catch(() => undefined);
|
|
281
291
|
if (watch && server)
|
|
282
292
|
server.watcher.unwatch(slot.dir);
|
|
@@ -331,6 +341,16 @@ export async function createHub(opts = {}) {
|
|
|
331
341
|
if (!closed)
|
|
332
342
|
server?.ws.send({ type: 'custom', event: VOICE_EVENT, data: { projectId, state } });
|
|
333
343
|
},
|
|
344
|
+
// profile 是本机共用的:改了就通知所有看板,各自重新取自己项目的声音状态
|
|
345
|
+
profilesChanged: () => {
|
|
346
|
+
if (!closed)
|
|
347
|
+
server?.ws.send({ type: 'custom', event: VOICE_EVENT, data: { profilesChanged: true } });
|
|
348
|
+
},
|
|
349
|
+
});
|
|
350
|
+
// 直接发布到云端(D76):发布任务变化推 joplo:cloud
|
|
351
|
+
const cloudHub = new CloudHub(opts.cloud, (projectId, job) => {
|
|
352
|
+
if (!closed)
|
|
353
|
+
server?.ws.send({ type: 'custom', event: CLOUD_EVENT, data: { projectId, job } });
|
|
334
354
|
});
|
|
335
355
|
// ---------- HTTP ----------
|
|
336
356
|
const deny = (res, status, message) => sendJson(res, status, { error: { code: 'PERMISSION_DENIED', message } });
|
|
@@ -359,11 +379,31 @@ export async function createHub(opts = {}) {
|
|
|
359
379
|
};
|
|
360
380
|
const fail = (res, e) => {
|
|
361
381
|
const code = e instanceof JoploError ? e.code : 'INTERNAL';
|
|
362
|
-
const status = code === 'NOT_FOUND' ? 404 : code === 'USAGE' ? 400 : code === 'RENDER_FAILED' || code === 'EXPORT_COMPONENT_MISSING' ? 503 : 500;
|
|
382
|
+
const status = code === 'NOT_FOUND' ? 404 : code === 'USAGE' || code === 'INVALID_REFERENCE' ? 400 : code === 'REVISION_CONFLICT' || code === 'IDEMPOTENCY_MISMATCH' ? 409 : code === 'RENDER_FAILED' || code === 'EXPORT_COMPONENT_MISSING' ? 503 : 500;
|
|
363
383
|
sendJson(res, status, { error: { code, message: e instanceof Error ? e.message : String(e) } });
|
|
364
384
|
};
|
|
365
385
|
async function handleProject(id, rest, req, res) {
|
|
366
386
|
const method = req.method ?? 'GET';
|
|
387
|
+
if (rest === 'review' && (method === 'GET' || method === 'POST')) {
|
|
388
|
+
if (!guardWrite(req, res, 403, method === 'POST'))
|
|
389
|
+
return;
|
|
390
|
+
const slot = await ensure(id);
|
|
391
|
+
if (slot.compiling || slot.dirty || slot.timer || !slot.payload.ok || !slot.payload.project || slot.payload.diagnostics.some(d => d.severity === 'error'))
|
|
392
|
+
throw new JoploError('REVISION_CONFLICT', 'Wait for the project to compile successfully before reviewing');
|
|
393
|
+
if (method === 'GET') {
|
|
394
|
+
const optionId = new URL(req.url, baseUrl()).searchParams.get('option');
|
|
395
|
+
if (!optionId)
|
|
396
|
+
throw new JoploError('USAGE', 'option is required');
|
|
397
|
+
return sendJson(res, 200, reviewHub.state(slot.dir, optionId));
|
|
398
|
+
}
|
|
399
|
+
const body = await jsonBody(req, res);
|
|
400
|
+
if (!body.ok)
|
|
401
|
+
return;
|
|
402
|
+
const input = LocalReviewWrite.safeParse(body.body);
|
|
403
|
+
if (!input.success)
|
|
404
|
+
throw new JoploError('USAGE', 'Invalid review request: include a sessionId, requestId, type, and page context for feedback (1–10000 characters)');
|
|
405
|
+
return sendJson(res, 200, reviewHub.write(slot.dir, slot.payload.project, input.data));
|
|
406
|
+
}
|
|
367
407
|
if (rest === 'ir' && method === 'GET') {
|
|
368
408
|
const slot = await ensure(id);
|
|
369
409
|
return sendJson(res, 200, { projectId: id, ...slot.payload });
|
|
@@ -422,6 +462,12 @@ export async function createHub(opts = {}) {
|
|
|
422
462
|
if (await voiceHub.handleProject(id, slot.dir, slot.payload.project, rest === 'voice' ? '' : rest.slice('voice/'.length), req, res, ctx))
|
|
423
463
|
return;
|
|
424
464
|
}
|
|
465
|
+
if (rest.startsWith('cloud/')) {
|
|
466
|
+
const slot = await ensure(id);
|
|
467
|
+
const ctx = { guardWrite: (needJson = true) => guardWrite(req, res, 403, needJson), jsonBody: () => jsonBody(req, res), send: (status, body) => sendJson(res, status, body) };
|
|
468
|
+
if (await cloudHub.handleProject(id, slot.dir, rest.slice('cloud/'.length), req, ctx))
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
425
471
|
if (rest.startsWith('export/')) {
|
|
426
472
|
const slot = await ensure(id);
|
|
427
473
|
return exportsHub.handle(rest.slice('export/'.length), req, res, { projectId: id, dir: slot.dir, project: slot.payload.project, guardWrite: (needJson = true) => guardWrite(req, res, 403, needJson), jsonBody: () => jsonBody(req, res), fail: (e) => fail(res, e) });
|
|
@@ -495,6 +541,11 @@ export async function createHub(opts = {}) {
|
|
|
495
541
|
if (await voiceHub.handleGlobal(url.pathname.slice('/__joplo/voice/'.length), req, ctx))
|
|
496
542
|
return;
|
|
497
543
|
}
|
|
544
|
+
if (url.pathname.startsWith('/__joplo/cloud/')) {
|
|
545
|
+
const ctx = { guardWrite: (needJson = true) => guardWrite(req, res, 403, needJson), jsonBody: () => jsonBody(req, res), send: (status, body) => sendJson(res, status, body) };
|
|
546
|
+
if (await cloudHub.handleGlobal(url.pathname.slice('/__joplo/cloud/'.length), req, ctx))
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
498
549
|
if (url.pathname.startsWith('/__joplo/export-runtime/'))
|
|
499
550
|
return exportsHub.handleRuntime(url.pathname.slice('/__joplo/export-runtime/'.length), req, res, { guardWrite: (needJson = true) => guardWrite(req, res, 403, needJson), jsonBody: () => jsonBody(req, res), fail: (e) => fail(res, e) });
|
|
500
551
|
const pm = /^\/__joplo\/p\/([^/]+)\/(.+)$/.exec(url.pathname);
|
|
@@ -573,9 +624,10 @@ export async function createHub(opts = {}) {
|
|
|
573
624
|
const slot = slotOfFile(path.resolve(file));
|
|
574
625
|
if (!slot)
|
|
575
626
|
return;
|
|
627
|
+
reviewHub.invalidate(slot.dir, 'source_changed');
|
|
576
628
|
if (slot.timer)
|
|
577
629
|
clearTimeout(slot.timer);
|
|
578
|
-
slot.timer = setTimeout(() => void run(slot), 60);
|
|
630
|
+
slot.timer = setTimeout(() => { slot.timer = null; void run(slot); }, 60);
|
|
579
631
|
});
|
|
580
632
|
}
|
|
581
633
|
return {
|
|
@@ -604,7 +656,7 @@ export async function createHub(opts = {}) {
|
|
|
604
656
|
}
|
|
605
657
|
/** 启动一个看板进程并打开一个项目(等首次编译完成)。缺省不持久化。 */
|
|
606
658
|
export async function createDev(opts) {
|
|
607
|
-
const hub = await createHub({ port: opts.port, log: opts.log, watch: opts.watch, home: opts.home ?? null, exportDeps: opts.exportDeps });
|
|
659
|
+
const hub = await createHub({ port: opts.port, log: opts.log, watch: opts.watch, home: opts.home ?? null, exportDeps: opts.exportDeps, cloud: opts.cloud });
|
|
608
660
|
try {
|
|
609
661
|
const { id, url, slot } = hub.addProject(opts.projectDir);
|
|
610
662
|
await slot.ready;
|
|
@@ -687,7 +739,7 @@ export async function startDev(opts) {
|
|
|
687
739
|
return existing;
|
|
688
740
|
let hub;
|
|
689
741
|
try {
|
|
690
|
-
hub = await createHub({ port: opts.port, log, home, exportDeps: opts.exportDeps, startedIn: projectDir });
|
|
742
|
+
hub = await createHub({ port: opts.port, log, home, exportDeps: opts.exportDeps, startedIn: projectDir, cloud: opts.cloud });
|
|
691
743
|
}
|
|
692
744
|
catch (e) {
|
|
693
745
|
// 另一个 joplo dev 恰好同时启动:端口被它占了,改为加入它
|