C端改造
This commit is contained in:
@@ -88,15 +88,15 @@ class ConfigGenerator {
|
||||
console.log('[ConfigGenerator] Data path:', this.dataPath);
|
||||
console.log('[ConfigGenerator] MySQL port:', options.mysqlPort || 3306);
|
||||
console.log('[ConfigGenerator] MySQL password:', options.mysqlPassword || 'njcnpqs');
|
||||
console.log('[ConfigGenerator] Java port:', options.javaPort || 18092);
|
||||
console.log('[ConfigGenerator] WebSocket port:', options.websocketPort || 7777);
|
||||
|
||||
console.log('[ConfigGenerator] Java port:', options.javaPort || 18093);
|
||||
console.log('[ConfigGenerator] WebSocket port:', options.websocketPort || 7778);
|
||||
|
||||
resolve({
|
||||
configPath: this.configPath,
|
||||
dataPath: this.dataPath,
|
||||
mysqlPort: options.mysqlPort || 3306,
|
||||
javaPort: options.javaPort || 18092,
|
||||
websocketPort: options.websocketPort || 7777
|
||||
javaPort: options.javaPort || 18093,
|
||||
websocketPort: options.websocketPort || 7778
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('[ConfigGenerator] Failed to generate config:', error);
|
||||
@@ -123,6 +123,75 @@ class ConfigGenerator {
|
||||
console.log('[ConfigGenerator] Created directory:', dir);
|
||||
}
|
||||
});
|
||||
|
||||
// 复制内置的报告模板文件
|
||||
this.copyBuiltInTemplates();
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制内置的报告模板文件到用户数据目录
|
||||
*/
|
||||
copyBuiltInTemplates() {
|
||||
try {
|
||||
const isDev = !process.resourcesPath;
|
||||
const baseDir = isDev
|
||||
? path.join(__dirname, '..')
|
||||
: path.dirname(process.resourcesPath);
|
||||
|
||||
// 内置模板源路径
|
||||
const templateSource = isDev
|
||||
? path.join(baseDir, 'build', 'extraResources', 'templates')
|
||||
: path.join(process.resourcesPath, 'extraResources', 'templates');
|
||||
|
||||
// 目标路径:用户数据目录/template/
|
||||
const templateDest = path.join(this.dataPath, 'template');
|
||||
|
||||
// 检查源模板是否存在
|
||||
if (!fs.existsSync(templateSource)) {
|
||||
console.log('[ConfigGenerator] Built-in templates not found, skipping copy');
|
||||
return;
|
||||
}
|
||||
|
||||
// 递归复制模板文件(只复制不存在的文件,不覆盖已有文件)
|
||||
this.copyTemplatesRecursive(templateSource, templateDest);
|
||||
|
||||
console.log('[ConfigGenerator] Built-in templates copied successfully');
|
||||
} catch (error) {
|
||||
console.error('[ConfigGenerator] Failed to copy templates:', error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归复制模板文件(不覆盖已存在的文件)
|
||||
* @param {string} src 源目录
|
||||
* @param {string} dest 目标目录
|
||||
*/
|
||||
copyTemplatesRecursive(src, dest) {
|
||||
// 确保目标目录存在
|
||||
if (!fs.existsSync(dest)) {
|
||||
fs.mkdirSync(dest, { recursive: true });
|
||||
}
|
||||
|
||||
// 读取源目录内容
|
||||
const entries = fs.readdirSync(src, { withFileTypes: true });
|
||||
|
||||
entries.forEach(entry => {
|
||||
const srcPath = path.join(src, entry.name);
|
||||
const destPath = path.join(dest, entry.name);
|
||||
|
||||
if (entry.isDirectory()) {
|
||||
// 递归复制子目录
|
||||
this.copyTemplatesRecursive(srcPath, destPath);
|
||||
} else {
|
||||
// 只复制不存在的文件(不覆盖用户修改过的文件)
|
||||
if (!fs.existsSync(destPath)) {
|
||||
fs.copyFileSync(srcPath, destPath);
|
||||
console.log('[ConfigGenerator] Copied template:', destPath);
|
||||
} else {
|
||||
console.log('[ConfigGenerator] Template already exists, skipping:', destPath);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -166,11 +166,20 @@ class JavaRunner {
|
||||
'-Dfile.encoding=UTF-8', // 设置文件编码为UTF-8,解决中文乱码
|
||||
'-Duser.language=zh', // 设置语言为中文
|
||||
'-Duser.region=CN', // 设置地区为中国
|
||||
'-jar',
|
||||
jarPath,
|
||||
`--spring.config.location=${configPath}`
|
||||
];
|
||||
|
||||
// 如果提供了 logPath,通过 JVM 系统属性传递给 logback
|
||||
if (options.logPath) {
|
||||
// Windows 路径使用正斜杠或保持原样,JVM 会自动处理
|
||||
// 方案1:转换为正斜杠(跨平台兼容)
|
||||
const normalizedLogPath = options.logPath.replace(/\\/g, '/');
|
||||
javaArgs.push(`-DlogHomeDir=${normalizedLogPath}`);
|
||||
console.log('[Java] Setting log path to:', normalizedLogPath);
|
||||
console.log('[Java] Original log path:', options.logPath);
|
||||
}
|
||||
|
||||
javaArgs.push('-jar', jarPath, `--spring.config.location=${configPath}`);
|
||||
|
||||
const defaultOptions = {
|
||||
cwd: path.dirname(jarPath),
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
|
||||
@@ -300,6 +300,7 @@ default-character-set=utf8mb4
|
||||
// 如果还没退出,强制杀死
|
||||
this.log('warn', '优雅关闭超时,强制终止...');
|
||||
this.mysqlProcess.kill('SIGTERM');
|
||||
await this.sleep(1000);
|
||||
}
|
||||
|
||||
this.log('success', 'MySQL 进程已关闭');
|
||||
@@ -309,16 +310,30 @@ default-character-set=utf8mb4
|
||||
|
||||
if (this.mysqlProcess) {
|
||||
this.mysqlProcess.kill('SIGTERM');
|
||||
await this.sleep(1000);
|
||||
}
|
||||
|
||||
// 确保进程被杀死
|
||||
try {
|
||||
await this.execCommand('taskkill /F /IM mysqld.exe');
|
||||
await this.sleep(2000); // 等待文件句柄释放
|
||||
} catch (e) {
|
||||
// 忽略
|
||||
}
|
||||
}
|
||||
|
||||
// 最终检查:确保所有 mysqld.exe 进程都被终止
|
||||
try {
|
||||
const { stdout } = await this.execCommand('tasklist /FI "IMAGENAME eq mysqld.exe" /FO CSV /NH');
|
||||
if (stdout.includes('mysqld.exe')) {
|
||||
this.log('warn', '检测到残留进程,强制清理...');
|
||||
await this.execCommand('taskkill /F /IM mysqld.exe');
|
||||
await this.sleep(2000); // 额外等待以确保文件句柄释放
|
||||
}
|
||||
} catch (e) {
|
||||
// 忽略
|
||||
}
|
||||
|
||||
this.mysqlProcess = null;
|
||||
this.currentPort = null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user