@zhin.js/console 1.0.6 → 1.0.8

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.
Files changed (52) hide show
  1. package/README.md +86 -21
  2. package/app/bin.ts +52 -0
  3. package/app/build.ts +211 -0
  4. package/app/dev.ts +83 -0
  5. package/app/index.ts +193 -0
  6. package/app/websocket.ts +109 -0
  7. package/client/index.html +13 -0
  8. package/client/postcss.config.js +5 -0
  9. package/client/public/vendor/react-dom.production.min.js +1 -0
  10. package/client/public/vendor/react.production.min.js +1 -0
  11. package/client/src/components/PluginConfigForm/BasicFieldRenderers.tsx +253 -0
  12. package/client/src/components/PluginConfigForm/CollectionFieldRenderers.tsx +261 -0
  13. package/client/src/components/PluginConfigForm/CompositeFieldRenderers.tsx +105 -0
  14. package/client/src/components/PluginConfigForm/FieldRenderer.tsx +110 -0
  15. package/client/src/components/PluginConfigForm/NestedFieldRenderer.tsx +95 -0
  16. package/client/src/components/PluginConfigForm/index.tsx +237 -0
  17. package/client/src/components/PluginConfigForm/types.ts +46 -0
  18. package/client/src/components/ThemeToggle.tsx +21 -0
  19. package/client/src/hooks/useTheme.ts +17 -0
  20. package/client/src/layouts/dashboard.tsx +259 -0
  21. package/client/src/main.tsx +121 -0
  22. package/client/src/pages/dashboard-bots.tsx +198 -0
  23. package/client/src/pages/dashboard-home.tsx +301 -0
  24. package/client/src/pages/dashboard-logs.tsx +298 -0
  25. package/client/src/pages/dashboard-plugin-detail.tsx +360 -0
  26. package/client/src/pages/dashboard-plugins.tsx +166 -0
  27. package/client/src/style.css +1105 -0
  28. package/client/src/theme/index.ts +92 -0
  29. package/client/tailwind.config.js +85 -0
  30. package/client/tsconfig.json +17 -0
  31. package/lib/bin.d.ts +3 -0
  32. package/lib/bin.d.ts.map +1 -0
  33. package/lib/bin.js +45 -0
  34. package/lib/bin.js.map +1 -0
  35. package/lib/build.d.ts +33 -0
  36. package/lib/build.d.ts.map +1 -0
  37. package/lib/build.js +168 -0
  38. package/lib/build.js.map +1 -0
  39. package/lib/dev.d.ts +16 -0
  40. package/lib/dev.d.ts.map +1 -0
  41. package/lib/dev.js +70 -0
  42. package/lib/dev.js.map +1 -0
  43. package/lib/index.d.ts +4 -4
  44. package/lib/index.d.ts.map +1 -1
  45. package/lib/index.js +107 -269
  46. package/lib/index.js.map +1 -1
  47. package/lib/websocket.d.ts +14 -0
  48. package/lib/websocket.d.ts.map +1 -0
  49. package/lib/websocket.js +85 -0
  50. package/lib/websocket.js.map +1 -0
  51. package/package.json +28 -10
  52. package/src/index.ts +0 -370
