mirror of
https://github.com/crystelf/crystelf-core.git
synced 2025-07-04 06:39:18 +00:00
优化初始化流程
自动安装依赖&自动构建
This commit is contained in:
parent
0ea93bb670
commit
c024051db8
@ -17,7 +17,7 @@ class FileService {
|
||||
}
|
||||
|
||||
const filePath = path.join(this.filePath, relativePath);
|
||||
logger.debug(`尝试访问图像路径: ${filePath}`);
|
||||
logger.debug(`尝试访问文件路径: ${filePath}`);
|
||||
|
||||
return fs.existsSync(filePath) ? filePath : null;
|
||||
}
|
||||
|
@ -1,6 +1,11 @@
|
||||
import simpleGit, { SimpleGit } from 'simple-git';
|
||||
import paths from './path';
|
||||
import logger from './logger';
|
||||
import { exec } from 'child_process';
|
||||
import { promisify } from 'util';
|
||||
import fs from 'fs';
|
||||
|
||||
const execAsync = promisify(exec);
|
||||
|
||||
class AutoUpdater {
|
||||
private git: SimpleGit;
|
||||
@ -41,7 +46,10 @@ class AutoUpdater {
|
||||
return false;
|
||||
}
|
||||
|
||||
logger.info('更新成功!');
|
||||
logger.info('代码更新成功,开始更新依赖..');
|
||||
await this.updateDependencies();
|
||||
|
||||
logger.info('自动更新流程完成。');
|
||||
return true;
|
||||
} else {
|
||||
logger.info('远程仓库没有新变化..');
|
||||
@ -52,6 +60,30 @@ class AutoUpdater {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动更新依赖和构建
|
||||
*/
|
||||
private async updateDependencies(): Promise<void> {
|
||||
try {
|
||||
logger.info('执行 pnpm install...');
|
||||
await execAsync('pnpm install', { cwd: this.repoPath });
|
||||
logger.info('依赖安装完成。');
|
||||
|
||||
const pkgPath = paths.get('package');
|
||||
const pkgJson = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
||||
|
||||
if (pkgJson.scripts?.build) {
|
||||
logger.info('检测到 build 脚本,执行 pnpm build...');
|
||||
await execAsync('pnpm build', { cwd: this.repoPath });
|
||||
logger.info('构建完成。');
|
||||
} else {
|
||||
logger.info('未检测到 build 脚本,跳过构建。');
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error('更新依赖或构建失败: ', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const autoUpdater = new AutoUpdater();
|
||||
|
@ -35,6 +35,7 @@ class PathManager {
|
||||
userData: path.join(this.baseDir, 'private/data'),
|
||||
files: path.join(this.baseDir, 'public/files'),
|
||||
media: path.join(this.baseDir, 'public/files/media'),
|
||||
package: path.join(this.baseDir, 'package.json'),
|
||||
};
|
||||
|
||||
return type ? mappings[type] : this.baseDir;
|
||||
@ -81,6 +82,7 @@ type PathType =
|
||||
| 'temp'
|
||||
| 'userData'
|
||||
| 'files'
|
||||
| 'package'
|
||||
| 'media';
|
||||
|
||||
const paths = PathManager.getInstance();
|
||||
|
Loading…
x
Reference in New Issue
Block a user