refacor: 重构目录架构

This commit is contained in:
2026-09-16 22:43:21 +08:00
parent b37cdb0d54
commit 2754ed1e45
2762 changed files with 0 additions and 1529 deletions
+49
View File
@@ -0,0 +1,49 @@
import { execSync } from 'child_process';
import { cpSync, existsSync, readdirSync } from 'fs';
import { tmpdir } from 'os';
import { join } from 'path';
/** 本地临时目录(跨平台,替代 /tmp) */
export function getLocalTempPath(name: string): string {
return join(tmpdir(), name);
}
/** 解析 Maven 命令:Windows 用 mvnw.cmd,Unix 用 mvnw */
export function resolveMavenCommand(projectDir: string): string {
if (process.platform === 'win32') {
const mvnwCmd = join(projectDir, 'mvnw.cmd');
if (existsSync(mvnwCmd)) return `"${mvnwCmd}"`;
} else {
const mvnw = join(projectDir, 'mvnw');
if (existsSync(mvnw)) return `"${mvnw}"`;
}
return 'mvn';
}
/** 在 target 目录查找主 JAR(排除 *-original.jar) */
export function findMainJar(targetDir: string): string {
const jars = readdirSync(targetDir).filter(
(f) => f.endsWith('.jar') && !f.endsWith('-original.jar'),
);
if (jars.length === 0) throw new Error(`未找到 JAR 文件: ${targetDir}`);
return join(targetDir, jars[0]);
}
/** 将目录打包为 tar.gz(Windows 10+ / Linux / macOS 均内置 tar) */
export function createTarGz(sourceDir: string, destPath: string): void {
try {
execSync(`tar -czf "${destPath}" -C "${sourceDir}" .`, { stdio: 'pipe' });
} catch (e: unknown) {
const msg = e instanceof Error ? e.message : String(e);
throw new Error(`打包失败 (${sourceDir}): ${msg}`);
}
}
/** 递归复制目录/文件到临时构建目录 */
export function copyBuildArtifacts(src: string, dest: string, opts?: { optional?: boolean }): void {
if (!existsSync(src)) {
if (opts?.optional) return;
throw new Error(`源路径不存在: ${src}`);
}
cpSync(src, dest, { recursive: true });
}