@zhin.js/console 1.0.11 → 1.0.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/CHANGELOG.md +14 -0
- package/client/src/pages/dashboard-plugin-detail.tsx +33 -5
- package/dist/index.js +6 -6
- package/lib/bin.d.ts +0 -2
- package/lib/bin.js +101 -15
- package/lib/build.d.ts +4 -2
- package/lib/build.js +83 -83
- package/lib/dev.d.ts +6 -4
- package/lib/dev.js +72 -69
- package/lib/index.d.ts +7 -5
- package/lib/index.js +181 -159
- package/lib/websocket.d.ts +9 -5
- package/lib/websocket.js +71 -78
- package/package.json +20 -15
- package/lib/bin.d.ts.map +0 -1
- package/lib/bin.js.map +0 -1
- package/lib/build.d.ts.map +0 -1
- package/lib/build.js.map +0 -1
- package/lib/dev.d.ts.map +0 -1
- package/lib/dev.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/websocket.d.ts.map +0 -1
- package/lib/websocket.js.map +0 -1
package/lib/build.js
CHANGED
|
@@ -1,91 +1,91 @@
|
|
|
1
1
|
import * as vite from 'vite';
|
|
2
|
-
import { existsSync, promises
|
|
2
|
+
import { existsSync, promises } from 'fs';
|
|
3
3
|
import { join } from 'path';
|
|
4
4
|
import react from '@vitejs/plugin-react';
|
|
5
|
-
import tailwindcss from
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
resolve: {
|
|
53
|
-
alias: {
|
|
54
|
-
'react/jsx-runtime': root + '/react-jsx-runtime.js',
|
|
55
|
-
'react/jsx-dev-runtime': root + '/react-jsx-dev-runtime.js',
|
|
56
|
-
'react': root + '/react.js',
|
|
57
|
-
'react-dom': root + '/react-dom.js',
|
|
58
|
-
'radix-ui': root + '/radix-ui.js',
|
|
59
|
-
'@radix-ui/themes': root + '/radix-ui-themes.js',
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
output: {
|
|
63
|
-
format: 'iife',
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
plugins: [
|
|
68
|
-
react(),
|
|
69
|
-
tailwindcss(),
|
|
5
|
+
import tailwindcss from '@tailwindcss/vite';
|
|
6
|
+
|
|
7
|
+
// src/build.ts
|
|
8
|
+
async function build2(root, config = {}) {
|
|
9
|
+
if (!existsSync(root + "/client")) return;
|
|
10
|
+
const outDir = root + "/dist";
|
|
11
|
+
if (existsSync(outDir)) {
|
|
12
|
+
await promises.rm(outDir, { recursive: true });
|
|
13
|
+
}
|
|
14
|
+
const maybeFiles = [
|
|
15
|
+
join(root, "client", "index.tsx"),
|
|
16
|
+
join(root, "client", "index.ts"),
|
|
17
|
+
join(root, "client", "index.js"),
|
|
18
|
+
join(root, "client", "index.jsx")
|
|
19
|
+
];
|
|
20
|
+
const entry = maybeFiles.find((file) => existsSync(file));
|
|
21
|
+
if (!entry) {
|
|
22
|
+
throw new Error("No entry file found");
|
|
23
|
+
}
|
|
24
|
+
await promises.mkdir(root + "/dist", { recursive: true });
|
|
25
|
+
const results = await vite.build(vite.mergeConfig({
|
|
26
|
+
root,
|
|
27
|
+
build: {
|
|
28
|
+
write: false,
|
|
29
|
+
outDir: "dist",
|
|
30
|
+
assetsDir: "",
|
|
31
|
+
minify: true,
|
|
32
|
+
emptyOutDir: true,
|
|
33
|
+
commonjsOptions: {
|
|
34
|
+
strictRequires: true
|
|
35
|
+
},
|
|
36
|
+
lib: {
|
|
37
|
+
entry,
|
|
38
|
+
fileName: "index",
|
|
39
|
+
formats: ["es"]
|
|
40
|
+
},
|
|
41
|
+
rollupOptions: {
|
|
42
|
+
makeAbsoluteExternalsRelative: true,
|
|
43
|
+
external: [
|
|
44
|
+
"react",
|
|
45
|
+
"react-dom",
|
|
46
|
+
"react/jsx-runtime",
|
|
47
|
+
"react/jsx-dev-runtime",
|
|
48
|
+
"radix-ui",
|
|
49
|
+
"@radix-ui/themes",
|
|
50
|
+
"lucide-react",
|
|
51
|
+
"@zhin.js/client"
|
|
70
52
|
],
|
|
71
|
-
|
|
72
|
-
|
|
53
|
+
resolve: {
|
|
54
|
+
alias: {
|
|
55
|
+
"react/jsx-runtime": root + "/react-jsx-runtime.js",
|
|
56
|
+
"react/jsx-dev-runtime": root + "/react-jsx-dev-runtime.js",
|
|
57
|
+
"react": root + "/react.js",
|
|
58
|
+
"react-dom": root + "/react-dom.js",
|
|
59
|
+
"radix-ui": root + "/radix-ui.js",
|
|
60
|
+
"@radix-ui/themes": root + "/radix-ui-themes.js"
|
|
61
|
+
}
|
|
73
62
|
},
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (item.fileName === 'index.mjs')
|
|
77
|
-
item.fileName = 'index.js';
|
|
78
|
-
const dest = root + '/dist/' + item.fileName;
|
|
79
|
-
if (item.type === 'asset') {
|
|
80
|
-
await fs.writeFile(dest, item.source);
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
const result = await vite.transformWithEsbuild(item.code, dest, {
|
|
84
|
-
minifyWhitespace: true,
|
|
85
|
-
charset: 'utf8',
|
|
86
|
-
});
|
|
87
|
-
await fs.writeFile(dest, result.code);
|
|
63
|
+
output: {
|
|
64
|
+
format: "iife"
|
|
88
65
|
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
plugins: [
|
|
69
|
+
react(),
|
|
70
|
+
tailwindcss()
|
|
71
|
+
],
|
|
72
|
+
define: {
|
|
73
|
+
"process.env.NODE_ENV": '"production"'
|
|
74
|
+
}
|
|
75
|
+
}, config));
|
|
76
|
+
for (const item of results[0].output) {
|
|
77
|
+
if (item.fileName === "index.mjs") item.fileName = "index.js";
|
|
78
|
+
const dest = root + "/dist/" + item.fileName;
|
|
79
|
+
if (item.type === "asset") {
|
|
80
|
+
await promises.writeFile(dest, item.source);
|
|
81
|
+
} else {
|
|
82
|
+
const result = await vite.transformWithEsbuild(item.code, dest, {
|
|
83
|
+
minifyWhitespace: true,
|
|
84
|
+
charset: "utf8"
|
|
85
|
+
});
|
|
86
|
+
await promises.writeFile(dest, result.code);
|
|
89
87
|
}
|
|
88
|
+
}
|
|
90
89
|
}
|
|
91
|
-
|
|
90
|
+
|
|
91
|
+
export { build2 as build };
|
package/lib/dev.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { ViteDevServer } from
|
|
2
|
-
|
|
1
|
+
import { ViteDevServer } from 'vite';
|
|
2
|
+
|
|
3
|
+
interface DevServerOptions {
|
|
3
4
|
/** 客户端代码根目录 */
|
|
4
5
|
root: string;
|
|
5
6
|
/** 基础路径,默认 /vite/ */
|
|
@@ -12,5 +13,6 @@ export interface DevServerOptions {
|
|
|
12
13
|
* @param options 开发服务器选项
|
|
13
14
|
* @returns Vite 开发服务器实例
|
|
14
15
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
declare function createViteDevServer(options: DevServerOptions): Promise<ViteDevServer>;
|
|
17
|
+
|
|
18
|
+
export { type DevServerOptions, createViteDevServer };
|
package/lib/dev.js
CHANGED
|
@@ -1,71 +1,74 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import react from '@vitejs/plugin-react';
|
|
2
|
+
import tailwindcss from '@tailwindcss/vite';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
|
|
6
|
+
// src/dev.ts
|
|
7
|
+
async function createViteDevServer(options) {
|
|
8
|
+
const { root, base = "/vite/", enableTailwind = true } = options;
|
|
9
|
+
const { createServer, searchForWorkspaceRoot } = await import('vite');
|
|
10
|
+
const plugins = [react()];
|
|
11
|
+
if (enableTailwind) {
|
|
12
|
+
plugins.push(tailwindcss());
|
|
13
|
+
}
|
|
14
|
+
const clientPath = path.resolve(process.cwd(), "node_modules/@zhin.js/client/client");
|
|
15
|
+
if (!fs.existsSync(clientPath)) {
|
|
16
|
+
throw new Error("@zhin.js/client not found");
|
|
17
|
+
}
|
|
18
|
+
return await await createServer({
|
|
19
|
+
root,
|
|
20
|
+
base,
|
|
21
|
+
plugins: [react(), tailwindcss()],
|
|
22
|
+
server: {
|
|
23
|
+
middlewareMode: true,
|
|
24
|
+
allowedHosts: true,
|
|
25
|
+
fs: {
|
|
26
|
+
strict: false,
|
|
27
|
+
// 添加文件访问过滤,避免访问特殊文件
|
|
28
|
+
allow: [
|
|
29
|
+
// 允许访问的目录
|
|
30
|
+
root,
|
|
31
|
+
searchForWorkspaceRoot(root),
|
|
32
|
+
path.resolve(process.cwd(), "node_modules"),
|
|
33
|
+
path.resolve(process.cwd(), "client"),
|
|
34
|
+
path.resolve(process.cwd(), "src")
|
|
35
|
+
],
|
|
36
|
+
// 拒绝访问某些文件模式
|
|
37
|
+
deny: [
|
|
38
|
+
"**/.git/**",
|
|
39
|
+
"**/node_modules/.cache/**",
|
|
40
|
+
"**/*.socket",
|
|
41
|
+
"**/*.pipe",
|
|
42
|
+
"**/Dockerfile*",
|
|
43
|
+
"**/.env*"
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
resolve: {
|
|
48
|
+
dedupe: [
|
|
49
|
+
"react",
|
|
50
|
+
"react-dom",
|
|
51
|
+
"clsx",
|
|
52
|
+
"tailwind-merge",
|
|
53
|
+
"@reduxjs/toolkit",
|
|
54
|
+
"react-router",
|
|
55
|
+
"react-redux",
|
|
56
|
+
"redux-persist"
|
|
57
|
+
],
|
|
58
|
+
alias: {
|
|
59
|
+
"@zhin.js/client": path.resolve(process.cwd(), "node_modules/@zhin.js/client/client"),
|
|
60
|
+
"@": path.resolve(root, "../client/src")
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
optimizeDeps: {
|
|
64
|
+
include: ["react", "react-dom"]
|
|
65
|
+
},
|
|
66
|
+
build: {
|
|
67
|
+
rollupOptions: {
|
|
68
|
+
input: root + "/index.html"
|
|
69
|
+
}
|
|
15
70
|
}
|
|
16
|
-
|
|
17
|
-
root,
|
|
18
|
-
base,
|
|
19
|
-
plugins: [react(), tailwindcss()],
|
|
20
|
-
server: {
|
|
21
|
-
middlewareMode: true,
|
|
22
|
-
allowedHosts: true,
|
|
23
|
-
fs: {
|
|
24
|
-
strict: false,
|
|
25
|
-
// 添加文件访问过滤,避免访问特殊文件
|
|
26
|
-
allow: [
|
|
27
|
-
// 允许访问的目录
|
|
28
|
-
root,
|
|
29
|
-
searchForWorkspaceRoot(root),
|
|
30
|
-
path.resolve(process.cwd(), 'node_modules'),
|
|
31
|
-
path.resolve(process.cwd(), 'client'),
|
|
32
|
-
path.resolve(process.cwd(), 'src'),
|
|
33
|
-
],
|
|
34
|
-
// 拒绝访问某些文件模式
|
|
35
|
-
deny: [
|
|
36
|
-
'**/.git/**',
|
|
37
|
-
'**/node_modules/.cache/**',
|
|
38
|
-
'**/*.socket',
|
|
39
|
-
'**/*.pipe',
|
|
40
|
-
'**/Dockerfile*',
|
|
41
|
-
'**/.env*',
|
|
42
|
-
],
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
resolve: {
|
|
46
|
-
dedupe: [
|
|
47
|
-
"react",
|
|
48
|
-
"react-dom",
|
|
49
|
-
"clsx",
|
|
50
|
-
"tailwind-merge",
|
|
51
|
-
"@reduxjs/toolkit",
|
|
52
|
-
"react-router",
|
|
53
|
-
"react-redux",
|
|
54
|
-
"redux-persist",
|
|
55
|
-
],
|
|
56
|
-
alias: {
|
|
57
|
-
"@zhin.js/client": path.resolve(root, "../../../packages/client/client"),
|
|
58
|
-
"@": path.resolve(root, "../client/src"),
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
optimizeDeps: {
|
|
62
|
-
include: ["react", "react-dom"],
|
|
63
|
-
},
|
|
64
|
-
build: {
|
|
65
|
-
rollupOptions: {
|
|
66
|
-
input: root + "/index.html",
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
});
|
|
71
|
+
});
|
|
70
72
|
}
|
|
71
|
-
|
|
73
|
+
|
|
74
|
+
export { createViteDevServer };
|
package/lib/index.d.ts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import { WebSocketServer } from
|
|
2
|
-
import { ViteDevServer } from
|
|
1
|
+
import { WebSocketServer } from 'ws';
|
|
2
|
+
import { ViteDevServer } from 'vite';
|
|
3
|
+
|
|
3
4
|
declare module "@zhin.js/types" {
|
|
4
5
|
interface GlobalContext {
|
|
5
6
|
web: WebServer;
|
|
6
7
|
}
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
+
type WebEntry = string | {
|
|
9
10
|
production: string;
|
|
10
11
|
development: string;
|
|
11
12
|
};
|
|
12
|
-
|
|
13
|
+
type WebServer = {
|
|
13
14
|
vite?: ViteDevServer;
|
|
14
15
|
addEntry(entry: WebEntry): () => void;
|
|
15
16
|
entries: Record<string, string>;
|
|
16
17
|
ws: WebSocketServer;
|
|
17
18
|
};
|
|
18
|
-
|
|
19
|
+
|
|
20
|
+
export type { WebEntry, WebServer };
|