fdb2 1.0.3 → 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/bin/fdb2.js +11 -3
- package/package.json +2 -1
- package/scripts/preinstall.js +38 -0
- package/server.pid +0 -1
package/bin/fdb2.js
CHANGED
|
@@ -48,12 +48,19 @@ function startProject() {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
// 解析端口参数
|
|
52
|
+
let port = 9800;
|
|
53
|
+
const portIndex = commandArgs.findIndex(arg => arg === '-p' || arg === '--port');
|
|
54
|
+
if (portIndex !== -1 && commandArgs[portIndex + 1]) {
|
|
55
|
+
port = parseInt(commandArgs[portIndex + 1]);
|
|
56
|
+
}
|
|
57
|
+
|
|
51
58
|
// 命令和参数
|
|
52
59
|
let cmd, args;
|
|
53
60
|
|
|
54
|
-
// 直接使用 node
|
|
61
|
+
// 直接使用 node 命令启动服务器,传递端口参数
|
|
55
62
|
cmd = 'node';
|
|
56
|
-
args = ['server.js',
|
|
63
|
+
args = ['server.js', '-p', port.toString()];
|
|
57
64
|
|
|
58
65
|
console.log('Executing:', cmd, args);
|
|
59
66
|
|
|
@@ -77,9 +84,10 @@ function startProject() {
|
|
|
77
84
|
// 保存 PID 到文件
|
|
78
85
|
fs.writeFileSync(pidFilePath, child.pid.toString());
|
|
79
86
|
|
|
87
|
+
console.log('Logs are written to:', logFilePath);
|
|
80
88
|
console.log('Server started successfully with PID:', child.pid);
|
|
81
89
|
console.log('Server is running in the background');
|
|
82
|
-
console.log(
|
|
90
|
+
console.log(`Server is running at http://localhost:${port}`);
|
|
83
91
|
}
|
|
84
92
|
|
|
85
93
|
// 停止项目
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fdb2",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "view/index.html",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"icon": "public/favicon.ico"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
|
+
"preinstall": "node scripts/preinstall.js",
|
|
19
20
|
"start": "pm2 start server.js --name fdb2-server --disable-logs --",
|
|
20
21
|
"restart": "pm2 restart fdb2-server --disable-logs --",
|
|
21
22
|
"stop": "pm2 stop fdb2-server --",
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const { execSync } = require('child_process');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
|
|
5
|
+
console.log('Checking for running fdb2 instances...');
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
const projectRoot = path.resolve(__dirname, '..');
|
|
9
|
+
const pidFilePath = path.join(projectRoot, 'server.pid');
|
|
10
|
+
|
|
11
|
+
if (fs.existsSync(pidFilePath)) {
|
|
12
|
+
try {
|
|
13
|
+
const pid = parseInt(fs.readFileSync(pidFilePath, 'utf8'));
|
|
14
|
+
process.kill(pid, 0);
|
|
15
|
+
console.log('Found running fdb2 instance with PID:', pid);
|
|
16
|
+
console.log('Stopping fdb2...');
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
execSync('node bin/fdb2.js stop', {
|
|
20
|
+
cwd: projectRoot,
|
|
21
|
+
stdio: 'inherit'
|
|
22
|
+
});
|
|
23
|
+
console.log('fdb2 stopped successfully');
|
|
24
|
+
} catch (stopError) {
|
|
25
|
+
console.warn('Failed to stop fdb2:', stopError.message);
|
|
26
|
+
}
|
|
27
|
+
} catch (error) {
|
|
28
|
+
if (error.code === 'ESRCH') {
|
|
29
|
+
console.log('Cleaning up stale PID file...');
|
|
30
|
+
fs.unlinkSync(pidFilePath);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
console.log('No running fdb2 instance found');
|
|
35
|
+
}
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.warn('Pre-install check failed:', error.message);
|
|
38
|
+
}
|
package/server.pid
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
7684
|