@next-core/brick-container 3.5.11 → 3.5.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core.0bf2de32.js +2 -0
- package/dist/core.0bf2de32.js.map +1 -0
- package/dist/index.html +1 -1
- package/dist/{main.13dc33dc.js → main.244d6c9b.js} +2 -2
- package/dist/{main.13dc33dc.js.map → main.244d6c9b.js.map} +1 -1
- package/dist/{polyfill.c52438f4.js → polyfill.83f591d8.js} +1 -1
- package/package.json +6 -5
- package/serve/env.js +28 -6
- package/serve/getProxy.js +22 -0
- package/serve/index.js +26 -0
- package/serve/utils/getStoryboards.js +1 -1
- package/serve/utils/injectIndexHtml.js +14 -0
- package/dist/core.73972232.js +0 -2
- package/dist/core.73972232.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next-core/brick-container",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.13",
|
|
4
4
|
"description": "Brick Container Server",
|
|
5
5
|
"homepage": "https://github.com/easyops-cn/next-core/tree/v3/packages/brick-container",
|
|
6
6
|
"license": "GPL-3.0",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"@next-core/serve-helpers": "^1.2.0",
|
|
31
31
|
"body-parser": "^1.20.1",
|
|
32
32
|
"chalk": "^4.1.2",
|
|
33
|
+
"chokidar": "^3.5.3",
|
|
33
34
|
"compression": "^1.7.4",
|
|
34
35
|
"express": "^4.18.2",
|
|
35
36
|
"glob": "^8.1.0",
|
|
@@ -44,11 +45,11 @@
|
|
|
44
45
|
"@next-api-sdk/api-gateway-sdk": "^1.1.0",
|
|
45
46
|
"@next-api-sdk/micro-app-standalone-sdk": "^1.1.0",
|
|
46
47
|
"@next-core/build-next-bricks": "^1.13.4",
|
|
47
|
-
"@next-core/easyops-runtime": "^0.6.
|
|
48
|
+
"@next-core/easyops-runtime": "^0.6.16",
|
|
48
49
|
"@next-core/http": "^1.0.8",
|
|
49
50
|
"@next-core/i18n": "^1.0.24",
|
|
50
|
-
"@next-core/loader": "^1.
|
|
51
|
-
"@next-core/runtime": "^1.20.
|
|
51
|
+
"@next-core/loader": "^1.4.0",
|
|
52
|
+
"@next-core/runtime": "^1.20.2",
|
|
52
53
|
"@next-core/test-next": "^1.0.8",
|
|
53
54
|
"@next-core/theme": "^1.1.1",
|
|
54
55
|
"@next-core/types": "^1.6.0",
|
|
@@ -63,5 +64,5 @@
|
|
|
63
64
|
"@next-core/runtime": "*",
|
|
64
65
|
"@next-core/utils": "*"
|
|
65
66
|
},
|
|
66
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "0bd3d1edd7acdab6794f98366ef70e3d479930d8"
|
|
67
68
|
}
|
package/serve/env.js
CHANGED
|
@@ -19,6 +19,8 @@ const cli = meow(
|
|
|
19
19
|
--local-micro-apps Specify local micro apps to be used
|
|
20
20
|
--local-container Use local brick-container instead of remote in remote mode
|
|
21
21
|
--port Set local server listening port, defaults to "8081"
|
|
22
|
+
--ws-port Set local WebSocket server listening port, defaults to "8090"
|
|
23
|
+
--live-reload Enable live reload (currently only for local micro-apps)
|
|
22
24
|
--size-check Enable size-check mode
|
|
23
25
|
--cookie-same-site-none Append "Same-Site: none" for cookies
|
|
24
26
|
--verbose Print verbose logs
|
|
@@ -51,10 +53,17 @@ const cli = meow(
|
|
|
51
53
|
type: "boolean",
|
|
52
54
|
default: true,
|
|
53
55
|
},
|
|
56
|
+
liveReload: {
|
|
57
|
+
type: "boolean",
|
|
58
|
+
},
|
|
54
59
|
port: {
|
|
55
60
|
type: "string",
|
|
56
61
|
default: "8081",
|
|
57
62
|
},
|
|
63
|
+
wsPort: {
|
|
64
|
+
type: "string",
|
|
65
|
+
default: "8090",
|
|
66
|
+
},
|
|
58
67
|
sizeCheck: {
|
|
59
68
|
type: "boolean",
|
|
60
69
|
},
|
|
@@ -86,14 +95,19 @@ export async function getEnv(rootDir, runtimeFlags) {
|
|
|
86
95
|
...runtimeFlags,
|
|
87
96
|
};
|
|
88
97
|
|
|
98
|
+
let localSettings;
|
|
99
|
+
|
|
89
100
|
let brickFolders = ["node_modules/@next-bricks", "node_modules/@bricks"];
|
|
90
101
|
const devConfigMjs = path.join(rootDir, "dev.config.mjs");
|
|
91
102
|
let configuredBrickFolders = false;
|
|
92
103
|
if (existsSync(devConfigMjs)) {
|
|
93
104
|
const devConfig = (await import(devConfigMjs)).default;
|
|
94
|
-
if (devConfig
|
|
95
|
-
|
|
96
|
-
|
|
105
|
+
if (devConfig) {
|
|
106
|
+
if (Array.isArray(devConfig.brickFolders)) {
|
|
107
|
+
brickFolders = devConfig.brickFolders;
|
|
108
|
+
configuredBrickFolders = true;
|
|
109
|
+
}
|
|
110
|
+
localSettings = devConfig.settings;
|
|
97
111
|
}
|
|
98
112
|
}
|
|
99
113
|
|
|
@@ -122,7 +136,10 @@ export async function getEnv(rootDir, runtimeFlags) {
|
|
|
122
136
|
)
|
|
123
137
|
).flat(),
|
|
124
138
|
cookieSameSiteNone: flags.cookieSameSiteNone,
|
|
139
|
+
liveReload: flags.liveReload,
|
|
140
|
+
localSettings,
|
|
125
141
|
port: Number(flags.port),
|
|
142
|
+
wsPort: Number(flags.wsPort),
|
|
126
143
|
server: getServerPath(flags.server),
|
|
127
144
|
sizeCheck: flags.sizeCheck,
|
|
128
145
|
verbose: flags.verbose,
|
|
@@ -137,20 +154,25 @@ export async function getEnv(rootDir, runtimeFlags) {
|
|
|
137
154
|
}
|
|
138
155
|
|
|
139
156
|
if (configuredBrickFolders) {
|
|
140
|
-
console.log();
|
|
141
157
|
console.log("local brick folders:", env.localBrickFolders);
|
|
142
158
|
}
|
|
143
159
|
|
|
160
|
+
if (localSettings) {
|
|
161
|
+
console.log("local settings: enabled");
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (env.liveReload) {
|
|
165
|
+
console.log("live-reload: enabled");
|
|
166
|
+
}
|
|
167
|
+
|
|
144
168
|
const validLocalBricks = await getLocalBrickPackageNames(
|
|
145
169
|
env.localBrickFolders,
|
|
146
170
|
env.localBricks
|
|
147
171
|
);
|
|
148
172
|
|
|
149
|
-
console.log();
|
|
150
173
|
console.log("local brick packages:", validLocalBricks);
|
|
151
174
|
|
|
152
175
|
if (env.localMicroApps.length > 0) {
|
|
153
|
-
console.log();
|
|
154
176
|
console.log("local micro-apps:", env.localMicroApps);
|
|
155
177
|
}
|
|
156
178
|
|
package/serve/getProxy.js
CHANGED
|
@@ -88,6 +88,28 @@ export default function getProxy(env, getRawIndexHtml) {
|
|
|
88
88
|
return JSON.stringify(result);
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
if (
|
|
92
|
+
env.localSettings &&
|
|
93
|
+
req.path === "/next/api/v1/runtime_standalone"
|
|
94
|
+
) {
|
|
95
|
+
const content = responseBuffer.toString("utf-8");
|
|
96
|
+
const result = JSON.parse(content);
|
|
97
|
+
const { data } = result;
|
|
98
|
+
|
|
99
|
+
const { featureFlags, homepage, brand, misc } = env.localSettings;
|
|
100
|
+
data.featureFlags ??= {};
|
|
101
|
+
data.brand ??= {};
|
|
102
|
+
data.misc ??= {};
|
|
103
|
+
Object.assign(data.settings.featureFlags, featureFlags);
|
|
104
|
+
Object.assign(data.settings.brand, brand);
|
|
105
|
+
Object.assign(data.settings.misc, misc);
|
|
106
|
+
if (homepage) {
|
|
107
|
+
data.settings.homepage = homepage;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return JSON.stringify(result);
|
|
111
|
+
}
|
|
112
|
+
|
|
91
113
|
const appId = getAppIdFromBootstrapPath(req.path);
|
|
92
114
|
if (appId) {
|
|
93
115
|
if (localMicroApps.includes(appId)) {
|
package/serve/index.js
CHANGED
|
@@ -4,6 +4,9 @@ import { readFile } from "node:fs/promises";
|
|
|
4
4
|
import express from "express";
|
|
5
5
|
import compression from "compression";
|
|
6
6
|
import { createProxyMiddleware } from "http-proxy-middleware";
|
|
7
|
+
import WebSocket, { WebSocketServer } from "ws";
|
|
8
|
+
import { watch } from "chokidar";
|
|
9
|
+
import _ from "lodash";
|
|
7
10
|
import { getEnv } from "./env.js";
|
|
8
11
|
import { injectIndexHtml } from "./utils/injectIndexHtml.js";
|
|
9
12
|
import { getMatchedStoryboard } from "./utils/getStoryboards.js";
|
|
@@ -85,6 +88,29 @@ app.listen(port);
|
|
|
85
88
|
|
|
86
89
|
console.log(`open http://localhost:${port}${baseHref}`);
|
|
87
90
|
|
|
91
|
+
if (env.liveReload) {
|
|
92
|
+
const wss = new WebSocketServer({ port: env.wsPort });
|
|
93
|
+
const watcher = watch(
|
|
94
|
+
env.localMicroApps.map((appId) =>
|
|
95
|
+
path.join(env.rootDir, "mock-micro-apps", appId, "storyboard.yaml")
|
|
96
|
+
)
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
const throttledOnChange = _.throttle(
|
|
100
|
+
() => {
|
|
101
|
+
wss.clients.forEach((client) => {
|
|
102
|
+
if (client.readyState === WebSocket.OPEN) {
|
|
103
|
+
client.send("content change");
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
100,
|
|
108
|
+
{ trailing: false }
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
watcher.on("change", throttledOnChange);
|
|
112
|
+
}
|
|
113
|
+
|
|
88
114
|
/**
|
|
89
115
|
* @param {import("express").Request} req
|
|
90
116
|
* @param {import("express").Response} res
|
|
@@ -50,7 +50,7 @@ export async function getMatchedStoryboard(env, pathname) {
|
|
|
50
50
|
"desc"
|
|
51
51
|
);
|
|
52
52
|
for (const storyboard of sortedStoryboards) {
|
|
53
|
-
const homepage = storyboard.app
|
|
53
|
+
const homepage = storyboard.app?.homepage;
|
|
54
54
|
if (typeof homepage === "string" && homepage[0] === "/") {
|
|
55
55
|
if (
|
|
56
56
|
homepage === "/"
|
|
@@ -44,5 +44,19 @@ export function injectIndexHtml(env, content, standaloneConfig) {
|
|
|
44
44
|
);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
if (env.liveReload) {
|
|
48
|
+
content = content.replace(
|
|
49
|
+
"</body>",
|
|
50
|
+
`<script>
|
|
51
|
+
const socket = new WebSocket("ws://localhost:${env.wsPort}");
|
|
52
|
+
socket.onmessage = function(event) {
|
|
53
|
+
if (event.data === "content change") {
|
|
54
|
+
location.reload();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
</script></body>`
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
47
61
|
return content;
|
|
48
62
|
}
|