增加其他平台的打包指令
This commit is contained in:
@@ -20,6 +20,8 @@ config.json
|
||||
#打包文件夹
|
||||
dist/
|
||||
pixiv-manager-portable/
|
||||
pixiv-manager-portable-linux/
|
||||
pixiv-manager-portable-macos/
|
||||
pixiv-manager-portable.rar
|
||||
build/
|
||||
zzip.bat
|
||||
|
||||
+19
-7
@@ -212,7 +212,7 @@ class PixivServer {
|
||||
*/
|
||||
start() {
|
||||
this.server = this.app.listen(this.port, () => {
|
||||
logger.info('Pixiv 后端服务器已启动');
|
||||
logger.info('Pixiv 后端服务器已启动2');
|
||||
logger.info(`服务地址: http://localhost:${this.port}`);
|
||||
logger.info(`健康检查: http://localhost:${this.port}/health`);
|
||||
logger.info(`登录状态: ${this.backend.isLoggedIn ? '已登录' : '未登录'}`);
|
||||
@@ -242,11 +242,20 @@ class PixivServer {
|
||||
|
||||
const { spawn } = require('child_process');
|
||||
const os = require('os');
|
||||
const fs = require('fs');
|
||||
const platform = os.platform();
|
||||
|
||||
// 在服务器环境中直接跳过打开浏览器
|
||||
if (platform === 'linux') {
|
||||
// 直接跳过 Linux 服务器环境的浏览器打开
|
||||
logger.info('在 Linux 服务器环境中,跳过打开浏览器');
|
||||
return;
|
||||
}
|
||||
|
||||
let command;
|
||||
let args = [url];
|
||||
|
||||
switch (os.platform()) {
|
||||
switch (platform) {
|
||||
case 'win32':
|
||||
command = 'cmd';
|
||||
args = ['/c', 'start', '""', url];
|
||||
@@ -254,9 +263,6 @@ class PixivServer {
|
||||
case 'darwin':
|
||||
command = 'open';
|
||||
break;
|
||||
case 'linux':
|
||||
command = 'xdg-open';
|
||||
break;
|
||||
default:
|
||||
logger.warn('不支持的操作系统,无法自动打开浏览器');
|
||||
return;
|
||||
@@ -265,10 +271,16 @@ class PixivServer {
|
||||
try {
|
||||
const child = spawn(command, args, {
|
||||
detached: true,
|
||||
stdio: 'ignore'
|
||||
stdio: 'ignore',
|
||||
});
|
||||
|
||||
// 添加错误处理
|
||||
child.on('error', (err) => {
|
||||
logger.warn('打开浏览器失败:', err.message);
|
||||
});
|
||||
|
||||
child.unref();
|
||||
logger.info('浏览器已打开');
|
||||
logger.info('浏览器打开命令已执行');
|
||||
} catch (error) {
|
||||
logger.warn('打开浏览器失败:', error.message);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,12 @@
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
|
||||
// 只在 Windows 环境下设置终端标题
|
||||
if (os.platform() === 'win32') {
|
||||
process.title = 'Pixiv Manager';
|
||||
}
|
||||
|
||||
// 加载配置文件
|
||||
function loadConfig() {
|
||||
|
||||
+5
-1
@@ -17,7 +17,11 @@
|
||||
"scripts": {
|
||||
"dev": "node backend/start.js",
|
||||
"build": "pkg . && node scripts/add-icon.js",
|
||||
"bp": "npm run build && node scripts/create-portable.js"
|
||||
"bp": "npm run build && node scripts/create-portable.js",
|
||||
"build:linux": "pkg . --targets=node18-linux-x64 --output=dist/pixiv-manager",
|
||||
"build:macos": "pkg . --targets=node18-macos-x64 --output=dist/pixiv-manager",
|
||||
"bp:linux": "npm run build:linux && node scripts/create-portable.js linux",
|
||||
"bp:macos": "npm run build:macos && node scripts/create-portable.js macos"
|
||||
},
|
||||
"dependencies": {
|
||||
"adm-zip": "^0.5.16",
|
||||
|
||||
@@ -5,9 +5,24 @@ const { defaultLogger } = require('../backend/utils/logger');
|
||||
// 创建logger实例
|
||||
const logger = defaultLogger.child('CreatePortable');
|
||||
|
||||
async function createPortable() {
|
||||
async function createPortable(platform = 'win') {
|
||||
const distDir = path.join(__dirname, '..', 'dist');
|
||||
const portableDir = path.join(__dirname, '..', 'pixiv-manager-portable');
|
||||
let portableDir = path.join(__dirname, '..', 'pixiv-manager-portable');
|
||||
|
||||
// 根据平台设置不同的目录名和可执行文件名
|
||||
let exeName = 'pixiv-manager.exe';
|
||||
let exePath = path.join(distDir, exeName);
|
||||
|
||||
// 根据平台参数设置
|
||||
if (platform === 'linux') {
|
||||
portableDir = path.join(__dirname, '..', 'pixiv-manager-portable-linux');
|
||||
exeName = 'pixiv-manager';
|
||||
exePath = path.join(distDir, exeName);
|
||||
} else if (platform === 'macos') {
|
||||
portableDir = path.join(__dirname, '..', 'pixiv-manager-portable-macos');
|
||||
exeName = 'pixiv-manager';
|
||||
exePath = path.join(distDir, exeName);
|
||||
}
|
||||
|
||||
try {
|
||||
// 清理之前的便携版
|
||||
@@ -15,8 +30,6 @@ async function createPortable() {
|
||||
await fs.ensureDir(portableDir);
|
||||
|
||||
// 复制可执行文件
|
||||
const exeName = 'pixiv-manager.exe';
|
||||
const exePath = path.join(distDir, exeName);
|
||||
if (await fs.pathExists(exePath)) {
|
||||
await fs.copy(exePath, path.join(portableDir, exeName));
|
||||
}
|
||||
@@ -42,13 +55,24 @@ async function createPortable() {
|
||||
await fs.writeFile(path.join(portableDir, 'config.json'), JSON.stringify(config, null, 2), 'utf8');
|
||||
|
||||
// 创建README
|
||||
let executableInstructions = '';
|
||||
if (platform === 'linux') {
|
||||
executableInstructions = `1. 添加执行权限: \`chmod +x pixiv-manager-linux\`
|
||||
2. 运行程序: \`./pixiv-manager-linux\``;
|
||||
} else if (platform === 'macos') {
|
||||
executableInstructions = `1. 添加执行权限: \`chmod +x pixiv-manager-macos\`
|
||||
2. 运行程序: \`./pixiv-manager-macos\``;
|
||||
} else {
|
||||
executableInstructions = `1. 双击 \`pixiv-manager.exe\` 启动程序`;
|
||||
}
|
||||
|
||||
const readme = `# Pixiv Manager 便携版
|
||||
|
||||
## 使用说明
|
||||
|
||||
1. 双击 \`pixiv-manager.exe\` 启动程序
|
||||
2. 在浏览器中访问 http://localhost:3000
|
||||
3. 按 Ctrl+C 停止服务器
|
||||
${executableInstructions}
|
||||
${platform === 'win' ? '' : '3. '}在浏览器中访问 http://localhost:3000
|
||||
${platform === 'win' ? '3' : '4'}. 按 Ctrl+C 停止服务器
|
||||
|
||||
## 配置设置
|
||||
|
||||
@@ -139,4 +163,6 @@ async function createPortable() {
|
||||
}
|
||||
}
|
||||
|
||||
createPortable();
|
||||
// 获取命令行参数
|
||||
const platform = process.argv[2] || 'win';
|
||||
createPortable(platform);
|
||||
Reference in New Issue
Block a user