@joplo-app/server 0.1.2 → 0.2.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/dist/build.js +9 -9
- package/dist/contract.d.ts +7 -1
- package/dist/dev.js +28 -28
- package/dist/export.d.ts +10 -3
- package/dist/export.js +61 -27
- package/dist/home.d.ts +16 -8
- package/dist/home.js +21 -13
- package/dist/locale.d.ts +4 -0
- package/dist/locale.js +5 -0
- package/dist/page-report.js +8 -8
- package/dist/project.js +1 -1
- package/dist/render.d.ts +18 -0
- package/dist/render.js +30 -12
- package/dist/selection.js +12 -12
- package/dist/vite-shared.js +1 -1
- package/dist/web-assets.js +7 -7
- package/package.json +4 -4
package/dist/build.js
CHANGED
|
@@ -78,18 +78,18 @@ function realish(p) {
|
|
|
78
78
|
export async function buildSite(opts) {
|
|
79
79
|
const projectDir = realProjectDir(opts.projectDir);
|
|
80
80
|
if (!fs.existsSync(projectDir))
|
|
81
|
-
throw new JoploError('NOT_FOUND',
|
|
81
|
+
throw new JoploError('NOT_FOUND', `Project directory does not exist: ${projectDir}`);
|
|
82
82
|
const outDir = realish(opts.outDir ?? path.join(projectDir, 'dist'));
|
|
83
83
|
// 目标目录安全检查(先于任何耗时工作)
|
|
84
84
|
if (outDir === projectDir || projectDir.startsWith(outDir + path.sep) || outDir === os.homedir() || outDir === path.parse(outDir).root)
|
|
85
|
-
throw new JoploError('USAGE',
|
|
85
|
+
throw new JoploError('USAGE', `Cannot write the published site to ${outDir}: it is the project directory or its parent`);
|
|
86
86
|
if (outDir === path.join(projectDir, '.joplo') || outDir.startsWith(path.join(projectDir, '.joplo') + path.sep))
|
|
87
|
-
throw new JoploError('USAGE',
|
|
87
|
+
throw new JoploError('USAGE', `Cannot write to .joplo/: ${outDir}`);
|
|
88
88
|
const nonEmpty = fs.existsSync(outDir) && (!fs.statSync(outDir).isDirectory() || fs.readdirSync(outDir).length > 0);
|
|
89
89
|
if (nonEmpty && !opts.overwrite)
|
|
90
|
-
throw new JoploError('USAGE',
|
|
90
|
+
throw new JoploError('USAGE', `Output directory is not empty: ${outDir}. After confirming it can be cleared, pass overwrite: true (CLI: --overwrite)`);
|
|
91
91
|
if (nonEmpty && fs.existsSync(path.join(outDir, 'joplo.config.ts')))
|
|
92
|
-
throw new JoploError('USAGE',
|
|
92
|
+
throw new JoploError('USAGE', `Output directory appears to be a Joplo project (contains joplo.config.ts); refusing to clear: ${outDir}`);
|
|
93
93
|
const web = locateWebAssets();
|
|
94
94
|
// 1. 编译(publish)
|
|
95
95
|
const loader = await createServer({
|
|
@@ -112,7 +112,7 @@ export async function buildSite(opts) {
|
|
|
112
112
|
}
|
|
113
113
|
if (!compiled.project) {
|
|
114
114
|
const errs = compiled.diagnostics.filter((d) => d.severity === 'error');
|
|
115
|
-
throw new JoploError('EXPORT_FAILED',
|
|
115
|
+
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 });
|
|
116
116
|
}
|
|
117
117
|
const project = compiled.project;
|
|
118
118
|
const inline = publishPayload(project, compiled.home);
|
|
@@ -132,7 +132,7 @@ export async function buildSite(opts) {
|
|
|
132
132
|
fs.rmSync(siteHtml);
|
|
133
133
|
for (const rel of inlined)
|
|
134
134
|
fs.rmSync(path.join(staging, rel));
|
|
135
|
-
fs.writeFileSync(path.join(staging, 'index.html'), html.replace(
|
|
135
|
+
fs.writeFileSync(path.join(staging, 'index.html'), html.replace(/<title>[^<]*<\/title>/i, () => `<title>${escapeHtml(project.name)} · Joplo</title>`));
|
|
136
136
|
// 4. 写入目标目录
|
|
137
137
|
if (fs.existsSync(outDir))
|
|
138
138
|
fs.rmSync(outDir, { recursive: true, force: true });
|
|
@@ -201,14 +201,14 @@ export async function stageDistSite(web, projectDir, staging) {
|
|
|
201
201
|
}));
|
|
202
202
|
const files = (Array.isArray(out) ? out : [out]).flatMap((o) => o.output.map((x) => x.fileName)).filter((f) => f.endsWith('.css'));
|
|
203
203
|
if (files.length !== 1)
|
|
204
|
-
throw new JoploError('EXPORT_FAILED',
|
|
204
|
+
throw new JoploError('EXPORT_FAILED', `Unexpected stylesheet compilation result for author className: ${files.join(', ') || 'No CSS'}`);
|
|
205
205
|
const rel = `assets/${path.basename(files[0])}`;
|
|
206
206
|
fs.mkdirSync(path.join(staging, 'assets'), { recursive: true });
|
|
207
207
|
fs.copyFileSync(path.join(cssOut, files[0]), path.join(staging, rel));
|
|
208
208
|
const siteHtml = path.join(staging, 'site.html');
|
|
209
209
|
const html = fs.readFileSync(siteHtml, 'utf8');
|
|
210
210
|
if (!html.includes('</head>'))
|
|
211
|
-
throw new JoploError('EXPORT_FAILED', '
|
|
211
|
+
throw new JoploError('EXPORT_FAILED', 'Prebuilt site.html is missing </head>');
|
|
212
212
|
fs.writeFileSync(siteHtml, html.replace('</head>', ` <link rel="stylesheet" href="./${rel}">\n </head>`));
|
|
213
213
|
}
|
|
214
214
|
finally {
|
package/dist/contract.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* v2 接口(ADR-0002):CLI 只依赖这里导出的三个函数。由 T-board 实现,届时 index.ts 改为导出它们。
|
|
3
3
|
*/
|
|
4
|
-
import type { Diagnostic } from '@joplo-app/core';
|
|
4
|
+
import type { AppearanceFont, AppearanceStroke, Diagnostic } from '@joplo-app/core';
|
|
5
5
|
export type DevOptions = {
|
|
6
6
|
projectDir: string;
|
|
7
7
|
/** 缺省 4790;被占用时报错,不静默换端口。 */
|
|
@@ -42,6 +42,12 @@ export type RenderOptions = {
|
|
|
42
42
|
stepId?: string;
|
|
43
43
|
/** 主题名(D51):内置主题或项目 themes/<name>.css;缺省用项目配置的主题。 */
|
|
44
44
|
theme?: string;
|
|
45
|
+
/** UI language for the standalone render route. Unsupported values are ignored. */
|
|
46
|
+
locale?: string;
|
|
47
|
+
/** 字体(D55):hand / sans / serif / kai / mono;缺省跟随主题。 */
|
|
48
|
+
font?: AppearanceFont | null;
|
|
49
|
+
/** 线条(D55):rough / clean;缺省跟随主题。 */
|
|
50
|
+
stroke?: AppearanceStroke | null;
|
|
45
51
|
out: string;
|
|
46
52
|
overwrite?: boolean;
|
|
47
53
|
/** 截图尺寸(D44):舞台宽度仍是页面自己的 viewport,按比例放进这个尺寸。缺省为舞台尺寸。 */
|
package/dist/dev.js
CHANGED
|
@@ -56,7 +56,7 @@ function readBody(req) {
|
|
|
56
56
|
size += c.length;
|
|
57
57
|
if (size > MAX_BODY * 16) {
|
|
58
58
|
req.destroy();
|
|
59
|
-
reject(new Error('
|
|
59
|
+
reject(new Error('Request body is too large'));
|
|
60
60
|
}
|
|
61
61
|
else if (size <= MAX_BODY)
|
|
62
62
|
chunks.push(c);
|
|
@@ -196,7 +196,7 @@ export async function createHub(opts = {}) {
|
|
|
196
196
|
slot.payload = { version: prev.version + 1, ok: out.project !== null, project: out.project ?? prev.project, diagnostics: out.diagnostics, home: out.home ?? prev.home };
|
|
197
197
|
const errors = out.diagnostics.filter((d) => d.severity === 'error');
|
|
198
198
|
if (errors.length)
|
|
199
|
-
log(`[joplo] ${path.basename(slot.dir)}
|
|
199
|
+
log(`[joplo] ${path.basename(slot.dir)} compilation failed (${errors.length}): ${errors.map((d) => `${d.at ?? ''} ${d.message}`).join('; ').slice(0, 400)}`);
|
|
200
200
|
if (out.project && out.project.name)
|
|
201
201
|
registry.rename(slot.dir, out.project.name);
|
|
202
202
|
if (!closed)
|
|
@@ -219,7 +219,7 @@ export async function createHub(opts = {}) {
|
|
|
219
219
|
await recompile(slot);
|
|
220
220
|
}
|
|
221
221
|
catch (e) {
|
|
222
|
-
log(`[joplo]
|
|
222
|
+
log(`[joplo] Compilation exception: ${e instanceof Error ? e.message : String(e)}`);
|
|
223
223
|
}
|
|
224
224
|
} while (slot.dirty && !slot.closed);
|
|
225
225
|
})().finally(() => {
|
|
@@ -251,7 +251,7 @@ export async function createHub(opts = {}) {
|
|
|
251
251
|
if (watch && server)
|
|
252
252
|
server.watcher.add(dir);
|
|
253
253
|
await run(slot);
|
|
254
|
-
})().catch((e) => log(`[joplo]
|
|
254
|
+
})().catch((e) => log(`[joplo] Project startup failed: ${e instanceof Error ? e.message : String(e)}`));
|
|
255
255
|
invalidateCss();
|
|
256
256
|
return slot;
|
|
257
257
|
}
|
|
@@ -282,9 +282,9 @@ export async function createHub(opts = {}) {
|
|
|
282
282
|
if (!slot) {
|
|
283
283
|
const rec = recordOf(id);
|
|
284
284
|
if (!rec)
|
|
285
|
-
throw new JoploError('NOT_FOUND',
|
|
285
|
+
throw new JoploError('NOT_FOUND', `Unknown project: ${id}`);
|
|
286
286
|
if (!fs.existsSync(rec.dir))
|
|
287
|
-
throw new JoploError('NOT_FOUND',
|
|
287
|
+
throw new JoploError('NOT_FOUND', `Project directory not found: ${rec.dir}`);
|
|
288
288
|
slot = activate(rec.dir);
|
|
289
289
|
}
|
|
290
290
|
await slot.ready;
|
|
@@ -293,7 +293,7 @@ export async function createHub(opts = {}) {
|
|
|
293
293
|
function addProject(dirIn, o = {}) {
|
|
294
294
|
const dir = realProjectDir(dirIn);
|
|
295
295
|
if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory())
|
|
296
|
-
throw new JoploError('NOT_FOUND',
|
|
296
|
+
throw new JoploError('NOT_FOUND', `Project directory does not exist: ${dir}`);
|
|
297
297
|
const id = projectIdOf(dir);
|
|
298
298
|
const prev = registry.list().find((r) => r.dir === dir);
|
|
299
299
|
registry.touch(dir, prev?.name);
|
|
@@ -313,23 +313,23 @@ export async function createHub(opts = {}) {
|
|
|
313
313
|
const guardWrite = (req, res, tokenStatus = 403, needJson = true) => {
|
|
314
314
|
const origin = req.headers.origin;
|
|
315
315
|
if (origin !== undefined && !allowedOrigins().has(origin))
|
|
316
|
-
return deny(res, 403, `Origin
|
|
316
|
+
return deny(res, 403, `Origin is not allowed: ${origin}`), false;
|
|
317
317
|
const t = req.headers['x-joplo-token'];
|
|
318
318
|
if (typeof t !== 'string' || !safeEqual(t, token))
|
|
319
|
-
return deny(res, tokenStatus, '
|
|
319
|
+
return deny(res, tokenStatus, 'Missing or invalid local token (x-joplo-token)'), false;
|
|
320
320
|
if (needJson && !isJsonContentType(req.headers['content-type']))
|
|
321
|
-
return sendJson(res, 415, { error: { code: 'USAGE', message: 'Content-Type
|
|
321
|
+
return sendJson(res, 415, { error: { code: 'USAGE', message: 'Content-Type must be application/json' } }), false;
|
|
322
322
|
return true;
|
|
323
323
|
};
|
|
324
324
|
const jsonBody = async (req, res) => {
|
|
325
325
|
const raw = await readBody(req);
|
|
326
326
|
if (raw.tooLarge)
|
|
327
|
-
return sendJson(res, 413, { error: { code: 'USAGE', message:
|
|
327
|
+
return sendJson(res, 413, { error: { code: 'USAGE', message: `Request body is too large (limit: ${MAX_BODY} bytes)` } }), { ok: false };
|
|
328
328
|
try {
|
|
329
329
|
return { ok: true, body: JSON.parse(raw.text) };
|
|
330
330
|
}
|
|
331
331
|
catch (e) {
|
|
332
|
-
return sendJson(res, 400, { error: { code: 'USAGE', message:
|
|
332
|
+
return sendJson(res, 400, { error: { code: 'USAGE', message: `Request body is not valid JSON: ${e instanceof Error ? e.message : String(e)}` } }), { ok: false };
|
|
333
333
|
}
|
|
334
334
|
};
|
|
335
335
|
const fail = (res, e) => {
|
|
@@ -355,18 +355,18 @@ export async function createHub(opts = {}) {
|
|
|
355
355
|
return;
|
|
356
356
|
const parsed = SelectionBody.safeParse(b.body);
|
|
357
357
|
if (!parsed.success)
|
|
358
|
-
return sendJson(res, 400, { error: { code: 'USAGE', message: '
|
|
358
|
+
return sendJson(res, 400, { error: { code: 'USAGE', message: 'Invalid selection format', issues: parsed.error.issues.map((i) => ({ path: i.path.join('.'), message: i.message })) } });
|
|
359
359
|
const slot = await ensure(id);
|
|
360
360
|
if (parsed.data.selection === null) {
|
|
361
361
|
writeSelection(slot.dir, null);
|
|
362
362
|
return sendJson(res, 200, { ok: true, selection: null });
|
|
363
363
|
}
|
|
364
364
|
const project = slot.payload.project;
|
|
365
|
-
const r = project ? resolveSelection(project, parsed.data.selection) : { ok: false, problem: '
|
|
365
|
+
const r = project ? resolveSelection(project, parsed.data.selection) : { ok: false, problem: 'The project has not compiled successfully yet' };
|
|
366
366
|
if (!r.ok) {
|
|
367
367
|
// 不变量:被拒绝时文件写为 null(不能保留旧选中而界面显示新选中)
|
|
368
368
|
writeSelection(slot.dir, null);
|
|
369
|
-
return sendJson(res, 409, { error: { code: 'INVALID_REFERENCE', message:
|
|
369
|
+
return sendJson(res, 409, { error: { code: 'INVALID_REFERENCE', message: `Selection does not match the current project: ${r.problem}` }, current: null });
|
|
370
370
|
}
|
|
371
371
|
writeSelection(slot.dir, r.selection);
|
|
372
372
|
return sendJson(res, 200, { ok: true, selection: r.selection });
|
|
@@ -381,10 +381,10 @@ export async function createHub(opts = {}) {
|
|
|
381
381
|
const at = b.body?.at;
|
|
382
382
|
const m = typeof at === 'string' ? /^(.+?):(\d+)(?::(\d+))?$/.exec(at) : null;
|
|
383
383
|
if (!m)
|
|
384
|
-
return sendJson(res, 400, { error: { code: 'USAGE', message: 'at
|
|
384
|
+
return sendJson(res, 400, { error: { code: 'USAGE', message: 'at must be file:line[:column]' } });
|
|
385
385
|
const file = path.resolve(slot.dir, m[1]);
|
|
386
386
|
if (!isProjectSource(slot.dir, file) || !fs.existsSync(file))
|
|
387
|
-
return sendJson(res, 400, { error: { code: 'USAGE', message:
|
|
387
|
+
return sendJson(res, 400, { error: { code: 'USAGE', message: `Not a project source file: ${m[1]}` } });
|
|
388
388
|
// 交给 Vite 自带的 launch-editor(按 LAUNCH_EDITOR / EDITOR 或正在运行的编辑器打开)
|
|
389
389
|
req.__joploOpen = true;
|
|
390
390
|
req.url = `/__open-in-editor?file=${encodeURIComponent(`${file}:${m[2]}:${m[3] ?? 1}`)}`;
|
|
@@ -395,7 +395,7 @@ export async function createHub(opts = {}) {
|
|
|
395
395
|
const slot = await ensure(id);
|
|
396
396
|
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) });
|
|
397
397
|
}
|
|
398
|
-
return sendJson(res, 404, { error: { code: 'NOT_FOUND', message:
|
|
398
|
+
return sendJson(res, 404, { error: { code: 'NOT_FOUND', message: `Unknown endpoint: ${method} /__joplo/p/${id}/${rest}` } });
|
|
399
399
|
}
|
|
400
400
|
const boardPlugin = {
|
|
401
401
|
name: 'joplo:board',
|
|
@@ -404,13 +404,13 @@ export async function createHub(opts = {}) {
|
|
|
404
404
|
try {
|
|
405
405
|
const host = req.headers.host ?? '';
|
|
406
406
|
if (!allowedHosts().has(host))
|
|
407
|
-
return deny(res, 403, `Host
|
|
407
|
+
return deny(res, 403, `Host header is not allowed: ${host || '(empty)'}`);
|
|
408
408
|
const url = new URL(req.url ?? '/', `http://127.0.0.1:${actualPort}`);
|
|
409
409
|
if (web.mode === 'dist' && (req.method === 'GET' || req.method === 'HEAD') && serveDistAsset(web, url.pathname, res))
|
|
410
410
|
return;
|
|
411
411
|
// Vite 的打开编辑器中间件只能经由 /__joplo/p/<id>/open(校验令牌与路径)进入
|
|
412
412
|
if (url.pathname === '/__open-in-editor')
|
|
413
|
-
return req.__joploOpen ? next() : deny(res, 403, '
|
|
413
|
+
return req.__joploOpen ? next() : deny(res, 403, 'Use Open in editor in the board');
|
|
414
414
|
if (!url.pathname.startsWith('/__joplo/'))
|
|
415
415
|
return next();
|
|
416
416
|
const method = req.method ?? 'GET';
|
|
@@ -439,7 +439,7 @@ export async function createHub(opts = {}) {
|
|
|
439
439
|
return;
|
|
440
440
|
const dir = b.body?.dir;
|
|
441
441
|
if (typeof dir !== 'string' || !path.isAbsolute(dir))
|
|
442
|
-
return sendJson(res, 400, { error: { code: 'USAGE', message: 'dir
|
|
442
|
+
return sendJson(res, 400, { error: { code: 'USAGE', message: 'dir must be an absolute path to the project directory' } });
|
|
443
443
|
const r = addProject(dir);
|
|
444
444
|
return sendJson(res, 200, { id: r.id, url: r.url });
|
|
445
445
|
}
|
|
@@ -450,7 +450,7 @@ export async function createHub(opts = {}) {
|
|
|
450
450
|
const id = decodeURIComponent(del[1]);
|
|
451
451
|
const rec = recordOf(id);
|
|
452
452
|
if (!rec)
|
|
453
|
-
return sendJson(res, 404, { error: { code: 'NOT_FOUND', message:
|
|
453
|
+
return sendJson(res, 404, { error: { code: 'NOT_FOUND', message: `Unknown project: ${id}` } });
|
|
454
454
|
const slot = slots.get(id);
|
|
455
455
|
if (slot)
|
|
456
456
|
await deactivate(slot);
|
|
@@ -465,7 +465,7 @@ export async function createHub(opts = {}) {
|
|
|
465
465
|
return next();
|
|
466
466
|
return;
|
|
467
467
|
}
|
|
468
|
-
return sendJson(res, 404, { error: { code: 'NOT_FOUND', message:
|
|
468
|
+
return sendJson(res, 404, { error: { code: 'NOT_FOUND', message: `Unknown endpoint: ${method} ${url.pathname}` } });
|
|
469
469
|
}
|
|
470
470
|
catch (e) {
|
|
471
471
|
if (!res.headersSent)
|
|
@@ -522,7 +522,7 @@ export async function createHub(opts = {}) {
|
|
|
522
522
|
await server.close().catch(() => undefined);
|
|
523
523
|
const err = e;
|
|
524
524
|
if (err.code === 'EADDRINUSE' || /already in use/i.test(err.message ?? ''))
|
|
525
|
-
throw new JoploError('USAGE',
|
|
525
|
+
throw new JoploError('USAGE', `Port ${port} is already in use; choose another port (--port), or stop the process using it`, { details: { code: 'EADDRINUSE' } });
|
|
526
526
|
throw e;
|
|
527
527
|
}
|
|
528
528
|
const addr = server.httpServer?.address();
|
|
@@ -602,8 +602,8 @@ export async function attachToRunning(home, projectDir, log) {
|
|
|
602
602
|
});
|
|
603
603
|
const body = (await res.json().catch(() => null));
|
|
604
604
|
if (!res.ok || !body?.url)
|
|
605
|
-
throw new JoploError('UNSUPPORTED_ACTION',
|
|
606
|
-
log(`[joplo]
|
|
605
|
+
throw new JoploError('UNSUPPORTED_ACTION', `Cannot add the project to the running board (${base}, pid ${info.pid}): ${body?.error?.message ?? `HTTP ${res.status}`}`);
|
|
606
|
+
log(`[joplo] Joined the running board (pid ${info.pid})`);
|
|
607
607
|
return { url: body.url, port: info.port };
|
|
608
608
|
}
|
|
609
609
|
function openBrowser(url, log) {
|
|
@@ -613,7 +613,7 @@ function openBrowser(url, log) {
|
|
|
613
613
|
spawn(cmd, args, { stdio: 'ignore', detached: true }).unref();
|
|
614
614
|
}
|
|
615
615
|
catch {
|
|
616
|
-
log(`[joplo]
|
|
616
|
+
log(`[joplo] Cannot open the browser automatically; visit ${url}`);
|
|
617
617
|
}
|
|
618
618
|
}
|
|
619
619
|
/**
|
|
@@ -625,7 +625,7 @@ export async function startDev(opts) {
|
|
|
625
625
|
const home = opts.home ?? joploHome();
|
|
626
626
|
const projectDir = realProjectDir(opts.projectDir);
|
|
627
627
|
if (!fs.existsSync(projectDir))
|
|
628
|
-
throw new JoploError('NOT_FOUND',
|
|
628
|
+
throw new JoploError('NOT_FOUND', `Project directory does not exist: ${projectDir}`);
|
|
629
629
|
const attach = async () => {
|
|
630
630
|
const a = await attachToRunning(home, projectDir, log);
|
|
631
631
|
if (!a)
|
package/dist/export.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type http from 'node:http';
|
|
2
|
-
import { type Project } from '@joplo-app/core';
|
|
2
|
+
import { type AppearanceFont, type AppearanceStroke, type Project } from '@joplo-app/core';
|
|
3
3
|
import { type PlaywrightModule } from './render.js';
|
|
4
4
|
export type Device = 'desktop' | 'mobile';
|
|
5
5
|
/**
|
|
@@ -14,9 +14,9 @@ export type VideoJob = {
|
|
|
14
14
|
id: string;
|
|
15
15
|
projectId: string;
|
|
16
16
|
scenarioId: string;
|
|
17
|
-
status: 'running' | 'done' | 'error';
|
|
17
|
+
status: 'running' | 'done' | 'error' | 'cancelled';
|
|
18
18
|
/** starting 启动浏览器 → recording 录制中 → saving 写文件。 */
|
|
19
|
-
phase: 'starting' | 'recording' | 'saving' | 'done' | 'error';
|
|
19
|
+
phase: 'starting' | 'recording' | 'saving' | 'done' | 'error' | 'cancelled';
|
|
20
20
|
step: number;
|
|
21
21
|
total: number;
|
|
22
22
|
/** 0–100。 */
|
|
@@ -55,6 +55,11 @@ type Ctx = {
|
|
|
55
55
|
}>;
|
|
56
56
|
fail: (e: unknown) => void;
|
|
57
57
|
};
|
|
58
|
+
/** 导出请求里的字体与线条(D55):合法值保留,缺省、null 与未知值都是 null(跟随主题)。任何输入都不抛错。 */
|
|
59
|
+
export declare function exportAppearance(body: unknown): {
|
|
60
|
+
font: AppearanceFont | null;
|
|
61
|
+
stroke: AppearanceStroke | null;
|
|
62
|
+
};
|
|
58
63
|
/** 缺省的录制:Playwright recordVideo + 渲染路由的录制模式(window.__JOPLO_RECORD__)。 */
|
|
59
64
|
export declare function defaultRecorder(load: () => Promise<PlaywrightModule>): VideoRecorder;
|
|
60
65
|
export declare class ExportHub {
|
|
@@ -71,6 +76,8 @@ export declare class ExportHub {
|
|
|
71
76
|
onEvent?: (j: VideoJob) => void;
|
|
72
77
|
});
|
|
73
78
|
private renderUrl;
|
|
79
|
+
/** 取消正在进行的视频任务(D55 导出进度里的「取消」):立即标为“已取消”并中止录制;没有任务时返回 null。 */
|
|
80
|
+
cancel(projectId: string): VideoJob | null;
|
|
74
81
|
job(projectId: string): VideoJob | null;
|
|
75
82
|
private update;
|
|
76
83
|
handle(sub: string, req: http.IncomingMessage, res: http.ServerResponse, ctx: Ctx): Promise<void>;
|
package/dist/export.js
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 看板「…」菜单的导出(D39):
|
|
3
3
|
*
|
|
4
|
-
* - 图片:`POST /__joplo/p/<id>/export/image` `{ scenarioId, position, theme }` → PNG(当前步骤;尺寸跟随页面自己的 viewport,
|
|
4
|
+
* - 图片:`POST /__joplo/p/<id>/export/image` `{ scenarioId, position, theme, font?, stroke? }` → PNG(当前步骤;尺寸跟随页面自己的 viewport,
|
|
5
5
|
* 手机页面带外框;D44 起不再选择设备;镜头用这一步的导演镜头)。Playwright 打开本看板的渲染路由(与 renderStep 同一条渲染路径),截取 `[data-jexport]`。
|
|
6
|
-
* - 视频(只在本机):`POST …/export/video` `{ scenarioId, theme }` → 202 `{ jobId }`(尺寸跟随场景起始页面的 viewport);
|
|
6
|
+
* - 视频(只在本机):`POST …/export/video` `{ scenarioId, theme, font?, stroke? }` → 202 `{ jobId }`(尺寸跟随场景起始页面的 viewport);
|
|
7
7
|
* Playwright `recordVideo` 录下渲染路由的自动播放(含鼠标与字幕),保存为 `<项目>/exports/<场景>-<时间>.webm`。
|
|
8
8
|
* 进度:`GET …/export/video/events`(SSE,先发当前状态,之后每次变化一条,结束后关闭);`GET …/export/video` 取当前状态。
|
|
9
|
-
* 同一项目同时只能有一个视频任务(再提交返回 409)。没有 Playwright / Chromium 时任务失败,错误里带安装命令。
|
|
9
|
+
* 同一项目同时只能有一个视频任务(再提交返回 409);`DELETE …/export/video` 取消正在进行的任务(D55)。没有 Playwright / Chromium 时任务失败,错误里带安装命令。
|
|
10
|
+
*
|
|
11
|
+
* 外观(D55):font / stroke 由 exportAppearance 校验(未知值 = null = 跟随主题),非 null 时作为渲染路由的 URL 参数,
|
|
12
|
+
* RenderApp 读出后交给舞台、字幕与手机外框(与看板里看到的一致)。
|
|
10
13
|
*
|
|
11
14
|
* 字段流向:job(写入点:这里的 runJob)→ jobs Map(存储)→ SSE / GET(读取点)→ 看板的导出视频弹窗(消费者)。
|
|
12
15
|
*/
|
|
13
16
|
import crypto from 'node:crypto';
|
|
14
17
|
import fs from 'node:fs';
|
|
15
18
|
import path from 'node:path';
|
|
16
|
-
import {
|
|
19
|
+
import { exportLocale } from "./locale.js";
|
|
20
|
+
import { JoploError, SUBTITLE_HEIGHT, THEME_NAME, displaySceneId, isAppearanceFont, isAppearanceStroke } from '@joplo-app/core';
|
|
17
21
|
import { launch, loadPlaywright } from "./render.js";
|
|
18
22
|
/**
|
|
19
23
|
* 导出画面的尺寸:电脑 = 舞台 1280×800;手机 = 外框(renderer 的 phoneFrameSize(390, 844) = 446×934)
|
|
@@ -27,22 +31,29 @@ const send = (res, status, body) => {
|
|
|
27
31
|
res.writeHead(status, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store', 'x-content-type-options': 'nosniff' });
|
|
28
32
|
res.end(JSON.stringify(body));
|
|
29
33
|
};
|
|
34
|
+
/** 导出请求里的字体与线条(D55):合法值保留,缺省、null 与未知值都是 null(跟随主题)。任何输入都不抛错。 */
|
|
35
|
+
export function exportAppearance(body) {
|
|
36
|
+
const b = (body && typeof body === 'object' ? body : {});
|
|
37
|
+
return { font: isAppearanceFont(b.font) ? b.font : null, stroke: isAppearanceStroke(b.stroke) ? b.stroke : null };
|
|
38
|
+
}
|
|
39
|
+
/** 渲染路由上的外观参数(null 不写)。 */
|
|
40
|
+
const appearanceParams = (a) => ({ ...(a.font ? { font: a.font } : {}), ...(a.stroke ? { stroke: a.stroke } : {}) });
|
|
30
41
|
function parseRequest(project, body, needPosition) {
|
|
31
42
|
if (!project)
|
|
32
|
-
throw new JoploError('INVALID_SCHEMA', '
|
|
43
|
+
throw new JoploError('INVALID_SCHEMA', 'Cannot export before the project compiles successfully');
|
|
33
44
|
const b = (body ?? {});
|
|
34
45
|
if (typeof b.scenarioId !== 'string' || !project.scenarios[b.scenarioId])
|
|
35
|
-
throw new JoploError('USAGE',
|
|
46
|
+
throw new JoploError('USAGE', `Scenario does not exist: ${String(b.scenarioId)}`);
|
|
36
47
|
const sc = project.scenarios[b.scenarioId];
|
|
37
48
|
const position = needPosition ? Number(b.position ?? 0) : 0;
|
|
38
49
|
if (!Number.isInteger(position) || position < 0 || position > sc.steps.length)
|
|
39
|
-
throw new JoploError('USAGE',
|
|
50
|
+
throw new JoploError('USAGE', `Position must be an integer from 0 to ${sc.steps.length}`);
|
|
40
51
|
// 设备跟随页面自己的 viewport(D44)
|
|
41
52
|
const sceneId = displaySceneId(project, sc.id, position);
|
|
42
53
|
const device = project.scenes[sceneId]?.viewport === 'mobile' ? 'mobile' : 'desktop';
|
|
43
54
|
// 主题(D51):请求里的主题名,没有或不合法时用项目配置的主题
|
|
44
55
|
const theme = typeof b.theme === 'string' && THEME_NAME.test(b.theme) ? b.theme : project.theme;
|
|
45
|
-
return { sc, position, device, theme };
|
|
56
|
+
return { sc, position, device, look: { theme, ...exportAppearance(body), locale: exportLocale(b.locale) } };
|
|
46
57
|
}
|
|
47
58
|
const fileSafe = (s) => s.replace(/[^\w.-]+/g, '_').slice(0, 80) || 'scenario';
|
|
48
59
|
const stamp = (d = new Date()) => `${d.getFullYear()}${String(d.getMonth() + 1).padStart(2, '0')}${String(d.getDate()).padStart(2, '0')}-${String(d.getHours()).padStart(2, '0')}${String(d.getMinutes()).padStart(2, '0')}${String(d.getSeconds()).padStart(2, '0')}`;
|
|
@@ -50,7 +61,7 @@ async function waitReady(page) {
|
|
|
50
61
|
await page.waitForFunction(() => window.__JOPLO_READY__ === true, null, { timeout: 60000 });
|
|
51
62
|
const err = await page.evaluate(() => window.__JOPLO_ERROR__ ?? null);
|
|
52
63
|
if (err)
|
|
53
|
-
throw new JoploError('RENDER_FAILED',
|
|
64
|
+
throw new JoploError('RENDER_FAILED', `Render route reported an error: ${err}`);
|
|
54
65
|
}
|
|
55
66
|
/** 缺省的录制:Playwright recordVideo + 渲染路由的录制模式(window.__JOPLO_RECORD__)。 */
|
|
56
67
|
export function defaultRecorder(load) {
|
|
@@ -68,22 +79,22 @@ export function defaultRecorder(load) {
|
|
|
68
79
|
const t0 = Date.now();
|
|
69
80
|
for (;;) {
|
|
70
81
|
if (signal.aborted)
|
|
71
|
-
throw new JoploError('EXPORT_FAILED', '
|
|
82
|
+
throw new JoploError('EXPORT_FAILED', 'Export cancelled');
|
|
72
83
|
const p = await page.evaluate(() => window.__JOPLO_RECORD__.progress);
|
|
73
84
|
if (p.error)
|
|
74
|
-
throw new JoploError('EXPORT_FAILED',
|
|
85
|
+
throw new JoploError('EXPORT_FAILED', `Playback failed: ${p.error}`);
|
|
75
86
|
progress(p.step);
|
|
76
87
|
if (p.done)
|
|
77
88
|
break;
|
|
78
89
|
if (Date.now() - t0 > 5 * 60_000)
|
|
79
|
-
throw new JoploError('EXPORT_FAILED', '
|
|
90
|
+
throw new JoploError('EXPORT_FAILED', 'Recording exceeded 5 minutes and was stopped');
|
|
80
91
|
await page.waitForTimeout(150);
|
|
81
92
|
}
|
|
82
93
|
await page.waitForTimeout(900); // 停留在结果画面
|
|
83
94
|
const video = page.video();
|
|
84
95
|
await ctx.close();
|
|
85
96
|
if (!video)
|
|
86
|
-
throw new JoploError('EXPORT_FAILED', '
|
|
97
|
+
throw new JoploError('EXPORT_FAILED', 'The browser did not generate a video');
|
|
87
98
|
await video.saveAs(out);
|
|
88
99
|
}
|
|
89
100
|
finally {
|
|
@@ -107,6 +118,16 @@ export class ExportHub {
|
|
|
107
118
|
renderUrl(projectId, q) {
|
|
108
119
|
return `${this.opts.baseUrl()}?${new URLSearchParams({ render: '1', project: projectId, ...q })}`;
|
|
109
120
|
}
|
|
121
|
+
/** 取消正在进行的视频任务(D55 导出进度里的「取消」):立即标为“已取消”并中止录制;没有任务时返回 null。 */
|
|
122
|
+
cancel(projectId) {
|
|
123
|
+
const job = this.jobs.get(projectId);
|
|
124
|
+
if (!job || job.status !== 'running')
|
|
125
|
+
return null;
|
|
126
|
+
this.update(job, { status: 'cancelled', phase: 'cancelled', error: 'Cancelled' });
|
|
127
|
+
this.aborts.get(projectId)?.abort();
|
|
128
|
+
this.aborts.delete(projectId);
|
|
129
|
+
return { ...job };
|
|
130
|
+
}
|
|
110
131
|
job(projectId) {
|
|
111
132
|
return this.jobs.get(projectId) ?? null;
|
|
112
133
|
}
|
|
@@ -126,8 +147,8 @@ export class ExportHub {
|
|
|
126
147
|
const b = await ctx.jsonBody();
|
|
127
148
|
if (!b.ok)
|
|
128
149
|
return;
|
|
129
|
-
const { sc, position, device,
|
|
130
|
-
const png = await this.image(ctx.projectId, sc.id, position, device,
|
|
150
|
+
const { sc, position, device, look } = parseRequest(ctx.project, b.body, true);
|
|
151
|
+
const png = await this.image(ctx.projectId, sc.id, position, device, look);
|
|
131
152
|
res.writeHead(200, { 'content-type': 'image/png', 'cache-control': 'no-store', 'content-disposition': `attachment; filename="${fileSafe(sc.id)}-${position}.png"` });
|
|
132
153
|
res.end(png);
|
|
133
154
|
return;
|
|
@@ -138,21 +159,27 @@ export class ExportHub {
|
|
|
138
159
|
const b = await ctx.jsonBody();
|
|
139
160
|
if (!b.ok)
|
|
140
161
|
return;
|
|
141
|
-
const { sc, device,
|
|
162
|
+
const { sc, device, look } = parseRequest(ctx.project, b.body, false);
|
|
142
163
|
const cur = this.jobs.get(ctx.projectId);
|
|
143
164
|
if (cur?.status === 'running')
|
|
144
|
-
return send(res, 409, { error: { code: 'UNSUPPORTED_ACTION', message: '
|
|
145
|
-
const job = this.startVideo(ctx.projectId, ctx.dir, sc.id, sc.steps.length, device,
|
|
165
|
+
return send(res, 409, { error: { code: 'UNSUPPORTED_ACTION', message: 'This project already has a video export in progress; wait for it to finish' }, job: cur });
|
|
166
|
+
const job = this.startVideo(ctx.projectId, ctx.dir, sc.id, sc.steps.length, device, look);
|
|
146
167
|
return send(res, 202, { jobId: job.id, job });
|
|
147
168
|
}
|
|
148
169
|
if (sub === 'video' && method === 'GET')
|
|
149
170
|
return send(res, 200, { job: this.job(ctx.projectId) });
|
|
171
|
+
if (sub === 'video' && method === 'DELETE') {
|
|
172
|
+
if (!ctx.guardWrite(false))
|
|
173
|
+
return;
|
|
174
|
+
const job = this.cancel(ctx.projectId);
|
|
175
|
+
return job ? send(res, 200, { job }) : send(res, 404, { error: { code: 'NOT_FOUND', message: 'This project has no video export in progress' } });
|
|
176
|
+
}
|
|
150
177
|
if (sub === 'video/events' && method === 'GET') {
|
|
151
178
|
if (!ctx.guardWrite(false))
|
|
152
179
|
return;
|
|
153
180
|
return this.sse(ctx.projectId, res);
|
|
154
181
|
}
|
|
155
|
-
return send(res, 404, { error: { code: 'NOT_FOUND', message:
|
|
182
|
+
return send(res, 404, { error: { code: 'NOT_FOUND', message: `Unknown endpoint: ${method} export/${sub}` } });
|
|
156
183
|
}
|
|
157
184
|
catch (e) {
|
|
158
185
|
if (!res.headersSent)
|
|
@@ -161,12 +188,12 @@ export class ExportHub {
|
|
|
161
188
|
res.end();
|
|
162
189
|
}
|
|
163
190
|
}
|
|
164
|
-
async image(projectId, scenarioId, position, device,
|
|
191
|
+
async image(projectId, scenarioId, position, device, look) {
|
|
165
192
|
const pw = await this.deps.loadPlaywright();
|
|
166
193
|
const browser = await launch(pw);
|
|
167
194
|
try {
|
|
168
195
|
const page = await browser.newPage({ viewport: EXPORT_SIZE[device], deviceScaleFactor: 2, reducedMotion: 'reduce' });
|
|
169
|
-
await page.goto(this.renderUrl(projectId, { scenario: scenarioId, position: String(position), theme, frame: '1' }), { waitUntil: 'domcontentloaded' });
|
|
196
|
+
await page.goto(this.renderUrl(projectId, { scenario: scenarioId, position: String(position), theme: look.theme, ...appearanceParams(look), ...(look.locale ? { locale: look.locale } : {}), frame: '1' }), { waitUntil: 'domcontentloaded' });
|
|
170
197
|
await waitReady(page);
|
|
171
198
|
return await page.locator('[data-jexport]').screenshot({ type: 'png', animations: 'disabled' });
|
|
172
199
|
}
|
|
@@ -174,7 +201,7 @@ export class ExportHub {
|
|
|
174
201
|
await browser.close().catch(() => undefined);
|
|
175
202
|
}
|
|
176
203
|
}
|
|
177
|
-
startVideo(projectId, dir, scenarioId, total, device,
|
|
204
|
+
startVideo(projectId, dir, scenarioId, total, device, look) {
|
|
178
205
|
const job = { id: crypto.randomBytes(6).toString('hex'), projectId, scenarioId, status: 'running', phase: 'starting', step: 0, total, percent: 0, file: null, error: null };
|
|
179
206
|
this.jobs.set(projectId, job);
|
|
180
207
|
const ac = new AbortController();
|
|
@@ -186,29 +213,36 @@ export class ExportHub {
|
|
|
186
213
|
fs.mkdirSync(path.dirname(out), { recursive: true });
|
|
187
214
|
this.update(job, { phase: 'starting', percent: 2 });
|
|
188
215
|
await this.deps.recordVideo({
|
|
189
|
-
url: this.renderUrl(projectId, { scenario: scenarioId, position: '0', theme, frame: '1', record: '1' }),
|
|
216
|
+
url: this.renderUrl(projectId, { scenario: scenarioId, position: '0', theme: look.theme, ...appearanceParams(look), ...(look.locale ? { locale: look.locale } : {}), frame: '1', record: '1' }),
|
|
190
217
|
size: EXPORT_SIZE[device],
|
|
191
218
|
out,
|
|
192
219
|
total,
|
|
193
220
|
signal: ac.signal,
|
|
194
221
|
progress: (step) => {
|
|
222
|
+
if (job.status !== 'running')
|
|
223
|
+
return; // 已取消
|
|
195
224
|
const s = Math.max(0, Math.min(step, total));
|
|
196
225
|
const percent = Math.round(5 + (total ? s / total : 1) * 85);
|
|
197
226
|
if (job.phase !== 'recording' || s !== job.step)
|
|
198
227
|
this.update(job, { phase: 'recording', step: s, percent });
|
|
199
228
|
},
|
|
200
229
|
});
|
|
230
|
+
if (job.status !== 'running')
|
|
231
|
+
return; // 已取消:录制器之后才返回,不改回完成
|
|
201
232
|
this.update(job, { phase: 'saving', percent: 95 });
|
|
202
233
|
if (!fs.existsSync(out))
|
|
203
|
-
throw new JoploError('EXPORT_FAILED', '
|
|
234
|
+
throw new JoploError('EXPORT_FAILED', 'Recording completed, but no video file was generated');
|
|
204
235
|
this.update(job, { status: 'done', phase: 'done', percent: 100, step: total, file: rel });
|
|
205
|
-
this.opts.log(`[joplo]
|
|
236
|
+
this.opts.log(`[joplo] Exported video: ${out}`);
|
|
206
237
|
}
|
|
207
238
|
catch (e) {
|
|
208
|
-
|
|
239
|
+
if (job.status === 'running')
|
|
240
|
+
this.update(job, { status: 'error', phase: 'error', error: e instanceof Error ? e.message : String(e) });
|
|
209
241
|
}
|
|
210
242
|
finally {
|
|
211
|
-
|
|
243
|
+
// 只删自己的(取消后可能已经开始了新任务)
|
|
244
|
+
if (this.aborts.get(projectId) === ac)
|
|
245
|
+
this.aborts.delete(projectId);
|
|
212
246
|
}
|
|
213
247
|
})();
|
|
214
248
|
this.running.add(p);
|
package/dist/home.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type AppearanceFont, type AppearanceStroke } from '@joplo-app/core';
|
|
1
2
|
export type ProjectRecord = {
|
|
2
3
|
dir: string;
|
|
3
4
|
name: string;
|
|
@@ -32,18 +33,25 @@ export declare function writeServerInfo(home: string, info: ServerInfo): void;
|
|
|
32
33
|
export declare function clearServerInfo(home: string, pid: number): void;
|
|
33
34
|
export declare function pidAlive(pid: number): boolean;
|
|
34
35
|
/**
|
|
35
|
-
* `{ version: 1, theme
|
|
36
|
-
* theme
|
|
37
|
-
*
|
|
36
|
+
* `{ version: 1, theme?, font?, stroke?, projects?: { [项目 id]: { theme?, font?, stroke? } } }`
|
|
37
|
+
* - theme:主题名(内置或作者 themes/<name>.css);font:hand | sans | serif | kai | mono;stroke:rough | clean。
|
|
38
|
+
* - 顶层是“所有项目”的选择;projects[id] 按项目覆盖。值为 null:theme = 恢复为项目 config 的主题,font / stroke = 跟随主题。
|
|
39
|
+
* - 字段不存在 = 没有设置(项目条目里没有就看顶层,顶层没有就看项目 config / 主题)。
|
|
40
|
+
* 写入点:看板外观浮层(PUT /__joplo/settings);存储:这里(校验后原子写入);读取点:看板(GET /__joplo/settings →
|
|
41
|
+
* useBoardSettings → effectiveAppearance);消费者:舞台、字幕、手机外框、导出图片与视频。
|
|
42
|
+
* 只有 theme 的旧文件照常读取。发布站不读它(joplo.config.ts 只有 theme)。
|
|
38
43
|
*/
|
|
44
|
+
export type AppearanceOverride = {
|
|
45
|
+
theme?: string | null;
|
|
46
|
+
font?: AppearanceFont | null;
|
|
47
|
+
stroke?: AppearanceStroke | null;
|
|
48
|
+
};
|
|
39
49
|
export type BoardSettings = {
|
|
40
50
|
version: 1;
|
|
41
|
-
|
|
42
|
-
projects?: Record<string,
|
|
43
|
-
theme: string | null;
|
|
44
|
-
}>;
|
|
51
|
+
} & AppearanceOverride & {
|
|
52
|
+
projects?: Record<string, AppearanceOverride>;
|
|
45
53
|
};
|
|
46
|
-
/**
|
|
54
|
+
/** 校验并规范化设置(未知字段丢弃,不合法的值丢弃,没有合法字段的项目条目丢弃)。任何输入都不抛错。 */
|
|
47
55
|
export declare function normalizeSettings(v: unknown): BoardSettings;
|
|
48
56
|
export declare function readSettings(home: string): BoardSettings;
|
|
49
57
|
export declare function writeSettings(home: string, s: unknown): BoardSettings;
|
package/dist/home.js
CHANGED
|
@@ -14,6 +14,7 @@ import crypto from 'node:crypto';
|
|
|
14
14
|
import fs from 'node:fs';
|
|
15
15
|
import os from 'node:os';
|
|
16
16
|
import path from 'node:path';
|
|
17
|
+
import { THEME_NAME, isAppearanceFont, isAppearanceStroke } from '@joplo-app/core';
|
|
17
18
|
export function joploHome(env = process.env) {
|
|
18
19
|
const v = env.JOPLO_HOME;
|
|
19
20
|
return v && v.trim() ? path.resolve(v) : path.join(os.homedir(), '.joplo');
|
|
@@ -131,23 +132,30 @@ export function pidAlive(pid) {
|
|
|
131
132
|
return e.code === 'EPERM';
|
|
132
133
|
}
|
|
133
134
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const out = { version: 1 };
|
|
139
|
-
if (typeof o.theme === 'string' && NAME.test(o.theme))
|
|
135
|
+
/** 一组外观字段:只留合法值(null 合法),其余丢弃。 */
|
|
136
|
+
function normalizeAppearance(o) {
|
|
137
|
+
const out = {};
|
|
138
|
+
if (o.theme === null || (typeof o.theme === 'string' && THEME_NAME.test(o.theme)))
|
|
140
139
|
out.theme = o.theme;
|
|
141
|
-
|
|
142
|
-
out.
|
|
143
|
-
|
|
140
|
+
if (o.font === null || isAppearanceFont(o.font))
|
|
141
|
+
out.font = o.font;
|
|
142
|
+
if (o.stroke === null || isAppearanceStroke(o.stroke))
|
|
143
|
+
out.stroke = o.stroke;
|
|
144
|
+
return out;
|
|
145
|
+
}
|
|
146
|
+
const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
147
|
+
/** 校验并规范化设置(未知字段丢弃,不合法的值丢弃,没有合法字段的项目条目丢弃)。任何输入都不抛错。 */
|
|
148
|
+
export function normalizeSettings(v) {
|
|
149
|
+
const o = isObj(v) ? v : {};
|
|
150
|
+
const out = { version: 1, ...normalizeAppearance(o) };
|
|
151
|
+
const projects = isObj(o.projects) ? o.projects : {};
|
|
144
152
|
const p = {};
|
|
145
153
|
for (const [id, x] of Object.entries(projects)) {
|
|
146
|
-
if (!/^[\w-]{1,64}$/.test(id) || !x
|
|
154
|
+
if (!/^[\w-]{1,64}$/.test(id) || !isObj(x))
|
|
147
155
|
continue;
|
|
148
|
-
const
|
|
149
|
-
if (
|
|
150
|
-
p[id] =
|
|
156
|
+
const a = normalizeAppearance(x);
|
|
157
|
+
if (Object.keys(a).length)
|
|
158
|
+
p[id] = a;
|
|
151
159
|
}
|
|
152
160
|
if (Object.keys(p).length)
|
|
153
161
|
out.projects = p;
|
package/dist/locale.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Export URLs accept exact supported locale tags; invalid or absent values are omitted. */
|
|
2
|
+
export declare const exportLocales: readonly ["en", "zh-CN", "zh-TW", "ja", "ko", "es", "fr", "de", "pt-BR", "ru"];
|
|
3
|
+
export type ExportLocale = typeof exportLocales[number];
|
|
4
|
+
export declare function exportLocale(value: unknown): ExportLocale | undefined;
|
package/dist/locale.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Export URLs accept exact supported locale tags; invalid or absent values are omitted. */
|
|
2
|
+
export const exportLocales = ['en', 'zh-CN', 'zh-TW', 'ja', 'ko', 'es', 'fr', 'de', 'pt-BR', 'ru'];
|
|
3
|
+
export function exportLocale(value) {
|
|
4
|
+
return typeof value === 'string' && exportLocales.includes(value) ? value : undefined;
|
|
5
|
+
}
|
package/dist/page-report.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
const els = Array.from(stage.querySelectorAll('[data-jid]:not([data-jtype="#text"])'));
|
|
9
9
|
const name = (el) => {
|
|
10
10
|
const owner = el.closest('[data-jid]:not([data-jtype="#text"])');
|
|
11
|
-
return owner ?
|
|
11
|
+
return owner ? `"${owner.dataset.jlabel ?? ''}"(${owner.dataset.jid})` : el.closest('[data-jtoast]') ? 'Toast' : el.closest('[data-jbackdrop]') ? 'Modal backdrop' : el.tagName.toLowerCase();
|
|
12
12
|
};
|
|
13
13
|
const elements = els.map((el) => {
|
|
14
14
|
const r = el.getBoundingClientRect();
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
const cx = r.left + r.width / 2;
|
|
34
34
|
const cy = r.top + r.height / 2;
|
|
35
35
|
if (cx < sr.left || cx > sr.right || cy < sr.top || cy > sr.bottom) {
|
|
36
|
-
warnings.push(
|
|
36
|
+
warnings.push(`Outside frame: "${e.label}"(${e.id}) has its center outside the frame`);
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
39
|
// 视口小于舞台时,视口外的点 elementFromPoint 返回 null——那不是遮挡,单独汇总
|
|
@@ -45,15 +45,15 @@
|
|
|
45
45
|
if (hit && (hit === el || el.contains(hit))) return;
|
|
46
46
|
// 弹窗打开时,背景被遮罩或弹窗面板覆盖是预期的层次,不算遮挡(窄屏下面板常盖住背景按钮)
|
|
47
47
|
if ((hit?.closest('[data-jbackdrop]') || (dialogOpen && hit?.closest('[role="dialog"]'))) && !el.closest('[role="dialog"]')) return;
|
|
48
|
-
warnings.push(
|
|
48
|
+
warnings.push(`Occluded: "${e.label}"(${e.id}) has its center covered by ${hit ? name(hit) : 'content outside the frame'}`);
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
if (offViewport.length)
|
|
52
|
-
warnings.push(
|
|
52
|
+
warnings.push(`Outside viewport: viewport ${vw}×${vh} is smaller than the stage; ${offViewport.length} interactive elements have centers outside the viewport; occlusion checks skipped (${offViewport.join(', ')})`);
|
|
53
53
|
|
|
54
54
|
// 2. 标签文字溢出
|
|
55
55
|
stage.querySelectorAll('[data-jtext], .jtrunc').forEach((t) => {
|
|
56
|
-
if (t.scrollWidth > t.clientWidth + 1) warnings.push(
|
|
56
|
+
if (t.scrollWidth > t.clientWidth + 1) warnings.push(`Label text overflow: ${name(t)} text "${(t.textContent ?? '').slice(0, 40)}" is clipped`);
|
|
57
57
|
});
|
|
58
58
|
|
|
59
59
|
// 3. Toast 等浮层(pointer-events:none,elementFromPoint 看不到)与可交互元素按几何相交检测
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
if (dialogOpen && !el.closest('[role="dialog"]')) return; // 被弹窗遮罩盖住的背景本来就不可操作
|
|
66
66
|
const r = el.getBoundingClientRect();
|
|
67
67
|
if (!toasts.some((b) => overlap(b, r))) return;
|
|
68
|
-
warnings.push(e.id === args.nextTargetId ? `Toast
|
|
68
|
+
warnings.push(e.id === args.nextTargetId ? `Toast obscures the next action target: ${name(el)}` : `Toast covers an interactive element: ${name(el)}`);
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -73,10 +73,10 @@
|
|
|
73
73
|
// 主题用到手写字体时(--jp-font 含 Excalifont)检查它们已加载
|
|
74
74
|
if (/Excalifont|Xiaolai/.test(getComputedStyle(stage).fontFamily)) {
|
|
75
75
|
const text = stage.innerText || '中文';
|
|
76
|
-
if (!document.fonts.check('16px "Joplo Excalifont"', text) || !document.fonts.check('16px "Joplo Xiaolai"', text)) warnings.push('
|
|
76
|
+
if (!document.fonts.check('16px "Joplo Excalifont"', text) || !document.fonts.check('16px "Joplo Xiaolai"', text)) warnings.push('Fonts not loaded: Hand-drawn fonts (Excalifont / Xiaolai) are not ready; the screenshot may use fallback fonts');
|
|
77
77
|
}
|
|
78
78
|
const failed = Array.from(document.fonts).filter((f) => f.status === 'error');
|
|
79
|
-
if (failed.length) warnings.push(
|
|
79
|
+
if (failed.length) warnings.push(`Fonts not loaded: ${failed.length} font files failed to load (${failed[0].family})`);
|
|
80
80
|
|
|
81
81
|
return { elements, warnings };
|
|
82
82
|
}
|
package/dist/project.js
CHANGED
|
@@ -50,7 +50,7 @@ export async function compileProject(server, projectDir, mode) {
|
|
|
50
50
|
...d,
|
|
51
51
|
at: precise,
|
|
52
52
|
// 位置已在 at 里,说明只保留第一行的原因
|
|
53
|
-
message: d.message.replace(/\x1b\[[0-9;]*m/g, '').split('\n')[0].replace(
|
|
53
|
+
message: d.message.replace(/\x1b\[[0-9;]*m/g, '').split('\n')[0].replace(`Load failed: ${precise} `, 'Load failed: '),
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
56
|
const key = `${out.code}|${out.at}|${out.message}`;
|
package/dist/render.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Browser } from 'playwright';
|
|
2
|
+
import { type AppearanceFont, type AppearanceStroke } from '@joplo-app/core';
|
|
2
3
|
import type { RenderOptions, RenderResult } from './contract.js';
|
|
3
4
|
export type PlaywrightModule = typeof import('playwright');
|
|
4
5
|
/** 按需载入 Playwright;没有安装时抛出带安装命令的 RENDER_FAILED。 */
|
|
@@ -6,4 +7,21 @@ export declare function loadPlaywright(importer?: () => Promise<PlaywrightModule
|
|
|
6
7
|
/** 浏览器启动失败时的一行提示。 */
|
|
7
8
|
export declare function launchHint(e: unknown): string;
|
|
8
9
|
export declare function launch({ chromium }: PlaywrightModule): Promise<Browser>;
|
|
10
|
+
/**
|
|
11
|
+
* 渲染路由的参数(纯函数):主题必填(调用方缺省时传项目主题);字体与线条(D55)只在指定且合法时带上,
|
|
12
|
+
* 缺省 = 跟随主题,与 D55 之前的截图一致。
|
|
13
|
+
*/
|
|
14
|
+
export declare function renderQuery(q: {
|
|
15
|
+
projectId: string;
|
|
16
|
+
scenarioId: string;
|
|
17
|
+
position: number;
|
|
18
|
+
theme: string;
|
|
19
|
+
locale?: string;
|
|
20
|
+
font?: AppearanceFont | null;
|
|
21
|
+
stroke?: AppearanceStroke | null;
|
|
22
|
+
viewport?: {
|
|
23
|
+
width: number;
|
|
24
|
+
height: number;
|
|
25
|
+
};
|
|
26
|
+
}): string;
|
|
9
27
|
export declare function renderStep(opts: RenderOptions): Promise<RenderResult>;
|
package/dist/render.js
CHANGED
|
@@ -7,11 +7,12 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import fs from 'node:fs';
|
|
9
9
|
import path from 'node:path';
|
|
10
|
-
import { JoploError, SUBTITLE_HEIGHT, VIEWPORT_SIZE, displaySceneId, findNode, isNodeDisabled, nodeLabel, positionAfterStep, resolveProps, stateAt, walkNodes } from '@joplo-app/core';
|
|
10
|
+
import { JoploError, SUBTITLE_HEIGHT, VIEWPORT_SIZE, isAppearanceFont, isAppearanceStroke, displaySceneId, findNode, isNodeDisabled, nodeLabel, positionAfterStep, resolveProps, stateAt, walkNodes } from '@joplo-app/core';
|
|
11
|
+
import { exportLocale } from "./locale.js";
|
|
11
12
|
import { createDev } from "./dev.js";
|
|
12
13
|
import { realProjectDir } from "./vite-shared.js";
|
|
13
14
|
const STAGE_SIZE = VIEWPORT_SIZE;
|
|
14
|
-
const NOT_NEEDED = 'dev
|
|
15
|
+
const NOT_NEEDED = 'dev, check, and build do not require it.';
|
|
15
16
|
const isMissingModule = (e) => {
|
|
16
17
|
const code = e?.code;
|
|
17
18
|
return (code === 'ERR_MODULE_NOT_FOUND' || code === 'MODULE_NOT_FOUND') && /playwright/.test(e instanceof Error ? e.message : String(e));
|
|
@@ -24,13 +25,13 @@ export async function loadPlaywright(importer = () => import('playwright')) {
|
|
|
24
25
|
catch (e) {
|
|
25
26
|
if (!isMissingModule(e))
|
|
26
27
|
throw e;
|
|
27
|
-
throw new JoploError('RENDER_FAILED',
|
|
28
|
+
throw new JoploError('RENDER_FAILED', `Screenshots require Playwright and Chromium, which are not installed. Run: npm i -D playwright && npx playwright install chromium (about 150 MB). ${NOT_NEEDED}`);
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
31
|
/** 浏览器启动失败时的一行提示。 */
|
|
31
32
|
export function launchHint(e) {
|
|
32
33
|
const first = (e instanceof Error ? e.message : String(e)).split('\n')[0].trim();
|
|
33
|
-
return
|
|
34
|
+
return `Screenshots require Chromium; browser launch failed (${first}). Run: npx playwright install chromium (about 150 MB). ${NOT_NEEDED}`;
|
|
34
35
|
}
|
|
35
36
|
export async function launch({ chromium }) {
|
|
36
37
|
try {
|
|
@@ -70,16 +71,33 @@ function assertNotProjectData(projectDir, out) {
|
|
|
70
71
|
const dir = fold(realish(projectDir));
|
|
71
72
|
const dataDir = path.join(dir, '.joplo');
|
|
72
73
|
if (o === dataDir || o.startsWith(dataDir + path.sep))
|
|
73
|
-
throw new JoploError('USAGE',
|
|
74
|
+
throw new JoploError('USAGE', `Cannot write to project data: ${out} (.joplo/ is managed by Joplo)`);
|
|
74
75
|
if (/\.(tsx?|jsx?|mts)$/.test(o) && o.startsWith(dir + path.sep))
|
|
75
|
-
throw new JoploError('USAGE',
|
|
76
|
+
throw new JoploError('USAGE', `Cannot overwrite a project source file with a screenshot: ${out}`);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* 渲染路由的参数(纯函数):主题必填(调用方缺省时传项目主题);字体与线条(D55)只在指定且合法时带上,
|
|
80
|
+
* 缺省 = 跟随主题,与 D55 之前的截图一致。
|
|
81
|
+
*/
|
|
82
|
+
export function renderQuery(q) {
|
|
83
|
+
return new URLSearchParams({
|
|
84
|
+
render: '1',
|
|
85
|
+
project: q.projectId,
|
|
86
|
+
scenario: q.scenarioId,
|
|
87
|
+
position: String(q.position),
|
|
88
|
+
theme: q.theme,
|
|
89
|
+
...(exportLocale(q.locale) ? { locale: exportLocale(q.locale) } : {}),
|
|
90
|
+
...(isAppearanceFont(q.font) ? { font: q.font } : {}),
|
|
91
|
+
...(isAppearanceStroke(q.stroke) ? { stroke: q.stroke } : {}),
|
|
92
|
+
...(q.viewport ? { w: String(q.viewport.width), h: String(q.viewport.height) } : {}),
|
|
93
|
+
}).toString();
|
|
76
94
|
}
|
|
77
95
|
export async function renderStep(opts) {
|
|
78
96
|
const projectDir = realProjectDir(opts.projectDir);
|
|
79
97
|
const out = path.resolve(opts.out);
|
|
80
98
|
assertNotProjectData(projectDir, out);
|
|
81
99
|
if (fs.existsSync(out) && !opts.overwrite)
|
|
82
|
-
throw new JoploError('USAGE',
|
|
100
|
+
throw new JoploError('USAGE', `Output file already exists: ${out}. To overwrite, pass overwrite: true (CLI: --overwrite)`);
|
|
83
101
|
// 先确认 Playwright 可用,再启动编译服务(缺失时尽快失败)
|
|
84
102
|
const playwright = await loadPlaywright();
|
|
85
103
|
const server = await createDev({ projectDir, port: 0, watch: false, log: () => undefined });
|
|
@@ -89,11 +107,11 @@ export async function renderStep(opts) {
|
|
|
89
107
|
const project = payload.project;
|
|
90
108
|
if (!project) {
|
|
91
109
|
const errs = payload.diagnostics.filter((d) => d.severity === 'error');
|
|
92
|
-
throw new JoploError('INVALID_SCHEMA',
|
|
110
|
+
throw new JoploError('INVALID_SCHEMA', `Project compilation failed: ${errs.map((d) => `${d.at ?? ''} ${d.message}`).join('; ')}`, { diagnostics: payload.diagnostics });
|
|
93
111
|
}
|
|
94
112
|
const sc = project.scenarios[opts.scenarioId];
|
|
95
113
|
if (!sc)
|
|
96
|
-
throw new JoploError('NOT_FOUND',
|
|
114
|
+
throw new JoploError('NOT_FOUND', `Scenario does not exist: ${opts.scenarioId} (available: ${Object.keys(project.scenarios).join(', ') || 'none'})`);
|
|
97
115
|
const position = opts.stepId ? positionAfterStep(project, sc.id, opts.stepId) : 0;
|
|
98
116
|
const state = stateAt(project, sc.id, position); // 回放失败会抛出 PLAYBACK_FAILED
|
|
99
117
|
// 有层级的方案:截图与元素索引用这一步导演层的画面(每层一个独立画面)
|
|
@@ -107,12 +125,12 @@ export async function renderStep(opts) {
|
|
|
107
125
|
browser = await launch(playwright);
|
|
108
126
|
const page = await browser.newPage({ viewport, deviceScaleFactor: opts.scale ?? 1, reducedMotion: 'reduce' });
|
|
109
127
|
// D44:舞台宽度固定为页面自己的 viewport;指定 viewport 时它只是截图尺寸(舞台按比例放进去)
|
|
110
|
-
const q =
|
|
128
|
+
const q = renderQuery({ projectId: server.projectId, scenarioId: sc.id, position, theme, locale: opts.locale, font: opts.font, stroke: opts.stroke, ...(opts.viewport ? { viewport: opts.viewport } : {}) });
|
|
111
129
|
await page.goto(`${server.url}?${q}`, { waitUntil: 'domcontentloaded' });
|
|
112
130
|
await page.waitForFunction(() => window.__JOPLO_READY__ === true, null, { timeout: 60000 });
|
|
113
131
|
const err = await page.evaluate(() => window.__JOPLO_ERROR__ ?? null);
|
|
114
132
|
if (err)
|
|
115
|
-
throw new JoploError('RENDER_FAILED',
|
|
133
|
+
throw new JoploError('RENDER_FAILED', `Render route reported an error: ${err}`);
|
|
116
134
|
const report = (await page.evaluate(`(${COLLECT_REPORT})(${JSON.stringify({ nextTargetId, theme })})`));
|
|
117
135
|
const png = await page.locator(opts.viewport ? '[data-jshot]' : '[data-jrender]').screenshot({ type: 'png', animations: 'disabled' });
|
|
118
136
|
fs.mkdirSync(path.dirname(out), { recursive: true });
|
|
@@ -139,7 +157,7 @@ export async function renderStep(opts) {
|
|
|
139
157
|
const elements = [...report.elements, ...hidden];
|
|
140
158
|
const warnings = [...report.warnings];
|
|
141
159
|
if (nextTargetId && findNode(scene, nextTargetId) && !elements.find((e) => e.id === nextTargetId && e.visible))
|
|
142
|
-
warnings.push(
|
|
160
|
+
warnings.push(`Next action target ${nextTargetId} is not visible in the stage`);
|
|
143
161
|
return { path: out, sceneId: scene.id, position, elements, warnings, scale: opts.scale ?? 1 };
|
|
144
162
|
}
|
|
145
163
|
finally {
|
package/dist/selection.js
CHANGED
|
@@ -32,49 +32,49 @@ export function resolveSelection(project, input, now = new Date()) {
|
|
|
32
32
|
if (optionId !== null) {
|
|
33
33
|
const opt = project.options[optionId];
|
|
34
34
|
if (!opt)
|
|
35
|
-
return { ok: false, problem:
|
|
35
|
+
return { ok: false, problem: `Option ${optionId} does not exist` };
|
|
36
36
|
featureId = opt.featureId;
|
|
37
37
|
}
|
|
38
38
|
if (input.scenarioId !== null) {
|
|
39
39
|
const sc = project.scenarios[input.scenarioId];
|
|
40
40
|
if (!sc)
|
|
41
|
-
return { ok: false, problem:
|
|
41
|
+
return { ok: false, problem: `Scenario ${input.scenarioId} does not exist` };
|
|
42
42
|
if (optionId !== sc.optionId)
|
|
43
|
-
return { ok: false, problem:
|
|
43
|
+
return { ok: false, problem: `Scenario ${sc.id} does not belong to option ${optionId ?? '(none)'}` };
|
|
44
44
|
if (input.position > sc.steps.length)
|
|
45
|
-
return { ok: false, problem:
|
|
45
|
+
return { ok: false, problem: `Position ${input.position} is outside scenario ${sc.id} range 0..${sc.steps.length}` };
|
|
46
46
|
try {
|
|
47
47
|
sceneId = stateAt(project, sc.id, input.position).sceneId;
|
|
48
48
|
}
|
|
49
49
|
catch (e) {
|
|
50
|
-
return { ok: false, problem:
|
|
50
|
+
return { ok: false, problem: `Scenario ${sc.id} cannot replay to position ${input.position}: ${e instanceof Error ? e.message : String(e)}` };
|
|
51
51
|
}
|
|
52
52
|
// 有层级的方案:用户看的是某一层的画面(各层共享同一份状态),也接受
|
|
53
53
|
const layerScenes = Object.values(project.options[sc.optionId]?.layers ?? {}).map((l) => l.sceneId);
|
|
54
54
|
if (layerScenes.includes(input.sceneId))
|
|
55
55
|
sceneId = input.sceneId;
|
|
56
56
|
if (input.sceneId !== sceneId)
|
|
57
|
-
return { ok: false, problem:
|
|
57
|
+
return { ok: false, problem: `Position ${input.position} has stage ${sceneId}, not ${input.sceneId}` };
|
|
58
58
|
stepId = sc.steps[input.position - 1]?.id ?? null;
|
|
59
59
|
if (input.stepId) {
|
|
60
60
|
if (!sc.steps.some((s) => s.id === input.stepId))
|
|
61
|
-
return { ok: false, problem:
|
|
61
|
+
return { ok: false, problem: `Step ${input.stepId} is not in scenario ${sc.id}` };
|
|
62
62
|
stepId = input.stepId;
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
else if (input.position !== 0 || input.stepId)
|
|
66
|
-
return { ok: false, problem: '
|
|
66
|
+
return { ok: false, problem: 'Without a scenario, position must be 0 and no step may be selected' };
|
|
67
67
|
const scene = project.scenes[sceneId];
|
|
68
68
|
if (!scene)
|
|
69
|
-
return { ok: false, problem:
|
|
69
|
+
return { ok: false, problem: `Stage ${sceneId} does not exist` };
|
|
70
70
|
if (input.scenarioId === null && optionId !== null && scene.optionId !== optionId && scene.optionId !== null)
|
|
71
|
-
return { ok: false, problem:
|
|
71
|
+
return { ok: false, problem: `Stage ${sceneId} does not belong to option ${optionId}` };
|
|
72
72
|
let at = null;
|
|
73
73
|
let label = null;
|
|
74
74
|
if (input.nodeId) {
|
|
75
75
|
const hit = findNode(scene, input.nodeId);
|
|
76
76
|
if (!hit)
|
|
77
|
-
return { ok: false, problem:
|
|
77
|
+
return { ok: false, problem: `Element ${input.nodeId} is not in stage ${sceneId}` };
|
|
78
78
|
at = hit.node.source ?? null;
|
|
79
79
|
label = nodeLabel(hit.node); // Mantine 输入组件直接带 label 属性
|
|
80
80
|
}
|
|
@@ -84,7 +84,7 @@ export function resolveSelection(project, input, now = new Date()) {
|
|
|
84
84
|
label = st.caption;
|
|
85
85
|
}
|
|
86
86
|
else
|
|
87
|
-
return { ok: false, problem: '
|
|
87
|
+
return { ok: false, problem: 'Selection must point to an element or a step' };
|
|
88
88
|
return {
|
|
89
89
|
ok: true,
|
|
90
90
|
selection: {
|
package/dist/vite-shared.js
CHANGED
|
@@ -93,7 +93,7 @@ export function joploProjectPlugin(projectDir, web = locateWebAssets()) {
|
|
|
93
93
|
const loc = parseErrorLoc(first, file) ?? { line: 1, column: 1 };
|
|
94
94
|
const rel = path.relative(projectDir, file).split(path.sep).join('/');
|
|
95
95
|
const brief = (first.split('\n')[0] ?? '').replace(/^\s*\[[A-Z_]+\]\s*/, '').trim();
|
|
96
|
-
throw new ProjectSyntaxError(`${rel}:${loc.line}:${loc.column}
|
|
96
|
+
throw new ProjectSyntaxError(`${rel}:${loc.line}:${loc.column} syntax error: ${brief || 'Cannot parse'}`, { file, ...loc });
|
|
97
97
|
}
|
|
98
98
|
},
|
|
99
99
|
};
|
package/dist/web-assets.js
CHANGED
|
@@ -17,7 +17,7 @@ const require = createRequire(import.meta.url);
|
|
|
17
17
|
const FROM_SOURCE = import.meta.filename.endsWith('.ts');
|
|
18
18
|
const REPO_WEB = path.resolve(import.meta.dirname, '../../web');
|
|
19
19
|
const REPO_KIT = path.resolve(import.meta.dirname, '../../kit/src');
|
|
20
|
-
const broken = (webDir, what) => new JoploError('NOT_FOUND', `@joplo-app/web
|
|
20
|
+
const broken = (webDir, what) => new JoploError('NOT_FOUND', `@joplo-app/web (${webDir}) is missing prebuilt assets: ${what}. Reinstall joplo (npm install), or run pnpm --filter @joplo-app/web build in the Joplo repository`);
|
|
21
21
|
/** 读取并校验 @joplo-app/web 的 dist/manifest.json。 */
|
|
22
22
|
export function readWebDist(webDir) {
|
|
23
23
|
const dist = path.join(webDir, 'dist');
|
|
@@ -30,13 +30,13 @@ export function readWebDist(webDir) {
|
|
|
30
30
|
throw broken(webDir, 'dist/manifest.json');
|
|
31
31
|
}
|
|
32
32
|
if (manifest.format !== 1)
|
|
33
|
-
throw broken(webDir,
|
|
33
|
+
throw broken(webDir, `Unknown manifest format ${String(manifest.format)}`);
|
|
34
34
|
const inside = (rel, label) => {
|
|
35
35
|
if (typeof rel !== 'string' || !rel)
|
|
36
36
|
throw broken(webDir, label);
|
|
37
37
|
const abs = path.resolve(dist, rel);
|
|
38
38
|
if (abs !== dist && !abs.startsWith(dist + path.sep))
|
|
39
|
-
throw broken(webDir, `${label}
|
|
39
|
+
throw broken(webDir, `${label} escapes dist/`);
|
|
40
40
|
if (!fs.existsSync(abs))
|
|
41
41
|
throw broken(webDir, `dist/${rel}`);
|
|
42
42
|
return abs;
|
|
@@ -52,10 +52,10 @@ export function readWebDist(webDir) {
|
|
|
52
52
|
catch (e) {
|
|
53
53
|
if (e instanceof JoploError)
|
|
54
54
|
throw e;
|
|
55
|
-
throw broken(webDir, 'site-files.json
|
|
55
|
+
throw broken(webDir, 'site-files.json is not valid JSON');
|
|
56
56
|
}
|
|
57
57
|
if (!Array.isArray(siteFiles) || !siteFiles.every((f) => typeof f === 'string' && f && !path.isAbsolute(f) && !f.split(/[\\/]/).includes('..')))
|
|
58
|
-
throw broken(webDir, 'site-files.json
|
|
58
|
+
throw broken(webDir, 'site-files.json must be a list of relative paths within appDir');
|
|
59
59
|
return { mode: 'dist', webDir, appDir, siteFiles, projectCss, version: typeof manifest.version === 'string' ? manifest.version : '' };
|
|
60
60
|
}
|
|
61
61
|
let cached = null;
|
|
@@ -73,7 +73,7 @@ export function locateWebAssets(env) {
|
|
|
73
73
|
pkg = require.resolve('@joplo-app/web/package.json');
|
|
74
74
|
}
|
|
75
75
|
catch {
|
|
76
|
-
throw new JoploError('NOT_FOUND', '
|
|
76
|
+
throw new JoploError('NOT_FOUND', 'Cannot find @joplo-app/web (board and published site assets). Reinstall joplo (npm install)');
|
|
77
77
|
}
|
|
78
78
|
out = readWebDist(path.dirname(fs.realpathSync(pkg)));
|
|
79
79
|
}
|
|
@@ -118,7 +118,7 @@ export function kitAliases(web, projectDir) {
|
|
|
118
118
|
const main = fileURLToPath(import.meta.resolve('@joplo-app/kit'));
|
|
119
119
|
const sub = fileURLToPath(import.meta.resolve(`@joplo-app/kit/${KIT_SUBPATHS[0]}`));
|
|
120
120
|
if (path.dirname(main) !== path.dirname(sub))
|
|
121
|
-
throw new JoploError('NOT_FOUND', `@joplo-app/kit
|
|
121
|
+
throw new JoploError('NOT_FOUND', `@joplo-app/kit entry points are not in the same directory: ${main}, ${sub}`);
|
|
122
122
|
const ext = path.extname(main);
|
|
123
123
|
return [
|
|
124
124
|
{ find: /^@joplo-app\/kit$/, replacement: main },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@joplo-app/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Joplo 本地服务:dev 看板、build 发布站、render 截图",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@joplo-app/core": "0.
|
|
19
|
-
"@joplo-app/kit": "0.
|
|
20
|
-
"@joplo-app/web": "0.
|
|
18
|
+
"@joplo-app/core": "0.2.0",
|
|
19
|
+
"@joplo-app/kit": "0.2.0",
|
|
20
|
+
"@joplo-app/web": "0.2.0",
|
|
21
21
|
"@tailwindcss/vite": "4.3.4",
|
|
22
22
|
"tailwindcss": "4.3.4",
|
|
23
23
|
"vite": "8.3.5",
|