add: 添加前端对焦交互逻辑
This commit is contained in:
@@ -4,6 +4,19 @@ import fetch from 'node-fetch';
|
||||
|
||||
const execAsync = promisify(exec);
|
||||
|
||||
// Windows 支持函数
|
||||
function getCommand(command: string): string {
|
||||
// dotnet 在 Windows 上不需要 .cmd 后缀
|
||||
if (command === 'dotnet') {
|
||||
return 'dotnet';
|
||||
}
|
||||
return process.platform === 'win32' ? `${command}.cmd` : command;
|
||||
}
|
||||
|
||||
function getSpawnOptions() {
|
||||
return process.platform === 'win32' ? { stdio: 'pipe', shell: true } : { stdio: 'pipe' };
|
||||
}
|
||||
|
||||
async function waitForServer(url: string, maxRetries: number = 30, interval: number = 1000): Promise<boolean> {
|
||||
for (let i = 0; i < maxRetries; i++) {
|
||||
try {
|
||||
@@ -28,9 +41,7 @@ let webProcess: ChildProcess | null = null;
|
||||
async function startWeb(): Promise<ChildProcess> {
|
||||
console.log('Starting Vite frontend...');
|
||||
return new Promise((resolve, reject) => {
|
||||
const process = spawn('npm', ['run', 'dev'], {
|
||||
stdio: 'pipe'
|
||||
});
|
||||
const process = spawn(getCommand('npm'), ['run', 'dev'], getSpawnOptions() as any);
|
||||
|
||||
let webStarted = false;
|
||||
|
||||
@@ -75,10 +86,10 @@ async function startWeb(): Promise<ChildProcess> {
|
||||
async function startServer(): Promise<ChildProcess> {
|
||||
console.log('Starting .NET server...');
|
||||
return new Promise((resolve, reject) => {
|
||||
const process = spawn('dotnet', ['run', '--property:Configuration=Release'], {
|
||||
const process = spawn(getCommand('dotnet'), ['run', '--property:Configuration=Release'], {
|
||||
cwd: 'server',
|
||||
stdio: 'pipe'
|
||||
});
|
||||
...getSpawnOptions()
|
||||
} as any);
|
||||
|
||||
let serverStarted = false;
|
||||
|
||||
@@ -175,7 +186,12 @@ async function stopServer(): Promise<void> {
|
||||
|
||||
// 额外清理:确保没有遗留的 dotnet 进程
|
||||
try {
|
||||
if (process.platform !== 'win32') {
|
||||
if (process.platform === 'win32') {
|
||||
// Windows: 使用 taskkill 清理进程
|
||||
await execAsync('taskkill /F /IM dotnet.exe').catch(() => {
|
||||
// 忽略错误,可能没有匹配的进程
|
||||
});
|
||||
} else {
|
||||
// 只清理与我们项目相关的进程
|
||||
await execAsync('pkill -f "dotnet.*run.*--property:Configuration=Release"').catch(() => {
|
||||
// 忽略错误,可能没有匹配的进程
|
||||
@@ -242,7 +258,12 @@ async function stopWeb(): Promise<void> {
|
||||
|
||||
// 额外清理:确保没有遗留的 npm/node 进程
|
||||
try {
|
||||
if (process.platform !== 'win32') {
|
||||
if (process.platform === 'win32') {
|
||||
// Windows: 清理可能的 node 进程
|
||||
await execAsync('taskkill /F /IM node.exe').catch(() => {
|
||||
// 忽略错误,可能没有匹配的进程
|
||||
});
|
||||
} else {
|
||||
// 清理可能的 vite 进程
|
||||
await execAsync('pkill -f "vite"').catch(() => {
|
||||
// 忽略错误,可能没有匹配的进程
|
||||
@@ -257,7 +278,8 @@ async function stopWeb(): Promise<void> {
|
||||
async function generateApiClient(): Promise<void> {
|
||||
console.log('Generating API client...');
|
||||
try {
|
||||
await execAsync('npx nswag openapi2tsclient /input:http://localhost:5000/swagger/v1/swagger.json /output:src/APIClient.ts');
|
||||
const npxCommand = getCommand('npx');
|
||||
await execAsync(`${npxCommand} nswag openapi2tsclient /input:http://localhost:5000/swagger/v1/swagger.json /output:src/APIClient.ts`);
|
||||
console.log('✓ API client generated successfully');
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to generate API client: ${error}`);
|
||||
|
Reference in New Issue
Block a user