@blocklet/pages-kit-inner-components 0.6.101 → 0.6.103
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/add-component.js +1 -1
- package/lib/cjs/chunks/{components-DLLpFRy5.js → components-DsHjikTX.js} +1 -1
- package/lib/cjs/chunks/{home-Bu90cJ-l.js → home-DdN3Z-6B.js} +2 -2
- package/lib/cjs/chunks/{index-B4sanPsc.js → index-B-Wh6PRT.js} +12 -12
- package/lib/cjs/chunks/{publish-button-gIqRDc2d.js → publish-button-BtLFUEny.js} +1 -1
- package/lib/cjs/chunks/site-state-DlLhHuIr.js +1 -0
- package/lib/cjs/components.js +1 -1
- package/lib/cjs/home.js +1 -1
- package/lib/cjs/project-html.js +1 -1
- package/lib/cjs/resources.js +1 -1
- package/lib/cjs/site-state.js +1 -1
- package/lib/es/add-component.js +1 -1
- package/lib/es/chunks/{components-DLwSTd_N.js → components-BIhMGXjB.js} +1 -1
- package/lib/es/chunks/{home-BGCy4qtn.js → home-DVTVPkSm.js} +2 -2
- package/lib/es/chunks/{index-B3PuGYfF.js → index-DENjTU8O.js} +94 -79
- package/lib/es/chunks/{publish-button-5KAKGqbO.js → publish-button-BVcMw8Fh.js} +2 -2
- package/lib/es/chunks/{site-state-DyS5vqWT.js → site-state-CN4Kulgk.js} +418 -415
- package/lib/es/components.js +1 -1
- package/lib/es/home.js +2 -2
- package/lib/es/project-html.js +1 -1
- package/lib/es/resources.js +2 -2
- package/lib/es/site-state.js +2 -2
- package/package.json +7 -7
- package/lib/cjs/chunks/site-state-uZR_uvZu.js +0 -1
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { d as Fe, l as f, I as
|
|
2
|
-
import { getYjsValue as V, syncedStore as
|
|
1
|
+
import { d as Fe, l as f, I as st, c as ot, m as at, b as nt } from "./components-BIhMGXjB.js";
|
|
2
|
+
import { getYjsValue as V, syncedStore as rt } from "@syncedstore/core";
|
|
3
3
|
import * as N from "yjs";
|
|
4
|
-
import { setPageDataSource as
|
|
5
|
-
import { getRouteMetaDataByOptionIds as
|
|
4
|
+
import { setPageDataSource as it } from "@blocklet/pages-kit/utils/data-source";
|
|
5
|
+
import { getRouteMetaDataByOptionIds as ct, generateParamCombinations as Ie } from "@blocklet/pages-kit/utils/route";
|
|
6
6
|
import Ee from "lodash/cloneDeep";
|
|
7
7
|
import E from "@blocklet/sdk/lib/config";
|
|
8
|
-
import { mkdtempSync as
|
|
8
|
+
import { mkdtempSync as lt, existsSync as $, readFileSync as J, renameSync as Re, mkdirSync as _, rmSync as Ge, writeFileSync as te, copyFileSync as pt, lstatSync as x, readdirSync as ut, createWriteStream as dt } from "fs";
|
|
9
9
|
import { join as b, basename as k, dirname as L } from "path";
|
|
10
10
|
import { nextId as De } from "@blocklet/pages-kit/utils/common";
|
|
11
|
-
import { unzipSection as
|
|
12
|
-
import { getComponentDependencies as
|
|
13
|
-
import { getComponentWebEndpoint as
|
|
14
|
-
import { reactive as
|
|
11
|
+
import { unzipSection as ft } from "@blocklet/pages-kit/utils/page-model";
|
|
12
|
+
import { getComponentDependencies as mt } from "@blocklet/pages-kit/utils/property";
|
|
13
|
+
import { getComponentWebEndpoint as gt, getResources as ht, call as yt } from "@blocklet/sdk/lib/component";
|
|
14
|
+
import { reactive as St } from "@reactivedata/reactive";
|
|
15
15
|
import { globSync as se } from "glob";
|
|
16
16
|
import * as de from "lib0/decoding";
|
|
17
17
|
import * as D from "lib0/encoding";
|
|
@@ -19,16 +19,16 @@ import xe from "lodash/debounce";
|
|
|
19
19
|
import be from "lodash/get";
|
|
20
20
|
import Ae from "lodash/isEmpty";
|
|
21
21
|
import Te from "lodash/set";
|
|
22
|
-
import
|
|
22
|
+
import It from "lodash/union";
|
|
23
23
|
import { LRUCache as we } from "lru-cache";
|
|
24
|
-
import
|
|
25
|
-
import { DataTypes as R, Sequelize as Et, Model as
|
|
24
|
+
import Be from "p-limit";
|
|
25
|
+
import { DataTypes as R, Sequelize as Et, Model as Ve, Op as Pe } from "sequelize";
|
|
26
26
|
import { pipeline as bt } from "stream/promises";
|
|
27
27
|
import { x as At } from "tar";
|
|
28
|
-
import { withoutTrailingSlash as Oe, withLeadingSlash as
|
|
28
|
+
import { withoutTrailingSlash as Oe, withLeadingSlash as ze, joinURL as Y } from "ufo";
|
|
29
29
|
import wt from "wait-on";
|
|
30
30
|
import { Awareness as Pt, encodeAwarenessUpdate as ke, removeAwarenessStates as Ot, applyAwarenessUpdate as Ct } from "y-protocols/awareness";
|
|
31
|
-
import { writeUpdate as vt, writeSyncStep1 as
|
|
31
|
+
import { writeUpdate as vt, writeSyncStep1 as jt, readSyncMessage as Rt } from "y-protocols/sync";
|
|
32
32
|
import * as B from "yaml";
|
|
33
33
|
import { m as Le } from "./html-DOgzvdOd.js";
|
|
34
34
|
import "sqlite3";
|
|
@@ -81,8 +81,8 @@ ge = setInterval(
|
|
|
81
81
|
60 * 1e3 * 10
|
|
82
82
|
// 10 minutes
|
|
83
83
|
);
|
|
84
|
-
const kt = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o", Ue = "page", he = "trigger-reload-project-resource",
|
|
85
|
-
class Ce extends
|
|
84
|
+
const kt = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o", Ue = "page", he = "trigger-reload-project-resource", qe = kt, Lt = "z2qa7BQdkEb3TwYyEYC1psK6uvmGnHSUHt5RM", Ut = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o";
|
|
85
|
+
class Ce extends Ve {
|
|
86
86
|
// Foreign key to Component
|
|
87
87
|
}
|
|
88
88
|
Ce.init(
|
|
@@ -139,9 +139,9 @@ const Mt = "SLUG_INVALID", K = (t) => ({
|
|
|
139
139
|
if (!t) return "";
|
|
140
140
|
if (t === "/") return "/";
|
|
141
141
|
const e = Oe(t);
|
|
142
|
-
return
|
|
142
|
+
return ze(e) || "/";
|
|
143
143
|
}, Ft = (t) => t.did === Ut;
|
|
144
|
-
class U extends
|
|
144
|
+
class U extends Ve {
|
|
145
145
|
static async getProjectByIdOrSlug(e, s) {
|
|
146
146
|
return e ? U.findOne({
|
|
147
147
|
where: {
|
|
@@ -158,7 +158,7 @@ class U extends Be {
|
|
|
158
158
|
return null;
|
|
159
159
|
if (e === "")
|
|
160
160
|
return $t;
|
|
161
|
-
const o = e === "/" ? "/" : Oe(
|
|
161
|
+
const o = e === "/" ? "/" : Oe(ze(e)), a = Me(o);
|
|
162
162
|
if (o !== "/" && o.endsWith("/"))
|
|
163
163
|
return K((r) => `Project slug "${r}" cannot end with /`);
|
|
164
164
|
if (/\/{2,}/.test(o))
|
|
@@ -288,8 +288,8 @@ function oe(t) {
|
|
|
288
288
|
e.some((s) => s.changes.keys.has("updatedAt") || s.changes.keys.has("publishedAt")) || t.set("updatedAt", (/* @__PURE__ */ new Date()).toISOString());
|
|
289
289
|
});
|
|
290
290
|
}
|
|
291
|
-
function
|
|
292
|
-
return
|
|
291
|
+
function Ke() {
|
|
292
|
+
return lt(b(E.env.dataDir, "tmp-"));
|
|
293
293
|
}
|
|
294
294
|
function ae(t, e, s = []) {
|
|
295
295
|
return Array.isArray(t) ? t.flatMap((o, a) => ae(o, e, [...s, a])) : typeof t == "object" ? t === null ? [] : Object.entries(t).flatMap(([o, a]) => ae(a, e, [...s, o])) : e(t) ? [s] : [];
|
|
@@ -340,7 +340,7 @@ function Bt(t, e) {
|
|
|
340
340
|
if (!n || !n.params || n.params.length === 0)
|
|
341
341
|
continue;
|
|
342
342
|
if (s.includes("-") && a.length > 0) {
|
|
343
|
-
const c =
|
|
343
|
+
const c = ct(a, n);
|
|
344
344
|
c && (c.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
|
|
345
345
|
}
|
|
346
346
|
if (!e) {
|
|
@@ -383,10 +383,10 @@ function fe({
|
|
|
383
383
|
if (e.dataSource) {
|
|
384
384
|
let r = e.id;
|
|
385
385
|
a && (r = a.paramOptionIds.join("-"));
|
|
386
|
-
const
|
|
387
|
-
if (!
|
|
386
|
+
const l = e.dataSource.pathDataMappings?.[r]?.dataCache?.[c.locale] ?? e.dataSource.pathDataMappings?.[r]?.dataCache?.[s.config.defaultLocale || "en"];
|
|
387
|
+
if (!l)
|
|
388
388
|
continue;
|
|
389
|
-
|
|
389
|
+
it(n, s, c.locale, l);
|
|
390
390
|
}
|
|
391
391
|
a && a.routeMetaData && (a.routeMetaData.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
|
|
392
392
|
}
|
|
@@ -394,7 +394,7 @@ function fe({
|
|
|
394
394
|
}
|
|
395
395
|
["true", "1", "yes", "y"].includes(process.env.USE_FS_CACHE_HTML ?? "");
|
|
396
396
|
const Vt = 60 * 60 * 1e3, W = new we({
|
|
397
|
-
max:
|
|
397
|
+
max: 300,
|
|
398
398
|
ttl: Vt,
|
|
399
399
|
ttlResolution: 10 * 1e3,
|
|
400
400
|
// 10 seconds
|
|
@@ -441,10 +441,10 @@ function Xt() {
|
|
|
441
441
|
resources: {}
|
|
442
442
|
};
|
|
443
443
|
}
|
|
444
|
-
class
|
|
444
|
+
class C extends N.Doc {
|
|
445
445
|
constructor(e) {
|
|
446
|
-
super(), this.options = e, $(this.draftYjsFilePath) && N.applyUpdate(this, J(this.draftYjsFilePath)), this.syncedStore =
|
|
447
|
-
|
|
446
|
+
super(), this.options = e, $(this.draftYjsFilePath) && N.applyUpdate(this, J(this.draftYjsFilePath)), this.syncedStore = St(
|
|
447
|
+
rt(
|
|
448
448
|
{
|
|
449
449
|
pages: {},
|
|
450
450
|
pageIds: [],
|
|
@@ -468,7 +468,7 @@ class O extends N.Doc {
|
|
|
468
468
|
// 2 hours
|
|
469
469
|
static sharedInstances = {};
|
|
470
470
|
static pageUrlMapCache = new we({
|
|
471
|
-
max:
|
|
471
|
+
max: 300,
|
|
472
472
|
ttl: 1e3 * 60 * 60 * 24
|
|
473
473
|
// 1 day
|
|
474
474
|
});
|
|
@@ -480,7 +480,7 @@ class O extends N.Doc {
|
|
|
480
480
|
throw new Error("Should provide project context");
|
|
481
481
|
try {
|
|
482
482
|
const s = b(H, e), o = b(H, `@del-${e}`);
|
|
483
|
-
|
|
483
|
+
Re(s, o);
|
|
484
484
|
} catch (s) {
|
|
485
485
|
f.error("Failed to safe delete project state dir:", s);
|
|
486
486
|
}
|
|
@@ -498,15 +498,15 @@ class O extends N.Doc {
|
|
|
498
498
|
}
|
|
499
499
|
/** @deprecated 不再使用这个 getter 了,仅作为兼容性处理 */
|
|
500
500
|
static get allShared() {
|
|
501
|
-
return this.projectIds.map((e) =>
|
|
501
|
+
return this.projectIds.map((e) => C.shared(e));
|
|
502
502
|
}
|
|
503
503
|
static shared(e) {
|
|
504
504
|
if (!e)
|
|
505
505
|
throw new Error("Should provide project context");
|
|
506
|
-
let s =
|
|
507
|
-
return s || (s = new
|
|
506
|
+
let s = C.sharedInstances[e];
|
|
507
|
+
return s || (s = new C({
|
|
508
508
|
path: b(H, e)
|
|
509
|
-
}),
|
|
509
|
+
}), C.sharedInstances[e] = s, s);
|
|
510
510
|
}
|
|
511
511
|
// 轻量级 production 状态获取,不加载 draft 数据
|
|
512
512
|
static async getProductionState(e) {
|
|
@@ -514,7 +514,7 @@ class O extends N.Doc {
|
|
|
514
514
|
attributes: ["productionState"]
|
|
515
515
|
});
|
|
516
516
|
if (Ae(s?.productionState)) {
|
|
517
|
-
const o = b(H, e, "production"), a = await
|
|
517
|
+
const o = b(H, e, "production"), a = await Je(o, { includeResources: !0 }) ?? Xt();
|
|
518
518
|
if (!a?.config?.defaultLocale) {
|
|
519
519
|
a.config ??= {};
|
|
520
520
|
const n = ye.env.languages?.map((c) => ({ locale: c.code, name: c.name })) || [];
|
|
@@ -527,7 +527,7 @@ class O extends N.Doc {
|
|
|
527
527
|
destroy() {
|
|
528
528
|
this.cancelRelease(), this.save({ flush: !0 }), this.conns.forEach((s, o) => this.closeConn(o)), this.awareness.destroy();
|
|
529
529
|
const e = k(this.options.path);
|
|
530
|
-
delete
|
|
530
|
+
delete C.sharedInstances[e], super.destroy();
|
|
531
531
|
}
|
|
532
532
|
initObserver() {
|
|
533
533
|
Gt(this.syncedStore), xt(this.syncedStore);
|
|
@@ -537,22 +537,22 @@ class O extends N.Doc {
|
|
|
537
537
|
}
|
|
538
538
|
static async getStateByProjectId(e, s) {
|
|
539
539
|
if (s === "draft") {
|
|
540
|
-
const o =
|
|
540
|
+
const o = C.shared(e);
|
|
541
541
|
return JSON.parse(JSON.stringify(o.syncedStore));
|
|
542
542
|
}
|
|
543
|
-
return
|
|
543
|
+
return C.getProductionState(e);
|
|
544
544
|
}
|
|
545
545
|
async getState(e) {
|
|
546
546
|
if (e === "draft")
|
|
547
547
|
return JSON.parse(JSON.stringify(this.syncedStore));
|
|
548
548
|
const s = k(this.options.path);
|
|
549
|
-
return
|
|
549
|
+
return C.getProductionState(s);
|
|
550
550
|
}
|
|
551
551
|
async setState(e, s) {
|
|
552
552
|
const o = await ts(s, { exportAssets: !1, includeResources: !0 }), a = this.getPublishDir(e);
|
|
553
|
-
if (_(L(a), { recursive: !0 }), Ge(a, { force: !0, recursive: !0 }),
|
|
553
|
+
if (_(L(a), { recursive: !0 }), Ge(a, { force: !0, recursive: !0 }), Re(o, a), e === "production") {
|
|
554
554
|
const n = k(this.options.path);
|
|
555
|
-
|
|
555
|
+
C.pageUrlMapCache.delete(n);
|
|
556
556
|
const c = Ee(s);
|
|
557
557
|
await U.update({ productionState: c }, { where: { id: n } });
|
|
558
558
|
}
|
|
@@ -568,17 +568,17 @@ class O extends N.Doc {
|
|
|
568
568
|
awarenessChangeHandler = ({ added: e, updated: s, removed: o }, a) => {
|
|
569
569
|
const n = e.concat(s, o);
|
|
570
570
|
if (a !== null) {
|
|
571
|
-
const
|
|
572
|
-
|
|
573
|
-
|
|
571
|
+
const l = this.conns.get(a);
|
|
572
|
+
l && (e.forEach((y) => {
|
|
573
|
+
l.add(y);
|
|
574
574
|
}), o.forEach((y) => {
|
|
575
|
-
|
|
575
|
+
l.delete(y);
|
|
576
576
|
}));
|
|
577
577
|
}
|
|
578
578
|
const c = D.createEncoder();
|
|
579
579
|
D.writeVarUint(c, me), D.writeVarUint8Array(c, ke(this.awareness, n));
|
|
580
580
|
const r = D.toUint8Array(c);
|
|
581
|
-
this.conns.forEach((
|
|
581
|
+
this.conns.forEach((l, y) => this.send(y, r));
|
|
582
582
|
};
|
|
583
583
|
updateHandler = (e) => {
|
|
584
584
|
const s = D.createEncoder();
|
|
@@ -590,27 +590,27 @@ class O extends N.Doc {
|
|
|
590
590
|
const { supportedLocales: e, pages: s, pageIds: o, config: a, routes: n, routeIds: c } = this.syncedStore;
|
|
591
591
|
{
|
|
592
592
|
const r = new Set(Object.keys(s));
|
|
593
|
-
let
|
|
594
|
-
for (;
|
|
595
|
-
const y = o[
|
|
596
|
-
r.has(y) ? (r.delete(y),
|
|
593
|
+
let l = 0;
|
|
594
|
+
for (; l < o.length; ) {
|
|
595
|
+
const y = o[l];
|
|
596
|
+
r.has(y) ? (r.delete(y), l++) : o.splice(l, 1);
|
|
597
597
|
}
|
|
598
598
|
}
|
|
599
599
|
{
|
|
600
600
|
const r = new Set(Object.keys(n));
|
|
601
|
-
let
|
|
602
|
-
for (;
|
|
603
|
-
const y = c[
|
|
604
|
-
r.has(y) ? (r.delete(y),
|
|
601
|
+
let l = 0;
|
|
602
|
+
for (; l < c.length; ) {
|
|
603
|
+
const y = c[l];
|
|
604
|
+
r.has(y) ? (r.delete(y), l++) : c.splice(l, 1);
|
|
605
605
|
}
|
|
606
606
|
}
|
|
607
607
|
e.splice(0, e.length), e.push(...ye.env.languages.map((r) => ({ locale: r.code, name: r.name }))), a.defaultLocale = e[0]?.locale;
|
|
608
608
|
{
|
|
609
609
|
let r = 0;
|
|
610
|
-
const
|
|
610
|
+
const l = /* @__PURE__ */ new Set();
|
|
611
611
|
for (; r < e.length; ) {
|
|
612
612
|
const { locale: y } = e[r];
|
|
613
|
-
|
|
613
|
+
l.has(y) ? e.splice(r, 1) : (r++, l.add(y));
|
|
614
614
|
}
|
|
615
615
|
}
|
|
616
616
|
};
|
|
@@ -641,7 +641,7 @@ class O extends N.Doc {
|
|
|
641
641
|
const e = k(this.options.path);
|
|
642
642
|
this.releaseTimer = setTimeout(() => {
|
|
643
643
|
f.info(`[SiteState] releasing instance due to no active connections: ${e}`), this.conns.size === 0 && (this.releaseTimer = void 0, this.destroy());
|
|
644
|
-
},
|
|
644
|
+
}, C.RELEASE_DELAY), f.info(`[SiteState] scheduled release for project ${e} in ${C.RELEASE_DELAY / 1e3}s`);
|
|
645
645
|
}
|
|
646
646
|
// 取消延迟释放
|
|
647
647
|
cancelRelease() {
|
|
@@ -670,10 +670,10 @@ class O extends N.Doc {
|
|
|
670
670
|
e.config.fontFamily.title = a?.title || n?.title, e.config.fontFamily.description = a?.description || n?.description, await new Promise((c, r) => {
|
|
671
671
|
this.transact(async () => {
|
|
672
672
|
try {
|
|
673
|
-
const
|
|
674
|
-
c(
|
|
675
|
-
} catch (
|
|
676
|
-
r(
|
|
673
|
+
const l = await _e(e, s);
|
|
674
|
+
c(l);
|
|
675
|
+
} catch (l) {
|
|
676
|
+
r(l);
|
|
677
677
|
}
|
|
678
678
|
});
|
|
679
679
|
});
|
|
@@ -682,18 +682,18 @@ class O extends N.Doc {
|
|
|
682
682
|
const o = k(this.options.path), n = (await U.findByPk(o))?.slug || o;
|
|
683
683
|
let c = e;
|
|
684
684
|
(!c || c.length === 0) && (c = s.pageIds ?? []), f.info(`[SiteState] clearing page cache for project ${o}, routes:`, c || []);
|
|
685
|
-
const r = s.supportedLocales.map((
|
|
686
|
-
for (const
|
|
687
|
-
const
|
|
688
|
-
n && n !== o && (n === "/" ?
|
|
685
|
+
const r = s.supportedLocales.map((O) => O.locale), l = [], y = c.filter((O) => s.pageIds?.includes(O));
|
|
686
|
+
for (const O of y) {
|
|
687
|
+
const S = s.pages[O].slug;
|
|
688
|
+
n && n !== o && (n === "/" ? l.push(S) : l.push(`/${n}${S}`)), l.push(`/${o}${S}`);
|
|
689
689
|
}
|
|
690
|
-
if (
|
|
690
|
+
if (l.length > 0)
|
|
691
691
|
try {
|
|
692
|
-
const
|
|
693
|
-
f.info(`[SiteState] cleared ${
|
|
692
|
+
const O = zt(l, r);
|
|
693
|
+
f.info(`[SiteState] cleared ${O} page cache entries for project ${o}, routes:`, c);
|
|
694
694
|
} catch {
|
|
695
695
|
}
|
|
696
|
-
|
|
696
|
+
C.pageUrlMapCache.delete(o);
|
|
697
697
|
};
|
|
698
698
|
addConnection = (e) => {
|
|
699
699
|
if (this.conns.has(e))
|
|
@@ -719,7 +719,7 @@ class O extends N.Doc {
|
|
|
719
719
|
});
|
|
720
720
|
{
|
|
721
721
|
const a = D.createEncoder();
|
|
722
|
-
D.writeVarUint(a, Z),
|
|
722
|
+
D.writeVarUint(a, Z), jt(a, this), this.send(e, D.toUint8Array(a));
|
|
723
723
|
const n = this.awareness.getStates();
|
|
724
724
|
if (n.size > 0) {
|
|
725
725
|
const c = D.createEncoder();
|
|
@@ -732,7 +732,7 @@ class O extends N.Doc {
|
|
|
732
732
|
const o = D.createEncoder(), a = de.createDecoder(s), n = de.readVarUint(a);
|
|
733
733
|
switch (n) {
|
|
734
734
|
case Z:
|
|
735
|
-
D.writeVarUint(o, Z),
|
|
735
|
+
D.writeVarUint(o, Z), Rt(a, o, this, null), D.length(o) > 1 && (this.ensureDataStructure(), this.send(e, D.toUint8Array(o)));
|
|
736
736
|
break;
|
|
737
737
|
case me: {
|
|
738
738
|
Ct(this.awareness, de.readVarUint8Array(a), e);
|
|
@@ -748,14 +748,15 @@ class O extends N.Doc {
|
|
|
748
748
|
};
|
|
749
749
|
// 这个方法还是需要动态的,因为可能会动态修改 projectSlug、语言之类的
|
|
750
750
|
static async pageUrlMap(e, s) {
|
|
751
|
+
f.info(`[SiteState] get pageUrlMap, mode: ${e}, projectId: ${s}`);
|
|
751
752
|
let o = [];
|
|
752
753
|
s ? o = [s] : o = await this.getProjectIds();
|
|
753
754
|
let a = {};
|
|
754
755
|
if (e === "production" && o?.length) {
|
|
755
756
|
const n = new Map(o?.map((c) => [c, !0]) || []);
|
|
756
757
|
for (const c of o) {
|
|
757
|
-
const r =
|
|
758
|
-
r && (a = { ...a, ...r }, n.delete(c));
|
|
758
|
+
const r = C.pageUrlMapCache.get(c);
|
|
759
|
+
r && (f.info(`[SiteState] get pageUrlMap from cache, projectId: ${c}`), a = { ...a, ...r }, n.delete(c));
|
|
759
760
|
}
|
|
760
761
|
o = Array.from(n.keys());
|
|
761
762
|
}
|
|
@@ -766,102 +767,104 @@ class O extends N.Doc {
|
|
|
766
767
|
[Pe.in]: o
|
|
767
768
|
}
|
|
768
769
|
}
|
|
769
|
-
});
|
|
770
|
+
}), c = Be(10);
|
|
770
771
|
await Promise.all(
|
|
771
|
-
n?.map(
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
772
|
+
n?.map(
|
|
773
|
+
(r) => c(async () => {
|
|
774
|
+
const l = r.id, y = r.slug || l, O = {}, j = e === "production" && r?.productionState ? r.productionState : await C.getStateByProjectId(r.id, e), S = It(
|
|
775
|
+
E.env.languages?.map((p) => p.code) || [],
|
|
776
|
+
j.supportedLocales?.map((p) => p.locale) || []
|
|
777
|
+
), g = (p, d) => {
|
|
778
|
+
y && (O[Y("/", y, p)] = {
|
|
779
|
+
...d,
|
|
780
|
+
shouldRedirect: !0,
|
|
781
|
+
mainPage: !0
|
|
782
|
+
}), O[Y("/", l, p)] = {
|
|
783
|
+
...d,
|
|
784
|
+
shouldRedirect: !0,
|
|
785
|
+
mainPage: !0
|
|
786
|
+
};
|
|
787
|
+
for (const A of S) {
|
|
788
|
+
const m = { ...d, locale: A };
|
|
789
|
+
O[Y("/", A, l, p)] = m, y && (O[Y("/", A, y, p)] = m);
|
|
790
|
+
}
|
|
784
791
|
};
|
|
785
|
-
|
|
786
|
-
const
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
publishedAt: A.config.publishedAt,
|
|
816
|
-
isPublic: l.isPublic && d?.routeMetaData?.isPublic
|
|
817
|
-
};
|
|
818
|
-
I(h, w);
|
|
792
|
+
if (e === "draft")
|
|
793
|
+
for (const p of j.routeIds || []) {
|
|
794
|
+
const d = j?.routes?.[p];
|
|
795
|
+
if (!d) continue;
|
|
796
|
+
if (d.params && d.params.length > 0) {
|
|
797
|
+
const u = Ie({
|
|
798
|
+
basePath: d.path,
|
|
799
|
+
params: d.params,
|
|
800
|
+
routeId: d.id,
|
|
801
|
+
paramsOptions: d.paramsOptions,
|
|
802
|
+
currentIndex: 0,
|
|
803
|
+
currentParams: [],
|
|
804
|
+
currentOptionIds: [],
|
|
805
|
+
result: []
|
|
806
|
+
});
|
|
807
|
+
for (const h of u) {
|
|
808
|
+
const P = h.path, w = {
|
|
809
|
+
projectId: l,
|
|
810
|
+
projectSlug: y,
|
|
811
|
+
pageSlug: P,
|
|
812
|
+
pageId: d.displayTemplateId || "",
|
|
813
|
+
routeId: p,
|
|
814
|
+
// default locale
|
|
815
|
+
defaultLocale: S?.[0],
|
|
816
|
+
locales: S,
|
|
817
|
+
publishedAt: j.config.publishedAt,
|
|
818
|
+
isPublic: d.isPublic && h?.routeMetaData?.isPublic
|
|
819
|
+
};
|
|
820
|
+
g(P, w);
|
|
821
|
+
}
|
|
819
822
|
}
|
|
823
|
+
const A = d.path, m = {
|
|
824
|
+
projectId: l,
|
|
825
|
+
projectSlug: y,
|
|
826
|
+
pageSlug: A,
|
|
827
|
+
pageId: d.displayTemplateId || "",
|
|
828
|
+
routeId: p,
|
|
829
|
+
// default locale
|
|
830
|
+
defaultLocale: S?.[0],
|
|
831
|
+
locales: S,
|
|
832
|
+
publishedAt: j.config.publishedAt,
|
|
833
|
+
isPublic: d.isPublic
|
|
834
|
+
};
|
|
835
|
+
g(A, m);
|
|
820
836
|
}
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
837
|
+
for (const p of j.pageIds || []) {
|
|
838
|
+
const d = j.pages[p];
|
|
839
|
+
if (!d || e === "production" && !d.isPublic)
|
|
840
|
+
continue;
|
|
841
|
+
const A = d.slug, m = r.slug || l, u = {
|
|
842
|
+
projectId: l,
|
|
843
|
+
projectSlug: m,
|
|
844
|
+
pageSlug: A,
|
|
845
|
+
pageId: p,
|
|
827
846
|
// default locale
|
|
828
|
-
defaultLocale:
|
|
829
|
-
locales:
|
|
830
|
-
publishedAt:
|
|
831
|
-
isPublic:
|
|
847
|
+
defaultLocale: S?.[0],
|
|
848
|
+
locales: S,
|
|
849
|
+
publishedAt: j.config.publishedAt,
|
|
850
|
+
isPublic: d.isPublic,
|
|
851
|
+
templateConfig: d.templateConfig
|
|
832
852
|
};
|
|
833
|
-
|
|
853
|
+
g(A, u);
|
|
834
854
|
}
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
continue;
|
|
839
|
-
const g = l.slug, C = c.slug || r, m = {
|
|
840
|
-
projectId: r,
|
|
841
|
-
projectSlug: C,
|
|
842
|
-
pageSlug: g,
|
|
843
|
-
pageId: u,
|
|
844
|
-
// default locale
|
|
845
|
-
defaultLocale: j?.[0],
|
|
846
|
-
locales: j,
|
|
847
|
-
publishedAt: A.config.publishedAt,
|
|
848
|
-
isPublic: l.isPublic,
|
|
849
|
-
templateConfig: l.templateConfig
|
|
850
|
-
};
|
|
851
|
-
I(g, m);
|
|
852
|
-
}
|
|
853
|
-
e === "production" && O.pageUrlMapCache.set(r, y), a = { ...a, ...y };
|
|
854
|
-
})
|
|
855
|
+
e === "production" && (C.pageUrlMapCache.set(l, O), f.info(`[SiteState] set pageUrlMap to cache, projectId: ${l}`)), a = { ...a, ...O };
|
|
856
|
+
})
|
|
857
|
+
)
|
|
855
858
|
);
|
|
856
859
|
}
|
|
857
|
-
return a;
|
|
860
|
+
return f.info("[SiteState] success get pageUrlMap"), a;
|
|
858
861
|
}
|
|
859
862
|
getDocumentSize() {
|
|
860
863
|
return N.encodeStateAsUpdate(this).byteLength;
|
|
861
864
|
}
|
|
862
865
|
static getInstancesSizeInfo() {
|
|
863
866
|
const e = [];
|
|
864
|
-
for (const [s, o] of Object.entries(
|
|
867
|
+
for (const [s, o] of Object.entries(C.sharedInstances)) {
|
|
865
868
|
const a = o.getDocumentSize();
|
|
866
869
|
e.push({
|
|
867
870
|
projectId: s,
|
|
@@ -886,8 +889,8 @@ class O extends N.Doc {
|
|
|
886
889
|
}
|
|
887
890
|
// 执行定期检查
|
|
888
891
|
static performPeriodicCheck() {
|
|
889
|
-
const e = Object.keys(
|
|
890
|
-
for (const [a, n] of Object.entries(
|
|
892
|
+
const e = Object.keys(C.sharedInstances).length, s = [], o = [];
|
|
893
|
+
for (const [a, n] of Object.entries(C.sharedInstances))
|
|
891
894
|
n.conns.size === 0 ? s.push({ projectId: a, instance: n }) : o.push({ projectId: a, connections: n.conns.size });
|
|
892
895
|
if (f.info(
|
|
893
896
|
`[SiteState] periodic check summary: total instances: ${e}, with connections: ${o.length}, without connections: ${s.length}`
|
|
@@ -925,14 +928,14 @@ async function Qt(t, e, s) {
|
|
|
925
928
|
})(), s[t] = o), o;
|
|
926
929
|
}
|
|
927
930
|
const Zt = async (t, e) => {
|
|
928
|
-
const s = k(t), o = await
|
|
929
|
-
name:
|
|
931
|
+
const s = k(t), o = await yt({
|
|
932
|
+
name: qe,
|
|
930
933
|
path: Y("/uploads", s),
|
|
931
934
|
responseType: "stream",
|
|
932
935
|
method: "GET"
|
|
933
936
|
});
|
|
934
937
|
if (o.status >= 200 && o.status < 400) {
|
|
935
|
-
const a =
|
|
938
|
+
const a = dt(e);
|
|
936
939
|
await bt(o.data, a);
|
|
937
940
|
} else
|
|
938
941
|
throw new Error(`download asset failed ${o.status}`);
|
|
@@ -947,7 +950,7 @@ const Zt = async (t, e) => {
|
|
|
947
950
|
})
|
|
948
951
|
);
|
|
949
952
|
};
|
|
950
|
-
function
|
|
953
|
+
function He(t) {
|
|
951
954
|
return ve.test(t) ? [t] : X.test(t) ? ($e.lastIndex = 0, Array.from(t.matchAll($e)).map((s) => s[1]).filter((s) => !!s)) : [];
|
|
952
955
|
}
|
|
953
956
|
async function ee(t, e, s) {
|
|
@@ -955,10 +958,10 @@ async function ee(t, e, s) {
|
|
|
955
958
|
if (_(L(n), { recursive: !0 }), te(n, B.stringify(t)), a) {
|
|
956
959
|
const r = ae(
|
|
957
960
|
t,
|
|
958
|
-
(
|
|
959
|
-
).map((
|
|
960
|
-
const y = be(t,
|
|
961
|
-
return
|
|
961
|
+
(l) => typeof l == "string" && (ve.test(l) || X.test(l))
|
|
962
|
+
).map((l) => {
|
|
963
|
+
const y = be(t, l);
|
|
964
|
+
return He(y);
|
|
962
965
|
}).flat().filter(Boolean);
|
|
963
966
|
await es(r, L(n));
|
|
964
967
|
}
|
|
@@ -972,21 +975,21 @@ async function Ne(t, e, s) {
|
|
|
972
975
|
const o = ae(
|
|
973
976
|
t,
|
|
974
977
|
(r) => typeof r == "string" && (ve.test(r) || X.test(r))
|
|
975
|
-
), a =
|
|
978
|
+
), a = Be(2), n = o.map(
|
|
976
979
|
(r) => a(async () => {
|
|
977
980
|
try {
|
|
978
|
-
const
|
|
979
|
-
for (const
|
|
980
|
-
const j = k(
|
|
981
|
-
if (
|
|
982
|
-
X.test(
|
|
981
|
+
const l = be(t, r), y = He(l);
|
|
982
|
+
for (const O of y) {
|
|
983
|
+
const j = k(O), S = s.getFilePath(O, r), g = S ? `${S}:${j}` : j, p = Se.get(g);
|
|
984
|
+
if (p) {
|
|
985
|
+
X.test(l) || Te(t, r, p);
|
|
983
986
|
return;
|
|
984
987
|
}
|
|
985
|
-
const
|
|
986
|
-
|
|
988
|
+
const d = await Qt(S, j, e);
|
|
989
|
+
d && (X.test(l) || Te(t, r, d), Se.set(g, d));
|
|
987
990
|
}
|
|
988
|
-
} catch (
|
|
989
|
-
f.error(`Failed to process upload for path ${r.join(".")}:`,
|
|
991
|
+
} catch (l) {
|
|
992
|
+
f.error(`Failed to process upload for path ${r.join(".")}:`, l.message || l.reason);
|
|
990
993
|
}
|
|
991
994
|
})
|
|
992
995
|
), c = await Promise.allSettled(n);
|
|
@@ -1000,15 +1003,15 @@ async function ts(t, {
|
|
|
1000
1003
|
includeResources: n = !1,
|
|
1001
1004
|
routeIds: c = "all"
|
|
1002
1005
|
} = {}) {
|
|
1003
|
-
const r = s === "all" ? t.pageIds : s,
|
|
1006
|
+
const r = s === "all" ? t.pageIds : s, l = mt({
|
|
1004
1007
|
state: t,
|
|
1005
1008
|
pageIds: r,
|
|
1006
1009
|
componentIds: o === "all" ? Object.keys(t.components) : o
|
|
1007
1010
|
});
|
|
1008
|
-
Object.entries(t.components).forEach(([i,
|
|
1009
|
-
|
|
1011
|
+
Object.entries(t.components).forEach(([i, I]) => {
|
|
1012
|
+
I.data?.renderer?.type === "component-template" && l.push(i);
|
|
1010
1013
|
});
|
|
1011
|
-
const y = c === "all" ? t.routeIds : c,
|
|
1014
|
+
const y = c === "all" ? t.routeIds : c, O = (i) => ({
|
|
1012
1015
|
id: i.id,
|
|
1013
1016
|
name: i.name,
|
|
1014
1017
|
isTemplateSection: i.isTemplateSection ?? !1,
|
|
@@ -1019,32 +1022,32 @@ async function ts(t, {
|
|
|
1019
1022
|
config: i.config,
|
|
1020
1023
|
visibility: i.visibility,
|
|
1021
1024
|
sections: i?.sectionIds ? T(
|
|
1022
|
-
i?.sectionIds?.map((
|
|
1023
|
-
const v = i.sections?.[
|
|
1024
|
-
return v &&
|
|
1025
|
+
i?.sectionIds?.map((I) => {
|
|
1026
|
+
const v = i.sections?.[I];
|
|
1027
|
+
return v && O(v);
|
|
1025
1028
|
})
|
|
1026
1029
|
) : void 0
|
|
1027
1030
|
/** @deprecated 已经废弃,数据在 page.dataSource 中管理 */
|
|
1028
1031
|
// properties: section.locales?.[locale] ?? {},
|
|
1029
|
-
}), j = (i,
|
|
1032
|
+
}), j = (i, I) => ({
|
|
1030
1033
|
id: i.id,
|
|
1031
1034
|
createdAt: i.createdAt,
|
|
1032
1035
|
updatedAt: i.updatedAt,
|
|
1033
1036
|
publishedAt: i.publishedAt,
|
|
1034
1037
|
isPublic: i.isPublic ?? !0,
|
|
1035
1038
|
templateConfig: i.templateConfig,
|
|
1036
|
-
meta: i.locales?.[
|
|
1039
|
+
meta: i.locales?.[I] ?? {},
|
|
1037
1040
|
sections: T(
|
|
1038
1041
|
i.sectionIds.map((v) => {
|
|
1039
1042
|
const G = i.sections[v];
|
|
1040
|
-
return G &&
|
|
1043
|
+
return G && O(G);
|
|
1041
1044
|
})
|
|
1042
1045
|
),
|
|
1043
1046
|
// 将 dataSource.sectionId.locale 转换为 dataSource.sectionId
|
|
1044
1047
|
dataSource: Object.fromEntries(
|
|
1045
|
-
Object.entries(i.dataSource || {}).map(([v, G]) => [v, G?.[
|
|
1048
|
+
Object.entries(i.dataSource || {}).map(([v, G]) => [v, G?.[I] ?? {}])
|
|
1046
1049
|
)
|
|
1047
|
-
}),
|
|
1050
|
+
}), S = (i) => ({
|
|
1048
1051
|
id: i.id,
|
|
1049
1052
|
createdAt: i.createdAt,
|
|
1050
1053
|
updatedAt: i.updatedAt,
|
|
@@ -1056,15 +1059,15 @@ async function ts(t, {
|
|
|
1056
1059
|
enabledGenerate: i.enabledGenerate ?? !1,
|
|
1057
1060
|
displayTemplateId: i.displayTemplateId,
|
|
1058
1061
|
dataSource: i.dataSource
|
|
1059
|
-
}),
|
|
1062
|
+
}), g = T(
|
|
1060
1063
|
y.map((i) => {
|
|
1061
|
-
const
|
|
1062
|
-
return
|
|
1064
|
+
const I = t.routes[i];
|
|
1065
|
+
return I && S(I);
|
|
1063
1066
|
})
|
|
1064
|
-
),
|
|
1067
|
+
), p = T(
|
|
1065
1068
|
t.supportedLocales.map((i) => i.locale).flatMap(
|
|
1066
|
-
(i) => r.map((
|
|
1067
|
-
const v = t.pages[
|
|
1069
|
+
(i) => r.map((I) => {
|
|
1070
|
+
const v = t.pages[I];
|
|
1068
1071
|
return v && {
|
|
1069
1072
|
locale: i,
|
|
1070
1073
|
slug: v.slug,
|
|
@@ -1072,58 +1075,58 @@ async function ts(t, {
|
|
|
1072
1075
|
};
|
|
1073
1076
|
})
|
|
1074
1077
|
)
|
|
1075
|
-
),
|
|
1076
|
-
_(
|
|
1077
|
-
const m = b(
|
|
1078
|
+
), d = Ke(), A = b(d, "pages");
|
|
1079
|
+
_(A, { recursive: !0 });
|
|
1080
|
+
const m = b(d, "components");
|
|
1078
1081
|
_(m, { recursive: !0 });
|
|
1079
|
-
const
|
|
1080
|
-
_(
|
|
1081
|
-
for (const { locale: i, slug:
|
|
1082
|
-
await ee(v,
|
|
1083
|
-
getFilename: () => `${ne(
|
|
1082
|
+
const u = b(d, "routes");
|
|
1083
|
+
_(u, { recursive: !0 });
|
|
1084
|
+
for (const { locale: i, slug: I, page: v } of p)
|
|
1085
|
+
await ee(v, A, {
|
|
1086
|
+
getFilename: () => `${ne(I) || "index"}.${i}.yml`,
|
|
1084
1087
|
exportAssets: e
|
|
1085
1088
|
});
|
|
1086
|
-
for (const i of
|
|
1087
|
-
await ee(i,
|
|
1089
|
+
for (const i of g)
|
|
1090
|
+
await ee(i, u, {
|
|
1088
1091
|
// getFilename: () => `${sanitizeSlug(route.path)}.yml`,
|
|
1089
1092
|
getFilename: () => `${ne(i.path) || "index"}.yml`,
|
|
1090
1093
|
exportAssets: e
|
|
1091
1094
|
});
|
|
1092
|
-
for (const i of
|
|
1093
|
-
const
|
|
1094
|
-
|
|
1095
|
+
for (const i of l) {
|
|
1096
|
+
const I = t.components[i]?.data;
|
|
1097
|
+
I && await ee(I, m, {
|
|
1095
1098
|
getFilename: (v) => `${v.name || "unnamed"}.${v.id}.yml`,
|
|
1096
1099
|
exportAssets: e
|
|
1097
1100
|
});
|
|
1098
1101
|
}
|
|
1099
|
-
const h = b(
|
|
1102
|
+
const h = b(d, ".blocklet/pages/pages.config.yml");
|
|
1100
1103
|
_(L(h), { recursive: !0 });
|
|
1101
|
-
const
|
|
1104
|
+
const P = {
|
|
1102
1105
|
pages: T(
|
|
1103
1106
|
r.map((i) => {
|
|
1104
|
-
const
|
|
1105
|
-
return
|
|
1107
|
+
const I = t.pages[i];
|
|
1108
|
+
return I && { id: i, slug: I.slug };
|
|
1106
1109
|
})
|
|
1107
1110
|
),
|
|
1108
1111
|
routes: T(
|
|
1109
1112
|
y.map((i) => {
|
|
1110
|
-
const
|
|
1111
|
-
return
|
|
1113
|
+
const I = t.routes[i];
|
|
1114
|
+
return I && { id: i, path: I.path };
|
|
1112
1115
|
})
|
|
1113
1116
|
),
|
|
1114
1117
|
components: T(
|
|
1115
|
-
|
|
1116
|
-
const
|
|
1117
|
-
return
|
|
1118
|
+
l.map((i) => {
|
|
1119
|
+
const I = t.components[i]?.data;
|
|
1120
|
+
return I && {
|
|
1118
1121
|
id: i,
|
|
1119
|
-
name:
|
|
1122
|
+
name: I.name
|
|
1120
1123
|
};
|
|
1121
1124
|
})
|
|
1122
1125
|
),
|
|
1123
1126
|
...n ? {
|
|
1124
1127
|
resources: {
|
|
1125
1128
|
components: T(
|
|
1126
|
-
Object.keys(t.resources?.components || {}).filter((i) =>
|
|
1129
|
+
Object.keys(t.resources?.components || {}).filter((i) => l.includes(i)).map((i) => ({
|
|
1127
1130
|
id: i,
|
|
1128
1131
|
name: t.resources?.components?.[i]?.component?.name
|
|
1129
1132
|
}))
|
|
@@ -1133,80 +1136,80 @@ async function ts(t, {
|
|
|
1133
1136
|
supportedLocales: t.supportedLocales,
|
|
1134
1137
|
config: t.config
|
|
1135
1138
|
};
|
|
1136
|
-
te(h, B.stringify(
|
|
1137
|
-
const
|
|
1138
|
-
if (a && te(
|
|
1139
|
-
const i = b(
|
|
1140
|
-
_(
|
|
1139
|
+
te(h, B.stringify(P));
|
|
1140
|
+
const w = b(d, "config.source.json");
|
|
1141
|
+
if (a && te(w, JSON.stringify(a)), n) {
|
|
1142
|
+
const i = b(d, "resources"), I = b(i, "components");
|
|
1143
|
+
_(I, { recursive: !0 });
|
|
1141
1144
|
for (const z of Object.keys(t?.resources?.components ?? {}).filter(
|
|
1142
|
-
(M) =>
|
|
1145
|
+
(M) => l.includes(M)
|
|
1143
1146
|
)) {
|
|
1144
1147
|
const M = t.resources?.components?.[z]?.component;
|
|
1145
|
-
M && await ee(M,
|
|
1148
|
+
M && await ee(M, I, {
|
|
1146
1149
|
getFilename: (q) => `${q.name || "unnamed"}.${q.id}.yml`,
|
|
1147
1150
|
exportAssets: e
|
|
1148
1151
|
});
|
|
1149
1152
|
}
|
|
1150
|
-
const v = b(
|
|
1153
|
+
const v = b(d, "chunks");
|
|
1151
1154
|
_(v, { recursive: !0 });
|
|
1152
1155
|
const G = ss();
|
|
1153
1156
|
for (const z of Object.keys(t?.resources?.components ?? {}).filter(
|
|
1154
|
-
(M) =>
|
|
1157
|
+
(M) => l.includes(M)
|
|
1155
1158
|
)) {
|
|
1156
1159
|
const M = t.resources?.components?.[z]?.component;
|
|
1157
1160
|
if (M && M.renderer?.type === "react-component") {
|
|
1158
1161
|
const q = M.renderer?.chunks ?? [];
|
|
1159
1162
|
if (q?.length > 0)
|
|
1160
1163
|
for (const pe of q) {
|
|
1161
|
-
const
|
|
1164
|
+
const je = b(v, pe), ue = G?.[pe];
|
|
1162
1165
|
try {
|
|
1163
|
-
ue && $(ue) && !$(
|
|
1164
|
-
} catch (
|
|
1165
|
-
f.error(`copy chunk ${pe} error`,
|
|
1166
|
+
ue && $(ue) && !$(je) && pt(ue, je);
|
|
1167
|
+
} catch (tt) {
|
|
1168
|
+
f.error(`copy chunk ${pe} error`, tt.message);
|
|
1166
1169
|
}
|
|
1167
1170
|
}
|
|
1168
1171
|
}
|
|
1169
1172
|
}
|
|
1170
1173
|
}
|
|
1171
|
-
return
|
|
1174
|
+
return d;
|
|
1172
1175
|
}
|
|
1173
|
-
async function
|
|
1176
|
+
async function Je(t, { importAssets: e, includeResources: s } = {}) {
|
|
1174
1177
|
if (!$(t))
|
|
1175
1178
|
return null;
|
|
1176
1179
|
let o, a = !1;
|
|
1177
1180
|
try {
|
|
1178
|
-
x(t).isDirectory() ? o = t : /\.(tgz|gz|tar)$/.test(t) && (a = !0, o =
|
|
1179
|
-
const n = se("**/.blocklet/pages/pages.config.yml", { cwd: o, absolute: !0 }).at(0), c = n && b(L(n), "../../pages"), r = n && b(L(n), "../../components"),
|
|
1181
|
+
x(t).isDirectory() ? o = t : /\.(tgz|gz|tar)$/.test(t) && (a = !0, o = Ke(), await At({ file: t, C: o }));
|
|
1182
|
+
const n = se("**/.blocklet/pages/pages.config.yml", { cwd: o, absolute: !0 }).at(0), c = n && b(L(n), "../../pages"), r = n && b(L(n), "../../components"), l = n && b(L(n), "../../routes");
|
|
1180
1183
|
if (!n)
|
|
1181
1184
|
return null;
|
|
1182
|
-
const y = B.parse(J(n).toString()),
|
|
1183
|
-
let
|
|
1184
|
-
return (!$(
|
|
1185
|
-
}, j = (m,
|
|
1185
|
+
const y = B.parse(J(n).toString()), O = (m, u, h) => {
|
|
1186
|
+
let P = b(m, `${u}${h ? `.${h}` : ""}.yml`);
|
|
1187
|
+
return (!$(P) || !x(P).isFile()) && (P = b(m, u, `index${h ? `.${h}` : ""}.yml`), !$(P) || !x(P)) ? null : B.parse(J(P).toString());
|
|
1188
|
+
}, j = (m, u) => {
|
|
1186
1189
|
try {
|
|
1187
|
-
const h = se(`*.${
|
|
1190
|
+
const h = se(`*.${u}.yml`, { cwd: m, absolute: !0 })[0];
|
|
1188
1191
|
return h ? B.parse(J(h).toString()) : null;
|
|
1189
1192
|
} catch (h) {
|
|
1190
1193
|
f.error("parse component error", h);
|
|
1191
1194
|
}
|
|
1192
1195
|
return null;
|
|
1193
|
-
},
|
|
1194
|
-
let h = b(m, `${
|
|
1195
|
-
return (!$(h) || !x(h).isFile()) && (h = b(m,
|
|
1196
|
-
},
|
|
1196
|
+
}, S = (m, u) => {
|
|
1197
|
+
let h = b(m, `${u}.yml`);
|
|
1198
|
+
return (!$(h) || !x(h).isFile()) && (h = b(m, u, "index.yml"), !$(h) || !x(h)) ? null : B.parse(J(h).toString());
|
|
1199
|
+
}, g = T(
|
|
1197
1200
|
y.pages.map(({ slug: m }) => {
|
|
1198
|
-
const
|
|
1199
|
-
y.supportedLocales.map(({ locale:
|
|
1200
|
-
const i = c ?
|
|
1201
|
+
const u = T(
|
|
1202
|
+
y.supportedLocales.map(({ locale: w }) => {
|
|
1203
|
+
const i = c ? O(c, ne(m), w) : void 0;
|
|
1201
1204
|
if (i)
|
|
1202
|
-
return { locale:
|
|
1203
|
-
const
|
|
1204
|
-
return
|
|
1205
|
+
return { locale: w, page: i };
|
|
1206
|
+
const I = c ? O(c, m, w) : void 0;
|
|
1207
|
+
return I && { locale: w, page: I };
|
|
1205
1208
|
})
|
|
1206
|
-
), h =
|
|
1209
|
+
), h = u[0]?.page;
|
|
1207
1210
|
if (!h)
|
|
1208
1211
|
return null;
|
|
1209
|
-
const
|
|
1212
|
+
const P = h.sections.map(ft);
|
|
1210
1213
|
return {
|
|
1211
1214
|
id: h.id || De(),
|
|
1212
1215
|
createdAt: h.createdAt,
|
|
@@ -1215,30 +1218,30 @@ async function He(t, { importAssets: e, includeResources: s } = {}) {
|
|
|
1215
1218
|
isPublic: h.isPublic ?? !0,
|
|
1216
1219
|
templateConfig: h.templateConfig,
|
|
1217
1220
|
slug: m,
|
|
1218
|
-
sections: Object.fromEntries(
|
|
1219
|
-
sectionIds:
|
|
1220
|
-
locales: Object.fromEntries(
|
|
1221
|
+
sections: Object.fromEntries(P.map((w) => [w.id, w])),
|
|
1222
|
+
sectionIds: P.map((w) => w.id),
|
|
1223
|
+
locales: Object.fromEntries(u.map(({ locale: w, page: i }) => [w, i.meta])),
|
|
1221
1224
|
dataSource: h.dataSource ? Object.fromEntries(
|
|
1222
1225
|
// 获取 dataSource 中所有 section ID
|
|
1223
|
-
[...new Set(
|
|
1224
|
-
|
|
1226
|
+
[...new Set(u.flatMap(({ page: w }) => Object.keys(w.dataSource ?? {})))].map((w) => [
|
|
1227
|
+
w,
|
|
1225
1228
|
Object.fromEntries(
|
|
1226
|
-
|
|
1227
|
-
const v =
|
|
1229
|
+
u.map(({ locale: i, page: I }) => {
|
|
1230
|
+
const v = I.dataSource?.[w];
|
|
1228
1231
|
return [i, v || {}];
|
|
1229
1232
|
})
|
|
1230
1233
|
)
|
|
1231
1234
|
])
|
|
1232
1235
|
) : Object.fromEntries(
|
|
1233
1236
|
// 获取所有 section ID
|
|
1234
|
-
[...new Set(
|
|
1235
|
-
|
|
1237
|
+
[...new Set(u.flatMap(({ page: w }) => w.sections.map((i) => i.id)))].map((w) => [
|
|
1238
|
+
w,
|
|
1236
1239
|
Object.fromEntries(
|
|
1237
|
-
|
|
1238
|
-
const v =
|
|
1240
|
+
u.map(({ locale: i, page: I }) => {
|
|
1241
|
+
const v = I.dataSource?.[w];
|
|
1239
1242
|
if (v)
|
|
1240
1243
|
return [i, v];
|
|
1241
|
-
const G =
|
|
1244
|
+
const G = I.sections.find((z) => z.id === w);
|
|
1242
1245
|
return [i, G?.properties || {}];
|
|
1243
1246
|
})
|
|
1244
1247
|
)
|
|
@@ -1246,74 +1249,74 @@ async function He(t, { importAssets: e, includeResources: s } = {}) {
|
|
|
1246
1249
|
)
|
|
1247
1250
|
};
|
|
1248
1251
|
})
|
|
1249
|
-
),
|
|
1252
|
+
), p = T(
|
|
1250
1253
|
y?.routes?.map(({ path: m }) => {
|
|
1251
|
-
const
|
|
1254
|
+
const u = l ? S(l, ne(m)) : void 0;
|
|
1252
1255
|
return {
|
|
1253
|
-
...
|
|
1254
|
-
id:
|
|
1255
|
-
createdAt:
|
|
1256
|
-
updatedAt:
|
|
1256
|
+
...u,
|
|
1257
|
+
id: u?.id || De(),
|
|
1258
|
+
createdAt: u?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
1259
|
+
updatedAt: u?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
1257
1260
|
publishedAt: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
1258
|
-
path:
|
|
1259
|
-
params:
|
|
1260
|
-
handler:
|
|
1261
|
-
isPublic:
|
|
1262
|
-
enabledGenerate:
|
|
1263
|
-
displayTemplateId:
|
|
1264
|
-
dataSource:
|
|
1261
|
+
path: u?.path ?? `/${u?.id}`,
|
|
1262
|
+
params: u?.params,
|
|
1263
|
+
handler: u?.handler ?? "Pages Kit",
|
|
1264
|
+
isPublic: u?.isPublic ?? !0,
|
|
1265
|
+
enabledGenerate: u?.enabledGenerate ?? !1,
|
|
1266
|
+
displayTemplateId: u?.displayTemplateId ?? void 0,
|
|
1267
|
+
dataSource: u?.dataSource ?? {}
|
|
1265
1268
|
};
|
|
1266
1269
|
}) ?? []
|
|
1267
|
-
),
|
|
1270
|
+
), d = r ? T(y.components?.map(({ id: m }) => j(r, m)) ?? []) : [];
|
|
1268
1271
|
if (e) {
|
|
1269
|
-
const m = (...
|
|
1270
|
-
f.info(`[${a ? k(t) : k(b(t, "../../../../"))}] importAssets:`, ...
|
|
1272
|
+
const m = (...u) => {
|
|
1273
|
+
f.info(`[${a ? k(t) : k(b(t, "../../../../"))}] importAssets:`, ...u);
|
|
1271
1274
|
};
|
|
1272
1275
|
try {
|
|
1273
1276
|
m("wait image-bin api ready"), await wt({
|
|
1274
|
-
resources: [`${
|
|
1275
|
-
validateStatus: (
|
|
1277
|
+
resources: [`${gt(st)}/api/sdk/uploads`],
|
|
1278
|
+
validateStatus: (P) => P >= 200 && P <= 500
|
|
1276
1279
|
}), m("image-bin api is ready");
|
|
1277
|
-
const
|
|
1280
|
+
const u = {}, h = {};
|
|
1278
1281
|
m("start to upload assets"), await Promise.allSettled([
|
|
1279
|
-
Ne(
|
|
1280
|
-
getFilePath: (
|
|
1281
|
-
onFinish: (
|
|
1282
|
-
m(`upload ${
|
|
1282
|
+
Ne(d, u, {
|
|
1283
|
+
getFilePath: (P) => r && b(r, P),
|
|
1284
|
+
onFinish: (P) => {
|
|
1285
|
+
m(`upload ${P.length} component assets`);
|
|
1283
1286
|
}
|
|
1284
1287
|
}),
|
|
1285
|
-
Ne(
|
|
1286
|
-
getFilePath: (
|
|
1287
|
-
const i = be(
|
|
1288
|
-
return c && b(c, L(i.slug),
|
|
1288
|
+
Ne(g, h, {
|
|
1289
|
+
getFilePath: (P, w) => {
|
|
1290
|
+
const i = be(g, w.slice(0, 1));
|
|
1291
|
+
return c && b(c, L(i.slug), P);
|
|
1289
1292
|
},
|
|
1290
|
-
onFinish: (
|
|
1291
|
-
m(`upload ${
|
|
1293
|
+
onFinish: (P) => {
|
|
1294
|
+
m(`upload ${P.length} page assets`);
|
|
1292
1295
|
}
|
|
1293
1296
|
})
|
|
1294
1297
|
]), m("upload assets done"), Se.clear(), global.gc && global.gc();
|
|
1295
|
-
} catch (
|
|
1296
|
-
m("Error during asset import:",
|
|
1298
|
+
} catch (u) {
|
|
1299
|
+
m("Error during asset import:", u);
|
|
1297
1300
|
}
|
|
1298
1301
|
}
|
|
1299
|
-
const
|
|
1302
|
+
const A = {};
|
|
1300
1303
|
if (s) {
|
|
1301
|
-
const m = n && b(L(n), "../../resources/components"),
|
|
1304
|
+
const m = n && b(L(n), "../../resources/components"), u = T(
|
|
1302
1305
|
y.resources?.components?.map(({ id: h }) => j(m, h)) ?? []
|
|
1303
1306
|
);
|
|
1304
|
-
|
|
1305
|
-
|
|
1307
|
+
u.length > 0 && (A.components = Object.fromEntries(
|
|
1308
|
+
u.map((h, P) => [h.id, { index: P, component: h }])
|
|
1306
1309
|
));
|
|
1307
1310
|
}
|
|
1308
1311
|
return {
|
|
1309
1312
|
supportedLocales: y.supportedLocales,
|
|
1310
|
-
pageIds:
|
|
1311
|
-
components: Object.fromEntries(
|
|
1312
|
-
pages: Object.fromEntries(
|
|
1313
|
+
pageIds: g.map((m) => m.id),
|
|
1314
|
+
components: Object.fromEntries(d.map((m, u) => [m.id, { index: u, data: m }])),
|
|
1315
|
+
pages: Object.fromEntries(g.map((m) => [m.id, m])),
|
|
1313
1316
|
config: y.config || {},
|
|
1314
|
-
resources:
|
|
1315
|
-
routeIds:
|
|
1316
|
-
routes: Object.fromEntries(
|
|
1317
|
+
resources: A,
|
|
1318
|
+
routeIds: p.map((m) => m.id),
|
|
1319
|
+
routes: Object.fromEntries(p.map((m) => [m.id, m])),
|
|
1317
1320
|
dataSourceIds: [],
|
|
1318
1321
|
dataSources: {}
|
|
1319
1322
|
};
|
|
@@ -1328,138 +1331,138 @@ async function _e(t, e, {
|
|
|
1328
1331
|
publishMode: n = void 0
|
|
1329
1332
|
} = {}) {
|
|
1330
1333
|
try {
|
|
1331
|
-
n &&
|
|
1332
|
-
} catch (
|
|
1333
|
-
f.error("clear preload page cache error", { error:
|
|
1334
|
+
n && ot(n);
|
|
1335
|
+
} catch (S) {
|
|
1336
|
+
f.error("clear preload page cache error", { error: S });
|
|
1334
1337
|
}
|
|
1335
|
-
const { pages: c, pageIds: r, routeIds:
|
|
1338
|
+
const { pages: c, pageIds: r, routeIds: l, routes: y, supportedLocales: O } = t;
|
|
1336
1339
|
if (n === "production") {
|
|
1337
|
-
let
|
|
1338
|
-
for (const
|
|
1339
|
-
const
|
|
1340
|
-
if (
|
|
1341
|
-
const
|
|
1342
|
-
basePath:
|
|
1343
|
-
params:
|
|
1344
|
-
routeId:
|
|
1345
|
-
paramsOptions:
|
|
1340
|
+
let S = s ?? [], g = null;
|
|
1341
|
+
for (const p of l ?? []) {
|
|
1342
|
+
const d = y?.[p];
|
|
1343
|
+
if (d?.params && d?.params.length > 0 && d?.paramsOptions && d?.paramsOptions.length > 0) {
|
|
1344
|
+
const A = Ie({
|
|
1345
|
+
basePath: d.path,
|
|
1346
|
+
params: d.params,
|
|
1347
|
+
routeId: d.id,
|
|
1348
|
+
paramsOptions: d.paramsOptions,
|
|
1346
1349
|
currentIndex: 0,
|
|
1347
1350
|
currentParams: [],
|
|
1348
1351
|
currentOptionIds: [],
|
|
1349
1352
|
result: []
|
|
1350
|
-
}), m = Object.fromEntries(
|
|
1351
|
-
|
|
1352
|
-
} else s ||
|
|
1353
|
+
}), m = Object.fromEntries(A.map((u) => [`${p}-${u.paramOptionIds.join("-")}`, u]));
|
|
1354
|
+
g = { ...g || {}, ...m }, s || (S = [...S, ...A.map((u) => `${p}-${u.paramOptionIds.join("-")}`)]);
|
|
1355
|
+
} else s || S.push(p);
|
|
1353
1356
|
}
|
|
1354
|
-
f.info("routeIds to be published: ",
|
|
1355
|
-
for (const
|
|
1356
|
-
let
|
|
1357
|
-
if (
|
|
1358
|
-
const [
|
|
1359
|
-
|
|
1357
|
+
f.info("routeIds to be published: ", S);
|
|
1358
|
+
for (const p of S) {
|
|
1359
|
+
let d = p;
|
|
1360
|
+
if (d.includes("-")) {
|
|
1361
|
+
const [u] = d.split("-");
|
|
1362
|
+
d = u;
|
|
1360
1363
|
}
|
|
1361
|
-
const
|
|
1362
|
-
if (!
|
|
1363
|
-
const
|
|
1364
|
-
|
|
1364
|
+
const A = y?.[d];
|
|
1365
|
+
if (!A) {
|
|
1366
|
+
const u = e.pageIds.indexOf(d);
|
|
1367
|
+
u !== -1 && a && (e.pageIds.splice(u, 1), delete e.pages[d]);
|
|
1365
1368
|
for (const h of e.pageIds)
|
|
1366
|
-
h.includes(`${
|
|
1367
|
-
f.info("delete main route page",
|
|
1369
|
+
h.includes(`${d}-`) && (e.pageIds.splice(e.pageIds.indexOf(h), 1), delete e.pages[h]);
|
|
1370
|
+
f.info("delete main route page", d);
|
|
1368
1371
|
continue;
|
|
1369
1372
|
}
|
|
1370
|
-
if (
|
|
1371
|
-
const
|
|
1372
|
-
|
|
1373
|
+
if (p.includes("-") && !g?.[p]) {
|
|
1374
|
+
const u = e.pageIds.indexOf(p);
|
|
1375
|
+
u !== -1 && a && (e.pageIds.splice(u, 1), delete e.pages[p]), f.info("delete page", p);
|
|
1373
1376
|
continue;
|
|
1374
1377
|
}
|
|
1375
|
-
if (!
|
|
1376
|
-
f.info("no display template",
|
|
1378
|
+
if (!A.displayTemplateId) {
|
|
1379
|
+
f.info("no display template", p);
|
|
1377
1380
|
continue;
|
|
1378
1381
|
}
|
|
1379
|
-
const m = c[
|
|
1382
|
+
const m = c[A.displayTemplateId];
|
|
1380
1383
|
if (!m) {
|
|
1381
|
-
f.info("no template page",
|
|
1384
|
+
f.info("no template page", p);
|
|
1382
1385
|
continue;
|
|
1383
1386
|
}
|
|
1384
|
-
if (e.pageIds.includes(
|
|
1385
|
-
if (f.info("has need update page",
|
|
1386
|
-
e.pages[
|
|
1387
|
+
if (e.pageIds.includes(p)) {
|
|
1388
|
+
if (f.info("has need update page", p), o === "replace")
|
|
1389
|
+
e.pages[p] = fe({
|
|
1387
1390
|
page: m,
|
|
1388
|
-
route:
|
|
1391
|
+
route: A,
|
|
1389
1392
|
state: t,
|
|
1390
|
-
routeId:
|
|
1391
|
-
routePathInfo:
|
|
1392
|
-
}), f.info("replace page",
|
|
1393
|
+
routeId: p,
|
|
1394
|
+
routePathInfo: g?.[p]
|
|
1395
|
+
}), f.info("replace page", p);
|
|
1393
1396
|
else if (o === "byUpdateTime") {
|
|
1394
|
-
const
|
|
1395
|
-
(!
|
|
1397
|
+
const u = e.pages[A.id];
|
|
1398
|
+
(!u || A.updatedAt && A.updatedAt > u.updatedAt) && (e.pages[p] = fe({
|
|
1396
1399
|
page: m,
|
|
1397
|
-
route:
|
|
1400
|
+
route: A,
|
|
1398
1401
|
state: t,
|
|
1399
|
-
routeId:
|
|
1400
|
-
routePathInfo:
|
|
1401
|
-
}), f.info("replace page by update time",
|
|
1402
|
+
routeId: p,
|
|
1403
|
+
routePathInfo: g?.[p]
|
|
1404
|
+
}), f.info("replace page by update time", p));
|
|
1402
1405
|
}
|
|
1403
1406
|
} else
|
|
1404
|
-
e.pageIds.push(
|
|
1407
|
+
e.pageIds.push(p), e.pages[p] = fe({
|
|
1405
1408
|
page: m,
|
|
1406
|
-
route:
|
|
1409
|
+
route: A,
|
|
1407
1410
|
state: t,
|
|
1408
|
-
routeId:
|
|
1409
|
-
routePathInfo:
|
|
1410
|
-
}), f.info("add page",
|
|
1411
|
+
routeId: p,
|
|
1412
|
+
routePathInfo: g?.[p]
|
|
1413
|
+
}), f.info("add page", p);
|
|
1411
1414
|
}
|
|
1412
1415
|
if (a && !s)
|
|
1413
|
-
for (const
|
|
1414
|
-
|
|
1416
|
+
for (const p of e.pageIds)
|
|
1417
|
+
S?.includes(p) || (delete e.pages[p], f.info("delete page", p)), e.pageIds = [...e.pageIds].filter((d) => S?.includes(d));
|
|
1415
1418
|
} else {
|
|
1416
|
-
for (const
|
|
1417
|
-
const
|
|
1418
|
-
if (
|
|
1419
|
-
if (e.pageIds.includes(
|
|
1419
|
+
for (const S of r) {
|
|
1420
|
+
const g = c[S];
|
|
1421
|
+
if (g)
|
|
1422
|
+
if (e.pageIds.includes(g.id)) {
|
|
1420
1423
|
if (o === "replace")
|
|
1421
|
-
e.pages[
|
|
1424
|
+
e.pages[g.id] = g;
|
|
1422
1425
|
else if (o === "byUpdateTime") {
|
|
1423
|
-
const
|
|
1424
|
-
(!
|
|
1426
|
+
const p = e.pages[g.id];
|
|
1427
|
+
(!p || g.updatedAt && g.updatedAt > p.updatedAt) && (e.pages[g.id] = g);
|
|
1425
1428
|
}
|
|
1426
1429
|
} else
|
|
1427
|
-
e.pageIds.push(
|
|
1430
|
+
e.pageIds.push(g.id), e.pages[g.id] = g;
|
|
1428
1431
|
}
|
|
1429
|
-
for (const
|
|
1430
|
-
const
|
|
1431
|
-
if (
|
|
1432
|
-
if (e.routeIds.includes(
|
|
1432
|
+
for (const S of l) {
|
|
1433
|
+
const g = y[S];
|
|
1434
|
+
if (g)
|
|
1435
|
+
if (e.routeIds.includes(g.id)) {
|
|
1433
1436
|
if (o === "replace")
|
|
1434
|
-
e.routes[
|
|
1437
|
+
e.routes[g.id] = g;
|
|
1435
1438
|
else if (o === "byUpdateTime") {
|
|
1436
|
-
const
|
|
1437
|
-
(!
|
|
1439
|
+
const p = e.routes[g.id];
|
|
1440
|
+
(!p || g.updatedAt && g.updatedAt > p.updatedAt) && (e.routes[g.id] = g);
|
|
1438
1441
|
}
|
|
1439
1442
|
} else
|
|
1440
|
-
e.routeIds.push(
|
|
1443
|
+
e.routeIds.push(g.id), e.routes[g.id] = g;
|
|
1441
1444
|
}
|
|
1442
1445
|
}
|
|
1443
|
-
if (e.supportedLocales.splice(0, e.supportedLocales.length), e.supportedLocales.push(...Ee(
|
|
1444
|
-
for (const
|
|
1445
|
-
delete e.components[
|
|
1446
|
+
if (e.supportedLocales.splice(0, e.supportedLocales.length), e.supportedLocales.push(...Ee(O)), a)
|
|
1447
|
+
for (const S of Object.keys(e.components))
|
|
1448
|
+
delete e.components[S];
|
|
1446
1449
|
let j = JSON.parse(JSON.stringify(t.components));
|
|
1447
1450
|
j = Object.fromEntries(
|
|
1448
1451
|
await Promise.all(
|
|
1449
|
-
Object.entries(j).map(async ([
|
|
1450
|
-
const
|
|
1452
|
+
Object.entries(j).map(async ([S, g]) => {
|
|
1453
|
+
const p = await Ye(g?.data);
|
|
1451
1454
|
return [
|
|
1452
|
-
|
|
1455
|
+
S,
|
|
1453
1456
|
{
|
|
1454
|
-
...
|
|
1455
|
-
data:
|
|
1457
|
+
...g,
|
|
1458
|
+
data: p
|
|
1456
1459
|
}
|
|
1457
1460
|
];
|
|
1458
1461
|
})
|
|
1459
1462
|
)
|
|
1460
1463
|
), Object.assign(e.components, j), Object.assign(e.config, JSON.parse(JSON.stringify(t.config))), Ae(t.resources.components) || (e.resources.components = JSON.parse(JSON.stringify(t.resources.components || {})));
|
|
1461
1464
|
}
|
|
1462
|
-
const
|
|
1465
|
+
const Ye = at(
|
|
1463
1466
|
async (t) => {
|
|
1464
1467
|
if (!Ae(t?.properties))
|
|
1465
1468
|
return t;
|
|
@@ -1467,7 +1470,7 @@ const Je = ot(
|
|
|
1467
1470
|
const { script: e, PROPERTIES_SCHEMA: s } = t?.renderer || {};
|
|
1468
1471
|
if (s || e && e.includes("PROPERTIES_SCHEMA"))
|
|
1469
1472
|
try {
|
|
1470
|
-
const o = await
|
|
1473
|
+
const o = await nt(
|
|
1471
1474
|
e ?? "",
|
|
1472
1475
|
"PROPERTIES_SCHEMA",
|
|
1473
1476
|
t.id,
|
|
@@ -1490,28 +1493,28 @@ const Je = ot(
|
|
|
1490
1493
|
}
|
|
1491
1494
|
);
|
|
1492
1495
|
let re, Q, ie, ce;
|
|
1493
|
-
const
|
|
1496
|
+
const We = () => ht({
|
|
1494
1497
|
types: [
|
|
1495
|
-
{ did:
|
|
1498
|
+
{ did: qe, type: Ue },
|
|
1496
1499
|
{ did: Lt, type: Ue }
|
|
1497
1500
|
]
|
|
1498
1501
|
}), ss = () => {
|
|
1499
|
-
const t =
|
|
1502
|
+
const t = We(), e = {};
|
|
1500
1503
|
return t.forEach((s) => {
|
|
1501
1504
|
const o = se("**/.blocklet/pages/pages.config.yml", { cwd: s.path, absolute: !0 }).at(0), a = o && b(L(o), "../../chunks");
|
|
1502
1505
|
if (a && $(a)) {
|
|
1503
|
-
const n =
|
|
1506
|
+
const n = ut(a);
|
|
1504
1507
|
for (const c of n)
|
|
1505
1508
|
e[c] = b(a, c);
|
|
1506
1509
|
}
|
|
1507
1510
|
}), e;
|
|
1508
1511
|
};
|
|
1509
|
-
function
|
|
1512
|
+
function Xe() {
|
|
1510
1513
|
return re = (async () => {
|
|
1511
|
-
const t =
|
|
1514
|
+
const t = We();
|
|
1512
1515
|
Q = (await Promise.all(
|
|
1513
1516
|
t.map(async (s) => {
|
|
1514
|
-
const o = s.path ? await
|
|
1517
|
+
const o = s.path ? await Je(s.path, { importAssets: !1 }) : void 0;
|
|
1515
1518
|
return o ? { blockletId: s.did, state: o, blockletTitle: s.title } : void 0;
|
|
1516
1519
|
})
|
|
1517
1520
|
)).filter((s) => !!s), ie = Q.reduce(
|
|
@@ -1535,7 +1538,7 @@ function We() {
|
|
|
1535
1538
|
ce = Object.fromEntries(
|
|
1536
1539
|
await Promise.all(
|
|
1537
1540
|
Object.entries(e).map(async ([s, o]) => {
|
|
1538
|
-
const a = await
|
|
1541
|
+
const a = await Ye(o.component);
|
|
1539
1542
|
return [
|
|
1540
1543
|
s,
|
|
1541
1544
|
{
|
|
@@ -1551,7 +1554,7 @@ function We() {
|
|
|
1551
1554
|
function os(t) {
|
|
1552
1555
|
const e = xe(
|
|
1553
1556
|
async () => {
|
|
1554
|
-
await
|
|
1557
|
+
await Xe().catch((s) => {
|
|
1555
1558
|
f.error("load resource states error", { error: s });
|
|
1556
1559
|
}), await t?.({
|
|
1557
1560
|
states: Q,
|
|
@@ -1567,10 +1570,10 @@ function os(t) {
|
|
|
1567
1570
|
E.events.off(E.Events.componentAdded, e), E.events.off(E.Events.componentRemoved, e), E.events.off(E.Events.componentStarted, e), E.events.off(E.Events.componentStopped, e), E.events.off(E.Events.componentUpdated, e), E.events.off(he, e);
|
|
1568
1571
|
};
|
|
1569
1572
|
}
|
|
1570
|
-
const
|
|
1571
|
-
le[
|
|
1572
|
-
le[
|
|
1573
|
-
const s = await
|
|
1573
|
+
const Qe = Symbol.for("GLOBAL_RESOURCE_STATES_LISTENER_KEY"), Ze = Symbol.for("GLOBAL_ENV_UPDATE_LISTENER_KEY"), le = globalThis;
|
|
1574
|
+
le[Qe]?.();
|
|
1575
|
+
le[Qe] = os(async ({ pages: t, components: e }) => {
|
|
1576
|
+
const s = await C.getProjectIds();
|
|
1574
1577
|
f.info(`start update resource states projects(${s.length})`, s), await Promise.race([
|
|
1575
1578
|
new Promise((o) => {
|
|
1576
1579
|
setTimeout(() => {
|
|
@@ -1579,7 +1582,7 @@ le[Xe] = os(async ({ pages: t, components: e }) => {
|
|
|
1579
1582
|
}),
|
|
1580
1583
|
Promise.all(
|
|
1581
1584
|
s.map(async (o) => {
|
|
1582
|
-
|
|
1585
|
+
et({
|
|
1583
1586
|
projectId: o,
|
|
1584
1587
|
pages: t,
|
|
1585
1588
|
components: e
|
|
@@ -1590,31 +1593,31 @@ le[Xe] = os(async ({ pages: t, components: e }) => {
|
|
|
1590
1593
|
f.error("update resource states failed:", o);
|
|
1591
1594
|
});
|
|
1592
1595
|
});
|
|
1593
|
-
le[
|
|
1594
|
-
le[
|
|
1596
|
+
le[Ze]?.();
|
|
1597
|
+
le[Ze] = () => {
|
|
1595
1598
|
const t = () => {
|
|
1596
|
-
|
|
1599
|
+
C.pageUrlMapCache.clear(), f.info("[Cache CLEAR ALL] clear all page url map cache by env update");
|
|
1597
1600
|
};
|
|
1598
1601
|
return E.events.on(E.Events.envUpdate, t), () => {
|
|
1599
1602
|
E.events.off(E.Events.envUpdate, t);
|
|
1600
1603
|
};
|
|
1601
1604
|
};
|
|
1602
|
-
|
|
1605
|
+
C.startPeriodicCheck();
|
|
1603
1606
|
process.on("beforeExit", () => {
|
|
1604
|
-
|
|
1607
|
+
C.stopPeriodicCheck();
|
|
1605
1608
|
});
|
|
1606
1609
|
process.on("SIGINT", () => {
|
|
1607
|
-
|
|
1610
|
+
C.stopPeriodicCheck(), process.exit(0);
|
|
1608
1611
|
});
|
|
1609
1612
|
process.on("SIGTERM", () => {
|
|
1610
|
-
|
|
1613
|
+
C.stopPeriodicCheck(), process.exit(0);
|
|
1611
1614
|
});
|
|
1612
|
-
async function
|
|
1615
|
+
async function et({
|
|
1613
1616
|
projectId: t,
|
|
1614
1617
|
pages: e,
|
|
1615
1618
|
components: s
|
|
1616
1619
|
}) {
|
|
1617
|
-
const o =
|
|
1620
|
+
const o = C.sharedInstances[t];
|
|
1618
1621
|
if (!o) {
|
|
1619
1622
|
f.info(`projectId: ${t} not found in sharedInstances`);
|
|
1620
1623
|
return;
|
|
@@ -1622,8 +1625,8 @@ async function Ze({
|
|
|
1622
1625
|
if (o.syncedStore.resources.pages = e, (await U.findByPk(t))?.useAllResources)
|
|
1623
1626
|
o.syncedStore.resources.components = s;
|
|
1624
1627
|
else {
|
|
1625
|
-
const c = (await Ce.findAll({ where: { projectId: t } })).map((
|
|
1626
|
-
Object.entries(s || {}).filter(([
|
|
1628
|
+
const c = (await Ce.findAll({ where: { projectId: t } })).map((l) => l.componentId), r = Object.fromEntries(
|
|
1629
|
+
Object.entries(s || {}).filter(([l]) => c.includes(l))
|
|
1627
1630
|
);
|
|
1628
1631
|
o.syncedStore.resources.components = r;
|
|
1629
1632
|
}
|
|
@@ -1633,7 +1636,7 @@ async function Ze({
|
|
|
1633
1636
|
});
|
|
1634
1637
|
}
|
|
1635
1638
|
async function as(t) {
|
|
1636
|
-
return
|
|
1639
|
+
return et({
|
|
1637
1640
|
projectId: t,
|
|
1638
1641
|
pages: ie,
|
|
1639
1642
|
components: ce
|
|
@@ -1645,13 +1648,13 @@ async function _s() {
|
|
|
1645
1648
|
async function Fs({
|
|
1646
1649
|
ensureLoaded: t = !0
|
|
1647
1650
|
} = {}) {
|
|
1648
|
-
return t && (re ??=
|
|
1651
|
+
return t && (re ??= Xe(), await re), { states: Q, pages: ie, components: ce };
|
|
1649
1652
|
}
|
|
1650
1653
|
export {
|
|
1651
|
-
|
|
1654
|
+
qe as C,
|
|
1652
1655
|
U as P,
|
|
1653
1656
|
Ue as R,
|
|
1654
|
-
|
|
1657
|
+
C as S,
|
|
1655
1658
|
H as a,
|
|
1656
1659
|
$s as b,
|
|
1657
1660
|
Ns as c,
|
|
@@ -1659,7 +1662,7 @@ export {
|
|
|
1659
1662
|
Zt as e,
|
|
1660
1663
|
es as f,
|
|
1661
1664
|
Fs as g,
|
|
1662
|
-
|
|
1665
|
+
Je as h,
|
|
1663
1666
|
os as i,
|
|
1664
1667
|
_s as j,
|
|
1665
1668
|
_e as m,
|