collabdocchat 1.0.1 → 1.0.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "collabdocchat",
3
- "version": "1.0.1",
3
+ "version": "1.0.4",
4
4
  "description": "开源的实时协作文档聊天平台 - 集成任务管理、多人文档编辑、智能点名功能",
5
5
  "main": "./server/index.js",
6
6
  "type": "module",
@@ -1,159 +1,167 @@
1
- import { spawn } from 'child_process';
2
- import { platform } from 'os';
3
- import { fileURLToPath } from 'url';
4
- import { dirname, join } from 'path';
5
- import http from 'http';
6
-
7
- const __filename = fileURLToPath(import.meta.url);
8
- const __dirname = dirname(__filename);
9
- const rootDir = join(__dirname, '..');
10
-
11
- const PORT = process.env.PORT || 3000;
12
- const CLIENT_PORT = 5173;
13
- const CLIENT_URL = `http://localhost:${CLIENT_PORT}`;
14
-
15
- // 打开浏览器的函数
16
- function openBrowser(url) {
17
- const platformName = platform();
18
- let command;
19
- let args;
20
-
21
- switch (platformName) {
22
- case 'win32':
23
- command = 'cmd';
24
- args = ['/c', 'start', url];
25
- break;
26
- case 'darwin':
27
- command = 'open';
28
- args = [url];
29
- break;
30
- default:
31
- command = 'xdg-open';
32
- args = [url];
33
- }
34
-
35
- const browser = spawn(command, args, { stdio: 'ignore', detached: true });
36
- browser.unref();
37
- }
38
-
39
- // 检查服务器是否就绪
40
- function waitForServer(url, maxAttempts = 30, delay = 1000) {
41
- return new Promise((resolve, reject) => {
42
- let attempts = 0;
43
- const urlObj = new URL(url);
44
-
45
- const check = () => {
46
- attempts++;
47
-
48
- const req = http.get({
49
- hostname: urlObj.hostname,
50
- port: urlObj.port,
51
- path: urlObj.pathname,
52
- timeout: 1000
53
- }, (res) => {
54
- if (res.statusCode === 200) {
55
- resolve();
56
- return;
57
- }
58
- if (attempts < maxAttempts) {
59
- setTimeout(check, delay);
60
- } else {
61
- reject(new Error('服务器启动超时'));
62
- }
63
- });
64
-
65
- req.on('error', () => {
66
- if (attempts < maxAttempts) {
67
- setTimeout(check, delay);
68
- } else {
69
- reject(new Error('服务器启动超时'));
70
- }
71
- });
72
-
73
- req.on('timeout', () => {
74
- req.destroy();
75
- if (attempts < maxAttempts) {
76
- setTimeout(check, delay);
77
- } else {
78
- reject(new Error('服务器启动超时'));
79
- }
80
- });
81
- };
82
-
83
- check();
84
- });
85
- }
86
-
87
- // 启动服务器
88
- function startServer() {
89
- console.log('\n🚀 正在启动 CollabDocChat 服务器...');
90
- const server = spawn('node', ['server/index.js'], {
91
- cwd: rootDir,
92
- stdio: 'inherit',
93
- shell: true,
94
- detached: true
95
- });
96
-
97
- server.unref();
98
- return server;
99
- }
100
-
101
- // 启动客户端
102
- function startClient() {
103
- console.log('🎨 正在启动客户端...');
104
- const client = spawn('npm', ['run', 'client'], {
105
- cwd: rootDir,
106
- stdio: 'inherit',
107
- shell: true,
108
- detached: true
109
- });
110
-
111
- client.unref();
112
- return client;
113
- }
114
-
115
- // 主函数
116
- async function main() {
117
- console.log('\n📦 CollabDocChat 安装完成!');
118
- console.log('🚀 正在自动启动应用...\n');
119
-
120
- // 启动服务器
121
- const server = startServer();
122
-
123
- // 等待服务器就绪
124
- try {
125
- await waitForServer(`http://localhost:${PORT}/health`, 30, 1000);
126
- console.log(`✅ 服务器已就绪: http://localhost:${PORT}\n`);
127
- } catch (error) {
128
- console.error('❌ 服务器启动失败:', error.message);
129
- console.log('\n💡 请确保:');
130
- console.log(' 1. MongoDB 已启动');
131
- console.log(' 2. 端口 3000 和 5173 未被占用');
132
- console.log(' 3. 运行 npm start 手动启动');
133
- process.exit(0);
134
- return;
135
- }
136
-
137
- // 启动客户端
138
- const client = startClient();
139
-
140
- // 等待客户端就绪后打开浏览器
141
- setTimeout(async () => {
142
- try {
143
- await waitForServer(CLIENT_URL, 20, 500);
144
- console.log(`\n🌐 正在打开浏览器: ${CLIENT_URL}`);
145
- openBrowser(CLIENT_URL);
146
- console.log('\n✅ 应用已启动!浏览器应该已经自动打开。');
147
- console.log('\n💡 提示:按 Ctrl+C 可以停止服务器');
148
- } catch (error) {
149
- console.log(`\n⚠️ 客户端可能还在启动中,请手动访问: ${CLIENT_URL}`);
150
- openBrowser(CLIENT_URL);
151
- }
152
- }, 2000);
153
- }
154
-
155
- main().catch(error => {
156
- console.error('❌ 启动失败:', error.message);
157
- console.log('\n💡 可以运行 npm start 手动启动应用');
158
- });
159
-
1
+ import { spawn } from 'child_process';
2
+ import { platform } from 'os';
3
+ import { fileURLToPath } from 'url';
4
+ import { dirname, join } from 'path';
5
+ import http from 'http';
6
+
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __dirname = dirname(__filename);
9
+ const rootDir = join(__dirname, '..');
10
+
11
+ const PORT = process.env.PORT || 3000;
12
+ const CLIENT_PORT = 5173;
13
+ const CLIENT_URL = `http://localhost:${CLIENT_PORT}`;
14
+
15
+ // 打开浏览器的函数
16
+ function openBrowser(url) {
17
+ const platformName = platform();
18
+ let command;
19
+ let args;
20
+
21
+ switch (platformName) {
22
+ case 'win32':
23
+ command = 'cmd';
24
+ args = ['/c', 'start', url];
25
+ break;
26
+ case 'darwin':
27
+ command = 'open';
28
+ args = [url];
29
+ break;
30
+ default:
31
+ command = 'xdg-open';
32
+ args = [url];
33
+ }
34
+
35
+ const browser = spawn(command, args, { stdio: 'ignore', detached: true });
36
+ browser.unref();
37
+ }
38
+
39
+ // 检查服务器是否就绪
40
+ function waitForServer(url, maxAttempts = 30, delay = 1000) {
41
+ return new Promise((resolve, reject) => {
42
+ let attempts = 0;
43
+ const urlObj = new URL(url);
44
+
45
+ const check = () => {
46
+ attempts++;
47
+
48
+ const req = http.get({
49
+ hostname: urlObj.hostname,
50
+ port: urlObj.port,
51
+ path: urlObj.pathname,
52
+ timeout: 1000
53
+ }, (res) => {
54
+ if (res.statusCode === 200) {
55
+ resolve();
56
+ return;
57
+ }
58
+ if (attempts < maxAttempts) {
59
+ setTimeout(check, delay);
60
+ } else {
61
+ reject(new Error('服务器启动超时'));
62
+ }
63
+ });
64
+
65
+ req.on('error', () => {
66
+ if (attempts < maxAttempts) {
67
+ setTimeout(check, delay);
68
+ } else {
69
+ reject(new Error('服务器启动超时'));
70
+ }
71
+ });
72
+
73
+ req.on('timeout', () => {
74
+ req.destroy();
75
+ if (attempts < maxAttempts) {
76
+ setTimeout(check, delay);
77
+ } else {
78
+ reject(new Error('服务器启动超时'));
79
+ }
80
+ });
81
+ };
82
+
83
+ check();
84
+ });
85
+ }
86
+
87
+ // 启动服务器
88
+ function startServer() {
89
+ console.log('\n🚀 正在启动 CollabDocChat 服务器...');
90
+ const server = spawn('node', ['server/index.js'], {
91
+ cwd: rootDir,
92
+ stdio: 'inherit',
93
+ detached: true,
94
+ windowsHide: true
95
+ });
96
+
97
+ server.unref();
98
+ return server;
99
+ }
100
+
101
+ // 启动客户端
102
+ function startClient() {
103
+ console.log('🎨 正在启动客户端...');
104
+ const isWindows = platform() === 'win32';
105
+ const client = spawn(isWindows ? 'npm.cmd' : 'npm', ['run', 'client'], {
106
+ cwd: rootDir,
107
+ stdio: 'inherit',
108
+ detached: true,
109
+ windowsHide: true
110
+ });
111
+
112
+ client.unref();
113
+ return client;
114
+ }
115
+
116
+ // 主函数 - 在后台异步运行,不阻塞安装
117
+ async function main() {
118
+ console.log('\n📦 CollabDocChat 安装完成!');
119
+ console.log('🚀 正在自动启动应用...\n');
120
+
121
+ // 启动服务器
122
+ const server = startServer();
123
+
124
+ // 等待服务器就绪(不阻塞,在后台检查)
125
+ waitForServer(`http://localhost:${PORT}/health`, 30, 1000)
126
+ .then(() => {
127
+ console.log(`✅ 服务器已就绪: http://localhost:${PORT}\n`);
128
+
129
+ // 启动客户端
130
+ const client = startClient();
131
+
132
+ // 等待客户端就绪后打开浏览器
133
+ setTimeout(async () => {
134
+ try {
135
+ await waitForServer(CLIENT_URL, 30, 1000);
136
+ console.log(`\n🌐 正在打开浏览器: ${CLIENT_URL}`);
137
+ openBrowser(CLIENT_URL);
138
+ console.log('\n✅ 应用已启动!浏览器应该已经自动打开。');
139
+ } catch (error) {
140
+ // 即使检查失败也尝试打开浏览器(客户端可能正在启动)
141
+ console.log(`\n🌐 正在打开浏览器: ${CLIENT_URL}`);
142
+ openBrowser(CLIENT_URL);
143
+ console.log('\n✅ 应用正在启动中,浏览器已打开。');
144
+ console.log(' 如果页面未加载,请稍等片刻后刷新页面。');
145
+ }
146
+ }, 5000);
147
+ })
148
+ .catch(error => {
149
+ console.error('❌ 服务器启动失败:', error.message);
150
+ console.log('\n💡 请确保:');
151
+ console.log(' 1. MongoDB 已启动');
152
+ console.log(' 2. 端口 3000 和 5173 未被占用');
153
+ console.log(' 3. 运行 npm start 手动启动');
154
+ });
155
+ }
156
+
157
+ // 启动后台进程,不阻塞安装
158
+ main().catch(error => {
159
+ // 静默处理错误,不影响安装过程
160
+ });
161
+
162
+ // 不立即退出,让后台进程有时间启动
163
+ // 但也不阻塞安装过程
164
+ setTimeout(() => {
165
+ process.exit(0);
166
+ }, 2000);
167
+
@@ -1,164 +1,164 @@
1
- import { spawn } from 'child_process';
2
- import { platform } from 'os';
3
- import { fileURLToPath } from 'url';
4
- import { dirname, join } from 'path';
5
- import http from 'http';
6
-
7
- const __filename = fileURLToPath(import.meta.url);
8
- const __dirname = dirname(__filename);
9
- const rootDir = join(__dirname, '..');
10
-
11
- const PORT = process.env.PORT || 3000;
12
- const CLIENT_PORT = 5173;
13
- const CLIENT_URL = `http://localhost:${CLIENT_PORT}`;
14
-
15
- // 打开浏览器的函数
16
- function openBrowser(url) {
17
- const platformName = platform();
18
- let command;
19
- let args;
20
-
21
- switch (platformName) {
22
- case 'win32':
23
- command = 'cmd';
24
- args = ['/c', 'start', url];
25
- break;
26
- case 'darwin':
27
- command = 'open';
28
- args = [url];
29
- break;
30
- default:
31
- command = 'xdg-open';
32
- args = [url];
33
- }
34
-
35
- const browser = spawn(command, args, { stdio: 'ignore', detached: true });
36
- browser.unref();
37
- }
38
-
39
- // 检查服务器是否就绪
40
- function waitForServer(url, maxAttempts = 30, delay = 1000) {
41
- return new Promise((resolve, reject) => {
42
- let attempts = 0;
43
- const urlObj = new URL(url);
44
-
45
- const check = () => {
46
- attempts++;
47
-
48
- const req = http.get({
49
- hostname: urlObj.hostname,
50
- port: urlObj.port,
51
- path: urlObj.pathname,
52
- timeout: 1000
53
- }, (res) => {
54
- if (res.statusCode === 200) {
55
- resolve();
56
- return;
57
- }
58
- // 继续等待
59
- if (attempts < maxAttempts) {
60
- setTimeout(check, delay);
61
- } else {
62
- reject(new Error('服务器启动超时'));
63
- }
64
- });
65
-
66
- req.on('error', () => {
67
- // 服务器未就绪,继续等待
68
- if (attempts < maxAttempts) {
69
- setTimeout(check, delay);
70
- } else {
71
- reject(new Error('服务器启动超时'));
72
- }
73
- });
74
-
75
- req.on('timeout', () => {
76
- req.destroy();
77
- if (attempts < maxAttempts) {
78
- setTimeout(check, delay);
79
- } else {
80
- reject(new Error('服务器启动超时'));
81
- }
82
- });
83
- };
84
-
85
- check();
86
- });
87
- }
88
-
89
- // 启动服务器
90
- function startServer() {
91
- console.log('🚀 正在启动服务器...');
92
- const server = spawn('node', ['server/index.js'], {
93
- cwd: rootDir,
94
- stdio: 'inherit',
95
- shell: true
96
- });
97
-
98
- return server;
99
- }
100
-
101
- // 启动客户端(如果使用 Vite)
102
- function startClient() {
103
- console.log('🎨 正在启动客户端...');
104
- const client = spawn('npm', ['run', 'client'], {
105
- cwd: rootDir,
106
- stdio: 'inherit',
107
- shell: true
108
- });
109
-
110
- return client;
111
- }
112
-
113
- // 主函数
114
- async function main() {
115
- console.log('📦 CollabDocChat 正在启动...\n');
116
-
117
- // 启动服务器
118
- const server = startServer();
119
-
120
- // 等待服务器就绪
121
- try {
122
- await waitForServer(`http://localhost:${PORT}/health`, 30, 1000);
123
- console.log(`✅ 服务器已就绪: http://localhost:${PORT}\n`);
124
- } catch (error) {
125
- console.error('❌ 服务器启动失败:', error.message);
126
- process.exit(1);
127
- }
128
-
129
- // 启动客户端
130
- const client = startClient();
131
-
132
- // 等待客户端就绪后打开浏览器
133
- setTimeout(async () => {
134
- try {
135
- await waitForServer(CLIENT_URL, 20, 500);
136
- console.log(`\n🌐 正在打开浏览器: ${CLIENT_URL}`);
137
- openBrowser(CLIENT_URL);
138
- } catch (error) {
139
- console.log(`\n⚠️ 客户端可能还在启动中,请手动访问: ${CLIENT_URL}`);
140
- // 即使检查失败也尝试打开浏览器
141
- openBrowser(CLIENT_URL);
142
- }
143
- }, 2000);
144
-
145
- // 处理退出信号
146
- process.on('SIGINT', () => {
147
- console.log('\n\n🛑 正在关闭服务器...');
148
- server.kill();
149
- client.kill();
150
- process.exit(0);
151
- });
152
-
153
- process.on('SIGTERM', () => {
154
- server.kill();
155
- client.kill();
156
- process.exit(0);
157
- });
158
- }
159
-
160
- main().catch(error => {
161
- console.error('❌ 启动失败:', error);
162
- process.exit(1);
163
- });
164
-
1
+ import { spawn } from 'child_process';
2
+ import { platform } from 'os';
3
+ import { fileURLToPath } from 'url';
4
+ import { dirname, join } from 'path';
5
+ import http from 'http';
6
+
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __dirname = dirname(__filename);
9
+ const rootDir = join(__dirname, '..');
10
+
11
+ const PORT = process.env.PORT || 3000;
12
+ const CLIENT_PORT = 5173;
13
+ const CLIENT_URL = `http://localhost:${CLIENT_PORT}`;
14
+
15
+ // 打开浏览器的函数
16
+ function openBrowser(url) {
17
+ const platformName = platform();
18
+ let command;
19
+ let args;
20
+
21
+ switch (platformName) {
22
+ case 'win32':
23
+ command = 'cmd';
24
+ args = ['/c', 'start', url];
25
+ break;
26
+ case 'darwin':
27
+ command = 'open';
28
+ args = [url];
29
+ break;
30
+ default:
31
+ command = 'xdg-open';
32
+ args = [url];
33
+ }
34
+
35
+ const browser = spawn(command, args, { stdio: 'ignore', detached: true });
36
+ browser.unref();
37
+ }
38
+
39
+ // 检查服务器是否就绪
40
+ function waitForServer(url, maxAttempts = 30, delay = 1000) {
41
+ return new Promise((resolve, reject) => {
42
+ let attempts = 0;
43
+ const urlObj = new URL(url);
44
+
45
+ const check = () => {
46
+ attempts++;
47
+
48
+ const req = http.get({
49
+ hostname: urlObj.hostname,
50
+ port: urlObj.port,
51
+ path: urlObj.pathname,
52
+ timeout: 1000
53
+ }, (res) => {
54
+ if (res.statusCode === 200) {
55
+ resolve();
56
+ return;
57
+ }
58
+ // 继续等待
59
+ if (attempts < maxAttempts) {
60
+ setTimeout(check, delay);
61
+ } else {
62
+ reject(new Error('服务器启动超时'));
63
+ }
64
+ });
65
+
66
+ req.on('error', () => {
67
+ // 服务器未就绪,继续等待
68
+ if (attempts < maxAttempts) {
69
+ setTimeout(check, delay);
70
+ } else {
71
+ reject(new Error('服务器启动超时'));
72
+ }
73
+ });
74
+
75
+ req.on('timeout', () => {
76
+ req.destroy();
77
+ if (attempts < maxAttempts) {
78
+ setTimeout(check, delay);
79
+ } else {
80
+ reject(new Error('服务器启动超时'));
81
+ }
82
+ });
83
+ };
84
+
85
+ check();
86
+ });
87
+ }
88
+
89
+ // 启动服务器
90
+ function startServer() {
91
+ console.log('🚀 正在启动服务器...');
92
+ const server = spawn('node', ['server/index.js'], {
93
+ cwd: rootDir,
94
+ stdio: 'inherit',
95
+ shell: true
96
+ });
97
+
98
+ return server;
99
+ }
100
+
101
+ // 启动客户端(如果使用 Vite)
102
+ function startClient() {
103
+ console.log('🎨 正在启动客户端...');
104
+ const client = spawn('npm', ['run', 'client'], {
105
+ cwd: rootDir,
106
+ stdio: 'inherit',
107
+ shell: true
108
+ });
109
+
110
+ return client;
111
+ }
112
+
113
+ // 主函数
114
+ async function main() {
115
+ console.log('📦 CollabDocChat 正在启动...\n');
116
+
117
+ // 启动服务器
118
+ const server = startServer();
119
+
120
+ // 等待服务器就绪
121
+ try {
122
+ await waitForServer(`http://localhost:${PORT}/health`, 30, 1000);
123
+ console.log(`✅ 服务器已就绪: http://localhost:${PORT}\n`);
124
+ } catch (error) {
125
+ console.error('❌ 服务器启动失败:', error.message);
126
+ process.exit(1);
127
+ }
128
+
129
+ // 启动客户端
130
+ const client = startClient();
131
+
132
+ // 等待客户端就绪后打开浏览器
133
+ setTimeout(async () => {
134
+ try {
135
+ await waitForServer(CLIENT_URL, 20, 500);
136
+ console.log(`\n🌐 正在打开浏览器: ${CLIENT_URL}`);
137
+ openBrowser(CLIENT_URL);
138
+ } catch (error) {
139
+ console.log(`\n⚠️ 客户端可能还在启动中,请手动访问: ${CLIENT_URL}`);
140
+ // 即使检查失败也尝试打开浏览器
141
+ openBrowser(CLIENT_URL);
142
+ }
143
+ }, 2000);
144
+
145
+ // 处理退出信号
146
+ process.on('SIGINT', () => {
147
+ console.log('\n\n🛑 正在关闭服务器...');
148
+ server.kill();
149
+ client.kill();
150
+ process.exit(0);
151
+ });
152
+
153
+ process.on('SIGTERM', () => {
154
+ server.kill();
155
+ client.kill();
156
+ process.exit(0);
157
+ });
158
+ }
159
+
160
+ main().catch(error => {
161
+ console.error('❌ 启动失败:', error);
162
+ process.exit(1);
163
+ });
164
+