feat(api): generate and update API client modules
Add new API client modules for various endpoints including authentication, orders, events, and configuration management. Update existing modules to use the standardized request utility. Add post-generation script to restore request.ts after openapi-ts generation to prevent file deletion issues. The API client generation now includes comprehensive TypeScript types and proper request handling for all endpoints. The request utility has been enhanced to handle query parameters and response parsing consistently across all API calls.
This commit is contained in:
36
scripts/restore-api-request.mjs
Normal file
36
scripts/restore-api-request.mjs
Normal file
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* 在 openapi-ts 生成后恢复 request.ts 文件
|
||||
* 解决 openapi-ts-request 的 full 模式会删除整个 serversPath 目录的问题
|
||||
*/
|
||||
|
||||
import { copyFileSync, existsSync, mkdirSync } from 'fs';
|
||||
import { dirname, resolve } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const rootDir = resolve(__dirname, '..');
|
||||
|
||||
const templatePath = resolve(rootDir, 'src/utils/api-request.ts');
|
||||
const targetPath = resolve(rootDir, 'src/api/request.ts');
|
||||
|
||||
console.log('🔄 Restoring request.ts after openapi generation...');
|
||||
|
||||
// 确保目标目录存在
|
||||
const targetDir = dirname(targetPath);
|
||||
if (!existsSync(targetDir)) {
|
||||
mkdirSync(targetDir, { recursive: true });
|
||||
console.log('📁 Created directory:', targetDir);
|
||||
}
|
||||
|
||||
// 复制模板文件
|
||||
if (existsSync(templatePath)) {
|
||||
copyFileSync(templatePath, targetPath);
|
||||
console.log('✅ Restored:', targetPath);
|
||||
} else {
|
||||
console.error('❌ Template not found:', templatePath);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log('🎉 Request file restoration complete!');
|
||||
Reference in New Issue
Block a user