fdb2 1.0.15 → 1.0.17

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 CHANGED
@@ -57,6 +57,10 @@ switch (command) {
57
57
  case 'restart':
58
58
  restartProject();
59
59
  break;
60
+ case '-v':
61
+ case '--version':
62
+ showVersion();
63
+ break;
60
64
  default:
61
65
  showHelp();
62
66
  break;
@@ -307,6 +311,12 @@ function restartProject() {
307
311
  startProject();
308
312
  }
309
313
 
314
+ // 显示版本号
315
+ function showVersion() {
316
+ const pkg = JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf8'));
317
+ console.log(pkg.version);
318
+ }
319
+
310
320
  // 显示帮助信息
311
321
  function showHelp() {
312
322
  console.log('FDB2 Database Tool');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fdb2",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "private": false,
5
5
  "type": "commonjs",
6
6
  "main": "view/index.html",
@@ -8,6 +8,7 @@
8
8
  "bin/",
9
9
  "public/",
10
10
  "view/",
11
+ "scripts/",
11
12
  "server.js",
12
13
  "package.json",
13
14
  "README.md"
@@ -26,7 +27,6 @@
26
27
  "icon": "public/favicon.ico"
27
28
  },
28
29
  "scripts": {
29
- "preinstall": "node scripts/preinstall.js",
30
30
  "start": "pm2 start server.js --name fdb2-server --disable-logs --",
31
31
  "restart": "pm2 restart fdb2-server --disable-logs --",
32
32
  "stop": "pm2 stop fdb2-server --",
@@ -0,0 +1,136 @@
1
+ const nwbuilder = require('nw-builder');
2
+ const { resolve, join } = require('path');
3
+ const { copyFileSync, existsSync, readdirSync } = require('fs');
4
+
5
+ const projectRoot = resolve(__dirname, '..');
6
+
7
+ const args = process.argv.slice(2);
8
+ const targetPlatform = args.find(arg => arg.startsWith('--platform='))?.split('=')[1];
9
+
10
+ const supportedPlatforms = ['win', 'osx', 'linux'];
11
+
12
+ function getCurrentPlatform() {
13
+ const platform = process.platform;
14
+ if (platform === 'darwin') return ['osx'];
15
+ if (platform === 'linux') return ['linux'];
16
+ return ['win', 'linux'];
17
+ }
18
+
19
+ function getAppConfig(platform) {
20
+ const config = {
21
+ icon: resolve(projectRoot, 'dist', 'public', 'favicon.ico')
22
+ };
23
+
24
+ if (platform === 'osx') {
25
+ config.LSApplicationCategoryType = 'public.app-category.productivity';
26
+ config.NSHumanReadableCopyright = 'Copyright © 2025';
27
+ config.NSLocalNetworkUsageDescription = '需要网络访问以连接数据库';
28
+ config.CFBundleIdentifier = 'com.fdb.database';
29
+ config.CFBundleName = '数据库管理工具';
30
+ config.CFBundleDisplayName = '数据库管理工具';
31
+ config.CFBundleShortVersionString = '1.0.1';
32
+ config.CFBundleVersion = '1.0.1';
33
+ }
34
+
35
+ return config;
36
+ }
37
+
38
+ async function buildPlatform(platform) {
39
+ const outDir = resolve(projectRoot, `release/fdb2-${platform}`);
40
+ console.log(`\n========================================`);
41
+ console.log(`开始构建 ${platform} 平台...`);
42
+ console.log(`========================================`);
43
+
44
+ const buildOptions = {
45
+ mode: 'build',
46
+ srcDir: resolve(projectRoot, 'dist'),
47
+ version: '0.78.1',
48
+ flavor: 'normal',
49
+ platform: platform,
50
+ arch: 'x64',
51
+ outDir: outDir,
52
+ cacheDir: resolve(projectRoot, 'nw-cache'),
53
+ downloadUrl: 'https://github.com/nwjs/nw.js/releases/download/v0.78.1',
54
+ zip: false,
55
+ logLevel: 'info',
56
+ glob: false,
57
+ app: getAppConfig(platform)
58
+ };
59
+
60
+ await nwbuilder.default(buildOptions);
61
+
62
+ const packagedPath = join(outDir, platform, 'x64', 'package.nw', 'node_modules');
63
+ if (existsSync(packagedPath)) {
64
+ console.log(`✅ ${platform} 应用程序已包含 node_modules 目录 (${readdirSync(packagedPath).length} 个包)`);
65
+ } else {
66
+ console.log(`⚠️ ${platform} 应用程序不包含 node_modules 目录`);
67
+ }
68
+
69
+ console.log(`✅ ${platform} 平台构建完成 -> ${outDir}`);
70
+ }
71
+
72
+ async function build() {
73
+ try {
74
+ console.log('开始构建 NW.js 应用...\n');
75
+
76
+ console.log('1. 构建 Vue 应用...');
77
+ const { execSync } = require('child_process');
78
+ execSync('npm run build', { stdio: 'inherit', cwd: projectRoot });
79
+
80
+ console.log('\n2. 复制 package.json 到 dist 目录...');
81
+ copyFileSync(
82
+ join(projectRoot, 'package.json'),
83
+ join(projectRoot, 'dist', 'package.json')
84
+ );
85
+
86
+ console.log('\n3. 安装 npm 依赖到 dist 目录...');
87
+ const distPath = resolve(projectRoot, 'dist');
88
+ execSync('pnpm install --only=production', {
89
+ stdio: 'inherit',
90
+ cwd: distPath
91
+ });
92
+
93
+ if (!existsSync(join(distPath, 'node_modules'))) {
94
+ throw new Error('npm install 失败');
95
+ }
96
+ console.log('npm 依赖安装成功\n');
97
+
98
+ console.log('4. 配置 NW.js 构建参数...');
99
+
100
+ let platformsToBuild = [];
101
+
102
+ if (targetPlatform) {
103
+ if (targetPlatform === 'all') {
104
+ platformsToBuild = supportedPlatforms;
105
+ console.log(`构建所有支持平台: ${supportedPlatforms.join(', ')}`);
106
+ } else if (supportedPlatforms.includes(targetPlatform)) {
107
+ platformsToBuild = [targetPlatform];
108
+ console.log(`构建指定平台: ${targetPlatform}`);
109
+ } else {
110
+ console.error(`不支持的平台: ${targetPlatform}`);
111
+ console.log(`支持的平台: ${supportedPlatforms.join(', ')} 或 all`);
112
+ process.exit(1);
113
+ }
114
+ } else {
115
+ platformsToBuild = getCurrentPlatform();
116
+ console.log(`未指定平台,自动使用当前平台: ${platformsToBuild}`);
117
+ }
118
+
119
+ console.log(`输出目录: ${resolve(projectRoot, 'release')}`);
120
+
121
+ for (const platform of platformsToBuild) {
122
+ await buildPlatform(platform);
123
+ }
124
+
125
+ console.log('\n========================================');
126
+ console.log('🎉 所有平台构建完成!');
127
+ console.log('========================================');
128
+ console.log(`输出目录: ${resolve(projectRoot, 'release')}`);
129
+
130
+ } catch (error) {
131
+ console.error('构建过程中出错:', error);
132
+ process.exit(1);
133
+ }
134
+ }
135
+
136
+ build();
@@ -0,0 +1,67 @@
1
+ const { exec } = require('child_process');
2
+ const { createServer } = require('http');
3
+ const { join, resolve } = require('path');
4
+
5
+ const projectRoot = resolve(__dirname, '..');
6
+
7
+ // 启动 Vite 开发服务器
8
+ const viteProcess = exec('npm run dev', { cwd: projectRoot }, (error, stdout, stderr) => {
9
+ if (error) {
10
+ console.error(`执行 npm run dev 时出错: ${error}`);
11
+ return;
12
+ }
13
+ console.log(`stdout: ${stdout}`);
14
+ console.error(`stderr: ${stderr}`);
15
+ });
16
+
17
+ viteProcess.stdout.on('data', (data) => {
18
+ console.log(data);
19
+ // 当 Vite 服务器启动成功后,启动 NW.js
20
+ if (data.includes('ready')) {
21
+ setTimeout(() => {
22
+ console.log('starting NW.js...', 'npx nw . --url=http://localhost:9300');
23
+ const nwProcess = exec('npx nw . --url=http://localhost:9300', { cwd: projectRoot }, (error, stdout, stderr) => {
24
+ if (error) {
25
+ console.error(`启动 NW.js 时出错: ${error}`);
26
+ return;
27
+ }
28
+ console.log(`stdout: ${stdout}`);
29
+ console.error(`stderr: ${stderr}`);
30
+ });
31
+
32
+ nwProcess.stdout.on('data', (data) => {
33
+ console.log(data);
34
+ });
35
+
36
+ nwProcess.stderr.on('data', (data) => {
37
+ console.error(data);
38
+ });
39
+
40
+ nwProcess.on('close', (code) => {
41
+ console.log(`NW.js 进程退出,代码: ${code}`);
42
+ viteProcess.kill();
43
+ });
44
+
45
+ // 处理退出信号
46
+ process.on('SIGINT', () => {
47
+ nwProcess.kill();
48
+ viteProcess.kill();
49
+ process.exit();
50
+ });
51
+
52
+ process.on('SIGTERM', () => {
53
+ nwProcess.kill();
54
+ viteProcess.kill();
55
+ process.exit();
56
+ });
57
+ }, 2000);
58
+ }
59
+ });
60
+
61
+ viteProcess.stderr.on('data', (data) => {
62
+ console.error(data);
63
+ });
64
+
65
+ viteProcess.on('close', (code) => {
66
+ console.log(`Vite 进程退出,代码: ${code}`);
67
+ });
@@ -0,0 +1,112 @@
1
+ const { execSync } = require('child_process');
2
+ const path = require('path');
3
+ const fs = require('fs');
4
+ const os = require('os');
5
+
6
+ console.log('Checking for running fdb2 instances...');
7
+
8
+ try {
9
+ let pid = null;
10
+
11
+ // 检查当前目录的 PID 文件
12
+ const currentDirPidPath = path.join(process.cwd(), 'fdb2.server.pid');
13
+ if (fs.existsSync(currentDirPidPath)) {
14
+ try {
15
+ pid = parseInt(fs.readFileSync(currentDirPidPath, 'utf8'));
16
+ process.kill(pid, 0);
17
+ console.log('Found running fdb2 instance with PID:', pid);
18
+ } catch (error) {
19
+ if (error.code !== 'ESRCH') {
20
+ throw error;
21
+ }
22
+ }
23
+ }
24
+
25
+ // 如果没有找到,尝试从全局安装目录查找
26
+ if (!pid) {
27
+ try {
28
+ const globalPath = execSync('npm root -g', { encoding: 'utf8' }).trim();
29
+ const globalPidPath = path.join(globalPath, 'fdb2', 'fdb2.server.pid');
30
+
31
+ if (fs.existsSync(globalPidPath)) {
32
+ try {
33
+ pid = parseInt(fs.readFileSync(globalPidPath, 'utf8'));
34
+ process.kill(pid, 0);
35
+ console.log('Found running fdb2 instance with PID:', pid);
36
+ } catch (error) {
37
+ if (error.code !== 'ESRCH') {
38
+ throw error;
39
+ }
40
+ }
41
+ }
42
+ } catch (error) {
43
+ // 忽略全局路径查找失败
44
+ }
45
+ }
46
+
47
+ // 如果找到了运行中的进程,尝试停止它
48
+ if (pid) {
49
+ console.log('Stopping fdb2...');
50
+
51
+ try {
52
+ if (os.platform() === 'win32') {
53
+ // Windows: 使用 taskkill
54
+ execSync(`taskkill /F /PID ${pid}`, { stdio: 'inherit' });
55
+ } else {
56
+ // Unix-like: 使用 kill
57
+ process.kill(pid, 'SIGTERM');
58
+
59
+ // 等待进程结束
60
+ let attempts = 0;
61
+ while (attempts < 10) {
62
+ try {
63
+ process.kill(pid, 0);
64
+ attempts++;
65
+ // 等待 100ms
66
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 100);
67
+ } catch (error) {
68
+ if (error.code === 'ESRCH') {
69
+ // 进程已结束
70
+ break;
71
+ }
72
+ }
73
+ }
74
+
75
+ // 如果进程还在运行,强制终止
76
+ try {
77
+ process.kill(pid, 0);
78
+ process.kill(pid, 'SIGKILL');
79
+ } catch (error) {
80
+ if (error.code !== 'ESRCH') {
81
+ throw error;
82
+ }
83
+ }
84
+ }
85
+
86
+ console.log('fdb2 stopped successfully');
87
+ } catch (stopError) {
88
+ console.warn('Failed to stop fdb2:', stopError.message);
89
+ console.warn('Please manually stop the fdb2 process before installation');
90
+ }
91
+ } else {
92
+ console.log('No running fdb2 instance found');
93
+ }
94
+
95
+ // 清理 PID 文件
96
+ if (fs.existsSync(currentDirPidPath)) {
97
+ fs.unlinkSync(currentDirPidPath);
98
+ }
99
+
100
+ try {
101
+ const globalPath = execSync('npm root -g', { encoding: 'utf8' }).trim();
102
+ const globalPidPath = path.join(globalPath, 'fdb2', 'fdb2.server.pid');
103
+ if (fs.existsSync(globalPidPath)) {
104
+ fs.unlinkSync(globalPidPath);
105
+ }
106
+ } catch (error) {
107
+ // 忽略全局路径清理失败
108
+ }
109
+
110
+ } catch (error) {
111
+ console.warn('Pre-install check failed:', error.message);
112
+ }