@@ -0,0 +1,92 @@
1
+ // Theme configuration
2
+ export const themes = {
3
+ light: {
4
+ background: '0 0% 100%',
5
+ foreground: '222.2 84% 4.9%',
6
+ card: '0 0% 100%',
7
+ 'card-foreground': '222.2 84% 4.9%',
8
+ popover: '0 0% 100%',
9
+ 'popover-foreground': '222.2 84% 4.9%',
10
+ primary: '221.2 83.2% 53.3%',
11
+ 'primary-foreground': '210 40% 98%',
12
+ secondary: '210 40% 96.1%',
13
+ 'secondary-foreground': '222.2 47.4% 11.2%',
14
+ muted: '210 40% 96.1%',
15
+ 'muted-foreground': '215.4 16.3% 46.9%',
16
+ accent: '210 40% 96.1%',
17
+ 'accent-foreground': '222.2 47.4% 11.2%',
18
+ destructive: '0 84.2% 60.2%',
19
+ 'destructive-foreground': '210 40% 98%',
20
+ border: '214.3 31.8% 91.4%',
21
+ input: '214.3 31.8% 91.4%',
22
+ ring: '221.2 83.2% 53.3%',
23
+ radius: '0.5rem',
24
+ },
25
+ dark: {
26
+ background: '222.2 84% 4.9%',
27
+ foreground: '210 40% 98%',
28
+ card: '222.2 84% 4.9%',
29
+ 'card-foreground': '210 40% 98%',
30
+ popover: '222.2 84% 4.9%',
31
+ 'popover-foreground': '210 40% 98%',
32
+ primary: '217.2 91.2% 59.8%',
33
+ 'primary-foreground': '222.2 47.4% 11.2%',
34
+ secondary: '217.2 32.6% 17.5%',
35
+ 'secondary-foreground': '210 40% 98%',
36
+ muted: '217.2 32.6% 17.5%',
37
+ 'muted-foreground': '215 20.2% 65.1%',
38
+ accent: '217.2 32.6% 17.5%',
39
+ 'accent-foreground': '210 40% 98%',
40
+ destructive: '0 62.8% 30.6%',
41
+ 'destructive-foreground': '210 40% 98%',
42
+ border: '217.2 32.6% 17.5%',
43
+ input: '217.2 32.6% 17.5%',
44
+ ring: '224.3 76.3% 48%',
45
+ radius: '0.5rem',
46
+ },
47
+ } as const
48
+
49
+ export type Theme = keyof typeof themes
50
+ export type ThemeColors = typeof themes.light
51
+
52
+ // Apply theme to document
53
+ export function applyTheme(theme: Theme) {
54
+ const root = document.documentElement
55
+ const colors = themes[theme]
56
+
57
+ // Remove old theme class
58
+ root.classList.remove('light', 'dark')
59
+ // Add new theme class
60
+ root.classList.add(theme)
61
+
62
+ // Apply CSS variables
63
+ Object.entries(colors).forEach(([key, value]) => {
64
+ root.style.setProperty(`--${key}`, value)
65
+ })
66
+
67
+ // Save to localStorage
68
+ localStorage.setItem('theme', theme)
69
+ }
70
+
71
+ // Get current theme from localStorage or system preference
72
+ export function getInitialTheme(): Theme {
73
+ const stored = localStorage.getItem('theme') as Theme | null
74
+ if (stored && (stored === 'light' || stored === 'dark')) {
75
+ return stored
76
+ }
77
+
78
+ // Check system preference
79
+ if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
80
+ return 'dark'
81
+ }
82
+
83
+ return 'light'
84
+ }
85
+
86
+ // Initialize theme on app load
87
+ export function initializeTheme() {
88
+ const theme = getInitialTheme()
89
+ applyTheme(theme)
90
+ return theme
91
+ }
92
+
@@ -0,0 +1,85 @@
1
+ /** @type {import('tailwindcss').Config} */
2
+ import path from 'path';
3
+ const cwd = process.cwd();
4
+
5
+ // 安全的路径构建函数,避免扫描特殊文件
6
+ const safePath = (...parts) => {
7
+ try {
8
+ return path.resolve(...parts);
9
+ } catch (error) {
10
+ console.warn(`Tailwind 路径构建失败: ${parts.join('/')}`, error.message);
11
+ return '';
12
+ }
13
+ };
14
+
15
+ export default {
16
+ content: [
17
+ "./index.html",
18
+ './src/**/*.{js,ts,jsx,tsx,mdx}',
19
+ './node_modules/@radix-ui/**/*.{js,ts,jsx,tsx}',
20
+ `${cwd}/node_modules/@zhin.js/*/client/**/*.{js,ts,jsx,tsx}`,
21
+ `${cwd}/node_modules/@zhin.js/*/dist/**/*.{js,ts,jsx,tsx}`,
22
+ `${cwd}/plugins/*/client/**/*.{js,ts,jsx,tsx}`,
23
+ `${cwd}/client/**/*.{js,ts,jsx,tsx}`,
24
+ ].filter(Boolean), // 过滤掉空字符串
25
+ theme: {
26
+ extend: {
27
+ colors: {
28
+ border: 'hsl(var(--border))',
29
+ input: 'hsl(var(--input))',
30
+ ring: 'hsl(var(--ring))',
31
+ background: 'hsl(var(--background))',
32
+ foreground: 'hsl(var(--foreground))',
33
+ primary: {
34
+ DEFAULT: 'hsl(var(--primary))',
35
+ foreground: 'hsl(var(--primary-foreground))',
36
+ },
37
+ secondary: {
38
+ DEFAULT: 'hsl(var(--secondary))',
39
+ foreground: 'hsl(var(--secondary-foreground))',
40
+ },
41
+ destructive: {
42
+ DEFAULT: 'hsl(var(--destructive))',
43
+ foreground: 'hsl(var(--destructive-foreground))',
44
+ },
45
+ muted: {
46
+ DEFAULT: 'hsl(var(--muted))',
47
+ foreground: 'hsl(var(--muted-foreground))',
48
+ },
49
+ accent: {
50
+ DEFAULT: 'hsl(var(--accent))',
51
+ foreground: 'hsl(var(--accent-foreground))',
52
+ },
53
+ popover: {
54
+ DEFAULT: 'hsl(var(--popover))',
55
+ foreground: 'hsl(var(--popover-foreground))',
56
+ },
57
+ card: {
58
+ DEFAULT: 'hsl(var(--card))',
59
+ foreground: 'hsl(var(--card-foreground))',
60
+ },
61
+ },
62
+ borderRadius: {
63
+ lg: 'var(--radius)',
64
+ md: 'calc(var(--radius) - 2px)',
65
+ sm: 'calc(var(--radius) - 4px)',
66
+ },
67
+ keyframes: {
68
+ "accordion-down": {
69
+ from: { height: "0" },
70
+ to: { height: "var(--radix-accordion-content-height)" },
71
+ },
72
+ "accordion-up": {
73
+ from: { height: "var(--radix-accordion-content-height)" },
74
+ to: { height: "0" },
75
+ },
76
+ },
77
+ animation: {
78
+ "accordion-down": "accordion-down 0.2s ease-out",
79
+ "accordion-up": "accordion-up 0.2s ease-out",
80
+ },
81
+ },
82
+ },
83
+ darkMode: "class",
84
+ plugins: [],
85
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": ".",
4
+ "target": "ES2020",
5
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
6
+ "moduleResolution": "bundler",
7
+ "module": "ESNext",
8
+ "jsx": "react-jsx",
9
+ "paths": {
10
+ "@/*": ["src/*"],
11
+ "lucide-react": ["../node_modules/lucide-react"],
12
+ "react": ["../node_modules/@types/react"],
13
+ "react-dom": ["../node_modules/@types/react-dom"]
14
+ }
15
+ }
16
+ }
17
+
package/lib/bin.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=bin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../app/bin.ts"],"names":[],"mappings":""}
package/lib/bin.js ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env node
2
+ import { buildCurrentPlugin, buildConsoleClient } from "./build.js";
3
+ import path from "path";
4
+ import { fileURLToPath } from "url";
5
+ const args = process.argv.slice(2);
6
+ const command = args[0];
7
+ async function main() {
8
+ try {
9
+ switch (command) {
10
+ case "build":
11
+ // 构建当前目录的插件客户端代码
12
+ console.log("🔨 Building plugin client...");
13
+ await buildCurrentPlugin();
14
+ break;
15
+ case "build:console":
16
+ // 构建 console 插件的客户端代码
17
+ console.log("🔨 Building console client...");
18
+ const consoleRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
19
+ await buildConsoleClient({ consoleRoot });
20
+ break;
21
+ default:
22
+ console.log(`
23
+ Zhin.js Client Builder
24
+
25
+ Usage:
26
+ zhin-client build Build current plugin's client code
27
+ zhin-client build:console Build console plugin's client code (SPA mode)
28
+
29
+ Examples:
30
+ # Build a plugin (single file mode)
31
+ cd my-plugin && zhin-client build
32
+
33
+ # Build console (SPA mode)
34
+ zhin-client build:console
35
+ `);
36
+ process.exit(1);
37
+ }
38
+ }
39
+ catch (error) {
40
+ console.error("❌ Build failed:", error);
41
+ process.exit(1);
42
+ }
43
+ }
44
+ main();
45
+ //# sourceMappingURL=bin.js.map
package/lib/bin.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.js","sourceRoot":"","sources":["../app/bin.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnC,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;AAExB,KAAK,UAAU,IAAI;IACjB,IAAI,CAAC;QACH,QAAQ,OAAO,EAAE,CAAC;YAChB,KAAK,OAAO;gBACV,iBAAiB;gBACjB,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;gBAC5C,MAAM,kBAAkB,EAAE,CAAC;gBAC3B,MAAM;YAER,KAAK,eAAe;gBAClB,sBAAsB;gBACtB,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;gBAC7C,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAC9B,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAC5C,IAAI,CACL,CAAC;gBACF,MAAM,kBAAkB,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC;gBAC1C,MAAM;YAER;gBACE,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;SAaX,CAAC,CAAC;gBACH,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;QACxC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC"}
package/lib/build.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ export interface BuildOptions {
2
+ /** 插件根目录 */
3
+ pluginRoot: string;
4
+ /** 输出目录,默认为 pluginRoot/dist */
5
+ outDir?: string;
6
+ /** 是否启用 tailwindcss,默认 true */
7
+ enableTailwind?: boolean;
8
+ }
9
+ export interface ConsoleBuildOptions {
10
+ /** Console 插件根目录 */
11
+ consoleRoot: string;
12
+ /** 输出目录,默认为 consoleRoot/dist */
13
+ outDir?: string;
14
+ }
15
+ /**
16
+ * 构建插件的客户端代码(单文件模式)
17
+ * 用于构建普通插件的 client/index.tsx 文件
18
+ *
19
+ * 策略:将公共依赖配置为 external,运行时从 console 加载的 vendor chunks 中复用
20
+ * @param options 构建选项
21
+ */
22
+ export declare function buildPluginClient(options: BuildOptions): Promise<void>;
23
+ /**
24
+ * 构建 Console 插件的客户端代码(SPA 应用模式)
25
+ * Console 有完整的 index.html 和 src 目录结构
26
+ * @param options Console 构建选项
27
+ */
28
+ export declare function buildConsoleClient(options: ConsoleBuildOptions): Promise<void>;
29
+ /**
30
+ * 构建当前目录的插件客户端代码
31
+ */
32
+ export declare function buildCurrentPlugin(): Promise<void>;
33
+ //# sourceMappingURL=build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../app/build.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,YAAY;IAC3B,YAAY;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,+BAA+B;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+BAA+B;IAC/B,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,mBAAmB;IAClC,oBAAoB;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,gCAAgC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AA0CD;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CA8D5E;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,IAAI,CAAC,CA4Df;AAED;;GAEG;AACH,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC,CAKxD"}
package/lib/build.js ADDED
@@ -0,0 +1,168 @@
1
+ import { build, searchForWorkspaceRoot } from "vite";
2
+ import react from "@vitejs/plugin-react";
3
+ import tailwindcss from "@tailwindcss/vite";
4
+ import path from "path";
5
+ import fs from "fs";
6
+ /**
7
+ * 查找插件的客户端入口文件
8
+ * @param pluginRoot 插件根目录
9
+ * @returns 入口文件路径,如果不存在则返回 null
10
+ */
11
+ function findClientEntry(pluginRoot) {
12
+ const possibleEntries = [
13
+ path.join(pluginRoot, "client/index.tsx"),
14
+ path.join(pluginRoot, "client/index.ts"),
15
+ path.join(pluginRoot, "src/main.tsx"),
16
+ path.join(pluginRoot, "src/main.ts"),
17
+ ];
18
+ for (const entry of possibleEntries) {
19
+ if (fs.existsSync(entry)) {
20
+ return entry;
21
+ }
22
+ }
23
+ return null;
24
+ }
25
+ /**
26
+ * 验证构建环境
27
+ * @param pluginRoot 插件根目录
28
+ * @throws 如果环境不满足构建要求
29
+ */
30
+ function validateBuildEnvironment(pluginRoot) {
31
+ if (!fs.existsSync(pluginRoot)) {
32
+ throw new Error(`Plugin root directory does not exist: ${pluginRoot}`);
33
+ }
34
+ const entry = findClientEntry(pluginRoot);
35
+ if (!entry) {
36
+ throw new Error(`No client entry file found in ${pluginRoot}. Looking for: client/index.tsx, client/index.ts, src/main.tsx, or src/main.ts`);
37
+ }
38
+ }
39
+ /**
40
+ * 构建插件的客户端代码(单文件模式)
41
+ * 用于构建普通插件的 client/index.tsx 文件
42
+ *
43
+ * 策略:将公共依赖配置为 external,运行时从 console 加载的 vendor chunks 中复用
44
+ * @param options 构建选项
45
+ */
46
+ export async function buildPluginClient(options) {
47
+ const { pluginRoot, outDir = path.join(pluginRoot, "dist"), enableTailwind = true, } = options;
48
+ // 验证构建环境
49
+ validateBuildEnvironment(pluginRoot);
50
+ const entry = findClientEntry(pluginRoot);
51
+ if (!entry) {
52
+ throw new Error(`No client entry file found in ${pluginRoot}`);
53
+ }
54
+ const plugins = [react()];
55
+ if (enableTailwind) {
56
+ plugins.push(tailwindcss());
57
+ }
58
+ // 构建配置 - 库模式
59
+ const clientRoot = path.dirname(entry);
60
+ await build({
61
+ root: clientRoot,
62
+ plugins,
63
+ build: {
64
+ outDir,
65
+ emptyOutDir: true,
66
+ lib: {
67
+ entry,
68
+ formats: ["es"],
69
+ fileName: "index",
70
+ },
71
+ rollupOptions: {
72
+ makeAbsoluteExternalsRelative: true,
73
+ external: [
74
+ 'react',
75
+ 'react-dom',
76
+ 'react/jsx-runtime',
77
+ 'clsx',
78
+ 'tailwind-merge',
79
+ 'lucide-react',
80
+ '@radix-ui/themes'
81
+ ],
82
+ },
83
+ },
84
+ resolve: {
85
+ dedupe: [
86
+ "react",
87
+ "react-dom",
88
+ "clsx",
89
+ "tailwind-merge",
90
+ ],
91
+ alias: {
92
+ "@": path.resolve(pluginRoot, "client/src"),
93
+ },
94
+ }
95
+ });
96
+ console.log(`✅ Plugin client code built successfully: ${outDir}`);
97
+ console.log(`📦 External dependencies will be loaded from console vendor chunks`);
98
+ }
99
+ /**
100
+ * 构建 Console 插件的客户端代码(SPA 应用模式)
101
+ * Console 有完整的 index.html 和 src 目录结构
102
+ * @param options Console 构建选项
103
+ */
104
+ export async function buildConsoleClient(options) {
105
+ const { consoleRoot, outDir = path.join(consoleRoot, "dist") } = options;
106
+ const clientRoot = path.join(consoleRoot, "client");
107
+ // 检查 client 目录是否存在
108
+ if (!fs.existsSync(clientRoot)) {
109
+ throw new Error(`Console client directory does not exist: ${clientRoot}`);
110
+ }
111
+ // 检查 index.html 是否存在
112
+ const indexHtml = path.join(clientRoot, "index.html");
113
+ if (!fs.existsSync(indexHtml)) {
114
+ throw new Error(`index.html not found in: ${clientRoot}`);
115
+ }
116
+ const workspaceRoot = searchForWorkspaceRoot(consoleRoot);
117
+ const consoleClientRoot = path.resolve(workspaceRoot, "plugins/client/client");
118
+ const plugins = [react(), tailwindcss()];
119
+ await build({
120
+ root: clientRoot,
121
+ plugins,
122
+ build: {
123
+ outDir,
124
+ emptyOutDir: true,
125
+ // 设置最小 chunk 大小,避免过度分割
126
+ chunkSizeWarningLimit: 1000,
127
+ // SPA 应用模式,不是库模式
128
+ rollupOptions: {
129
+ input: indexHtml,
130
+ // 保留导出签名
131
+ preserveEntrySignatures: 'strict',
132
+ output: {
133
+ // 确保文件名稳定,不使用哈希,方便插件引用
134
+ chunkFileNames: '[name].js',
135
+ entryFileNames: '[name].js',
136
+ assetFileNames: '[name].[ext]',
137
+ },
138
+ },
139
+ },
140
+ resolve: {
141
+ dedupe: [
142
+ "react",
143
+ "react-dom",
144
+ "clsx",
145
+ "tailwind-merge",
146
+ "@reduxjs/toolkit",
147
+ "react-router",
148
+ "react-redux",
149
+ "redux-persist",
150
+ ],
151
+ alias: {
152
+ "@zhin.js/client": consoleClientRoot,
153
+ "@": path.resolve(clientRoot, "src"),
154
+ },
155
+ },
156
+ });
157
+ console.log(`✅ Console client built successfully: ${outDir}`);
158
+ }
159
+ /**
160
+ * 构建当前目录的插件客户端代码
161
+ */
162
+ export async function buildCurrentPlugin() {
163
+ const currentDir = process.cwd();
164
+ await buildPluginClient({
165
+ pluginRoot: currentDir,
166
+ });
167
+ }
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c,EAAE,WAAW;oBAC3B,cAAc,EAAE,WAAW;oBAC3B,cAAc,EAAE,cAAc;iBAC/B;aACF;SACF;QACD,OAAO,EAAE;YACP,MAAM,EAAE;gBACN,OAAO;gBACP,WAAW;gBACX,MAAM;gBACN,gBAAgB;gBAChB,kBAAkB;gBAClB,cAAc;gBACd,aAAa;gBACb,eAAe;aAChB;YACD,KAAK,EAAE;gBACL,iBAAiB,EAAE,iBAAiB;gBACpC,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC;aACrC;SACF;KACF,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,wCAAwC,MAAM,EAAE,CAAC,CAAC;AAChE,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB;IACtC,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IACjC,MAAM,iBAAiB,CAAC;QACtB,UAAU,EAAE,UAAU;KACvB,CAAC,CAAC;AACL,CAAC"}
package/lib/dev.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ import { ViteDevServer } from "vite";
2
+ export interface DevServerOptions {
3
+ /** 客户端代码根目录 */
4
+ root: string;
5
+ /** 基础路径,默认 /vite/ */
6
+ base?: string;
7
+ /** 是否启用 tailwindcss,默认 true */
8
+ enableTailwind?: boolean;
9
+ }
10
+ /**
11
+ * 创建 Vite 开发服务器
12
+ * @param options 开发服务器选项
13
+ * @returns Vite 开发服务器实例
14
+ */
15
+ export declare function createViteDevServer(options: DevServerOptions): Promise<ViteDevServer>;
16
+ //# sourceMappingURL=dev.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../app/dev.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAwC,MAAM,MAAM,CAAC;AAK3E,MAAM,WAAW,gBAAgB;IAC/B,eAAe;IACf,IAAI,EAAE,MAAM,CAAC;IACb,qBAAqB;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,+BAA+B;IAC/B,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,aAAa,CAAC,CA6DxB"}
package/lib/dev.js ADDED
@@ -0,0 +1,70 @@
1
+ import { createServer, searchForWorkspaceRoot } from "vite";
2
+ import react from "@vitejs/plugin-react";
3
+ import tailwindcss from "@tailwindcss/vite";
4
+ import path from "path";
5
+ /**
6
+ * 创建 Vite 开发服务器
7
+ * @param options 开发服务器选项
8
+ * @returns Vite 开发服务器实例
9
+ */
10
+ export async function createViteDevServer(options) {
11
+ const { root, base = "/vite/", enableTailwind = true } = options;
12
+ const plugins = [react()];
13
+ if (enableTailwind) {
14
+ plugins.push(tailwindcss());
15
+ }
16
+ return await await createServer({
17
+ root,
18
+ base,
19
+ plugins: [react(), tailwindcss()],
20
+ server: {
21
+ middlewareMode: true,
22
+ fs: {
23
+ strict: false,
24
+ // 添加文件访问过滤,避免访问特殊文件
25
+ allow: [
26
+ // 允许访问的目录
27
+ root,
28
+ searchForWorkspaceRoot(root),
29
+ path.resolve(process.cwd(), 'node_modules'),
30
+ path.resolve(process.cwd(), 'client'),
31
+ path.resolve(process.cwd(), 'src'),
32
+ ],
33
+ // 拒绝访问某些文件模式
34
+ deny: [
35
+ '**/.git/**',
36
+ '**/node_modules/.cache/**',
37
+ '**/*.socket',
38
+ '**/*.pipe',
39
+ '**/Dockerfile*',
40
+ '**/.env*',
41
+ ],
42
+ },
43
+ },
44
+ resolve: {
45
+ dedupe: [
46
+ "react",
47
+ "react-dom",
48
+ "clsx",
49
+ "tailwind-merge",
50
+ "@reduxjs/toolkit",
51
+ "react-router",
52
+ "react-redux",
53
+ "redux-persist",
54
+ ],
55
+ alias: {
56
+ "@zhin.js/client": path.resolve(root, "../../client/client"),
57
+ "@": path.resolve(root, "../client/src"),
58
+ },
59
+ },
60
+ optimizeDeps: {
61
+ include: ["react", "react-dom"],
62
+ },
63
+ build: {
64
+ rollupOptions: {
65
+ input: root + "/index.html",
66
+ },
67
+ },
68
+ });
69
+ }
70
+ //# sourceMappingURL=dev.js.map
package/lib/dev.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev.js","sourceRoot":"","sources":["../app/dev.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,YAAY,EAAE,sBAAsB,EAAE,MAAM,MAAM,CAAC;AAC3E,OAAO,KAAK,MAAM,sBAAsB,CAAC;AACzC,OAAO,WAAW,MAAM,mBAAmB,CAAC;AAC5C,OAAO,IAAI,MAAM,MAAM,CAAC;AAWxB;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,OAAyB;IAEzB,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,QAAQ,EAAE,cAAc,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;IAEjE,MAAM,OAAO,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC;IAC1B,IAAI,cAAc,EAAE,CAAC;QACnB,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;IAC9B,CAAC;IAED,OAAO,MAAM,MAAM,YAAY,CAAC;QAC9B,IAAI;QACJ,IAAI;QACJ,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,WAAW,EAAE,CAAC;QACjC,MAAM,EAAE;YACN,cAAc,EAAE,IAAI;YACpB,EAAE,EAAE;gBACF,MAAM,EAAE,KAAK;gBACb,oBAAoB;gBACpB,KAAK,EAAE;oBACL,UAAU;oBACV,IAAI;oBACJ,sBAAsB,CAAC,IAAI,CAAC;oBAC5B,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC;oBAC3C,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,CAAC;oBACrC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,CAAC;iBACnC;gBACD,aAAa;gBACb,IAAI,EAAE;oBACJ,YAAY;oBACZ,2BAA2B;oBAC3B,aAAa;oBACb,WAAW;oBACX,gBAAgB;oBAChB,UAAU;iBACX;aACF;SACF;QACD,OAAO,EAAE;YACP,MAAM,EAAE;gBACN,OAAO;gBACP,WAAW;gBACX,MAAM;gBACN,gBAAgB;gBAChB,kBAAkB;gBAClB,cAAc;gBACd,aAAa;gBACb,eAAe;aAChB;YACD,KAAK,EAAE;gBACL,iBAAiB,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,qBAAqB,CAAC;gBAC5D,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,eAAe,CAAC;aACzC;SACF;QACD,YAAY,EAAE;YACZ,OAAO,EAAE,CAAC,OAAO,EAAE,WAAW,CAAC;SAChC;QACD,KAAK,EAAE;YACL,aAAa,EAAE;gBACb,KAAK,EAAE,IAAI,GAAG,aAAa;aAC5B;SACF;KACF,CAAC,CAAC;AACL,CAAC"}
package/lib/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { WebSocketServer } from 'ws';
2
- import { ViteDevServer } from 'vite';
3
- declare module '@zhin.js/types' {
1
+ import { WebSocketServer } from "ws";
2
+ import { ViteDevServer } from "vite";
3
+ declare module "@zhin.js/types" {
4
4
  interface GlobalContext {
5
5
  web: WebServer;
6
6
  }
@@ -10,7 +10,7 @@ export type WebEntry = string | {
10
10
  development: string;
11
11
  };
12
12
  export type WebServer = {
13
- vite: ViteDevServer;
13
+ vite?: ViteDevServer;
14
14
  addEntry(entry: WebEntry): () => void;
15
15
  entries: Record<string, string>;
16
16
  ws: WebSocketServer;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAiB,EAAC,eAAe,EAAC,MAAM,IAAI,CAAC;AAC7C,OAAO,EAAc,aAAa,EAAwB,MAAM,MAAM,CAAC;AAOvE,OAAO,QAAQ,gBAAgB,CAAC;IAC5B,UAAU,aAAa;QACnB,GAAG,EAAE,SAAS,CAAC;KAClB;CACJ;AACD,MAAM,MAAM,QAAQ,GAAC,MAAM,GAAC;IACxB,UAAU,EAAC,MAAM,CAAA;IACjB,WAAW,EAAC,MAAM,CAAA;CACrB,CAAA;AACD,MAAM,MAAM,SAAS,GAAG;IACpB,IAAI,EAAC,aAAa,CAAC;IACnB,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,IAAI,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,EAAE,EAAC,eAAe,CAAA;CACrB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../app/index.ts"],"names":[],"mappings":"AACA,OAAQ,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAQrC,OAAO,QAAQ,gBAAgB,CAAC;IAC9B,UAAU,aAAa;QACrB,GAAG,EAAE,SAAS,CAAC;KAChB;CACF;AACD,MAAM,MAAM,QAAQ,GAChB,MAAM,GACN;IACE,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AACN,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,IAAI,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,EAAE,EAAE,eAAe,CAAC;CACrB,CAAC"}