生产管理系统 - 页面布局调整
This commit is contained in:
@@ -9,6 +9,44 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// 从环境配置文件中读取 API_BASE_URL
|
||||
function getApiBaseUrl() {
|
||||
try {
|
||||
// 首先尝试从 env/.env.dev 文件读取
|
||||
const envDevPath = path.join(process.cwd(), 'env', '.env.dev');
|
||||
if (fs.existsSync(envDevPath)) {
|
||||
const envContent = fs.readFileSync(envDevPath, 'utf8');
|
||||
const apiBaseUrlMatch = envContent.match(/API_BASE_URL=([^\r\n]+)/);
|
||||
|
||||
if (apiBaseUrlMatch && apiBaseUrlMatch[1]) {
|
||||
return apiBaseUrlMatch[1].trim();
|
||||
}
|
||||
}
|
||||
|
||||
// 如果上面的文件不存在,尝试从 TypeScript 环境配置文件读取
|
||||
const envConfigPath = path.join(process.cwd(), 'src', 'env', 'index.ts');
|
||||
if (fs.existsSync(envConfigPath)) {
|
||||
const envContent = fs.readFileSync(envConfigPath, 'utf8');
|
||||
const devConfigMatch = envContent.match(/dev:\s*\{[\s\S]*?BACKEND_BASE_URL:\s*['"`]([^'"`]+)['"`]/);
|
||||
|
||||
if (devConfigMatch && devConfigMatch[1]) {
|
||||
return devConfigMatch[1].trim();
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error('无法找到 API_BASE_URL 或 BACKEND_BASE_URL 配置');
|
||||
} catch (error) {
|
||||
console.log(`读取环境配置失败: ${error.message}`);
|
||||
return 'http://localhost:8080'; // 默认值
|
||||
}
|
||||
}
|
||||
|
||||
// 获取 API 基础 URL
|
||||
const API_BASE_URL = getApiBaseUrl();
|
||||
|
||||
// 设置环境变量供后续使用
|
||||
process.env.API_BASE_URL = API_BASE_URL;
|
||||
|
||||
// ANSI 颜色代码
|
||||
const colors = {
|
||||
reset: '\x1b[0m',
|
||||
@@ -44,7 +82,8 @@ function logInfo(message) {
|
||||
|
||||
// 显示环境配置信息
|
||||
logInfo(`当前环境: ${process.env.NODE_ENV || 'development'}`);
|
||||
logInfo(`API 服务器: ${process.env.API_BASE_URL || 'http://localhost:8080'}`);
|
||||
logInfo(`API 服务器: ${API_BASE_URL}`);
|
||||
logInfo(`已从 env/.env.dev 读取 API_BASE_URL 配置`);
|
||||
|
||||
/**
|
||||
* 检查自定义文件是否存在
|
||||
@@ -153,6 +192,59 @@ function restoreCustomFiles(customFiles) {
|
||||
logSuccess('自定义文件已恢复');
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载并保存 openapi.json 文件到本地
|
||||
*/
|
||||
function downloadOpenApiJson() {
|
||||
return new Promise((resolve, reject) => {
|
||||
const https = require('https');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const fileUrl = `${API_BASE_URL}/openapi.json`;
|
||||
const outputPath = path.join(process.cwd(), 'scripts', 'openapi.json');
|
||||
|
||||
logInfo(`下载 OpenAPI 规范文件: ${fileUrl}`);
|
||||
|
||||
const startTime = Date.now();
|
||||
|
||||
// 创建 HTTPS 代理(如果需要,可以忽略 SSL 证书验证)
|
||||
const agent = new https.Agent({
|
||||
rejectUnauthorized: false // 跳过 SSL 证书验证
|
||||
});
|
||||
|
||||
https.get(fileUrl, { agent }, (response) => {
|
||||
if (response.statusCode !== 200) {
|
||||
reject(new Error(`HTTP ${response.statusCode}: ${response.statusMessage}`));
|
||||
return;
|
||||
}
|
||||
|
||||
let data = '';
|
||||
|
||||
response.on('data', (chunk) => {
|
||||
data += chunk;
|
||||
});
|
||||
|
||||
response.on('end', () => {
|
||||
try {
|
||||
// 验证 JSON 格式
|
||||
JSON.parse(data);
|
||||
|
||||
// 写入文件
|
||||
fs.writeFileSync(outputPath, data, 'utf8');
|
||||
const executionTime = Date.now() - startTime;
|
||||
logSuccess(`OpenAPI 规范已保存到: scripts/openapi.json (${executionTime}ms)`);
|
||||
resolve();
|
||||
} catch (error) {
|
||||
reject(new Error(`JSON 格式错误: ${error.message}`));
|
||||
}
|
||||
});
|
||||
}).on('error', (error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用 openapi-ts 命令生成客户端代码
|
||||
*/
|
||||
@@ -259,6 +351,9 @@ async function main() {
|
||||
backupCustomFiles(customFiles);
|
||||
}
|
||||
|
||||
// 下载 openapi.json 文件到本地
|
||||
await downloadOpenApiJson();
|
||||
|
||||
// 使用 openapi-ts 生成代码
|
||||
await generateWithOpenApiTS();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user