120 lines
4.2 KiB
JavaScript
120 lines
4.2 KiB
JavaScript
const fs = require('fs');
|
|
const content = fs.readFileSync('final-backend.js', 'utf8');
|
|
const lines = content.split('\n');
|
|
|
|
const routes = [];
|
|
for (let i = 0; i < lines.length; i++) {
|
|
const line = lines[i];
|
|
const match = line.match(/app\.(get|post|put|delete|patch)\(['\"](\/api\/[^'\"]+)['\"]/);
|
|
if (match) {
|
|
routes.push({
|
|
method: match[1],
|
|
path: match[2],
|
|
line: i + 1
|
|
});
|
|
}
|
|
}
|
|
|
|
// 按模块分组
|
|
const modules = {};
|
|
routes.forEach(route => {
|
|
const pathParts = route.path.split('/');
|
|
let moduleName = 'other';
|
|
|
|
if (route.path.startsWith('/api/auth')) {
|
|
moduleName = 'auth';
|
|
} else if (route.path.startsWith('/api/users')) {
|
|
moduleName = 'users';
|
|
} else if (route.path.startsWith('/api/customers')) {
|
|
moduleName = 'customers';
|
|
} else if (route.path.startsWith('/api/suppliers')) {
|
|
moduleName = 'suppliers';
|
|
} else if (route.path.startsWith('/api/subcontractors')) {
|
|
moduleName = 'subcontractors';
|
|
} else if (route.path.startsWith('/api/projects')) {
|
|
moduleName = 'projects';
|
|
} else if (route.path.startsWith('/api/products')) {
|
|
moduleName = 'products';
|
|
} else if (route.path.startsWith('/api/categories')) {
|
|
moduleName = 'categories';
|
|
} else if (route.path.startsWith('/api/budget-projects')) {
|
|
moduleName = 'budget-projects';
|
|
} else if (route.path.startsWith('/api/exchange-rates')) {
|
|
moduleName = 'exchange-rates';
|
|
} else if (route.path.startsWith('/api/advances')) {
|
|
moduleName = 'advances';
|
|
} else if (route.path.startsWith('/api/payment-requests')) {
|
|
moduleName = 'payment-requests';
|
|
} else if (route.path.startsWith('/api/verifications')) {
|
|
moduleName = 'verifications';
|
|
} else if (route.path.startsWith('/api/executions')) {
|
|
moduleName = 'executions';
|
|
} else if (route.path.startsWith('/api/reimbursements')) {
|
|
moduleName = 'reimbursements';
|
|
} else if (route.path.startsWith('/api/purchase-requests')) {
|
|
moduleName = 'purchase-requests';
|
|
} else if (route.path.startsWith('/api/purchase-orders')) {
|
|
moduleName = 'purchase-orders';
|
|
} else if (route.path.startsWith('/api/payment-plans')) {
|
|
moduleName = 'payment-plans';
|
|
} else if (route.path.startsWith('/api/inventory')) {
|
|
moduleName = 'inventory';
|
|
} else if (route.path.startsWith('/api/upload')) {
|
|
moduleName = 'upload';
|
|
} else if (route.path === '/api/health' || route.path === '/status' || route.path === '/welcome' || route.path === '/' || route.path === '/api-docs') {
|
|
moduleName = 'system';
|
|
}
|
|
|
|
if (!modules[moduleName]) {
|
|
modules[moduleName] = [];
|
|
}
|
|
modules[moduleName].push(route);
|
|
}
|
|
|
|
// 计算每个模块的起始行和结束行
|
|
const moduleStats = {};
|
|
for (const [moduleName, moduleRoutes] of Object.entries(modules)) {
|
|
const lineNumbers = moduleRoutes.map(r => r.line);
|
|
const startLine = Math.min(...lineNumbers);
|
|
const endLine = Math.max(...lineNumbers);
|
|
|
|
// 查找模块的实际结束行(找到下一个模块的开始)
|
|
let actualEndLine = endLine;
|
|
for (let i = endLine; i < lines.length; i++) {
|
|
const nextLine = lines[i];
|
|
if (nextLine.includes('app.') && nextLine.includes('/api/')) {
|
|
const nextPath = nextLine.match(/['\"](\/api\/[^'\"]+)['\"]/);
|
|
if (nextPath) {
|
|
const nextModule = nextPath[1].split('/')[2];
|
|
if (nextModule !== moduleName) {
|
|
actualEndLine = i;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
moduleStats[moduleName] = {
|
|
pathPrefix: '/api/' + (moduleName === 'system' ? '' : moduleName),
|
|
routeCount: moduleRoutes.length,
|
|
startLine: startLine,
|
|
endLine: actualEndLine,
|
|
routes: moduleRoutes
|
|
};
|
|
}
|
|
|
|
// 输出表格
|
|
console.log('模块名 | 路径前缀 | 路由数量 | 起始行-结束行');
|
|
console.log('------|----------|----------|--------------');
|
|
for (const [moduleName, stats] of Object.entries(moduleStats)) {
|
|
console.log(`${moduleName} | ${stats.pathPrefix} | ${stats.routeCount} | ${stats.startLine}-${stats.endLine}`);
|
|
}
|
|
|
|
// 输出详细路由信息
|
|
console.log('\n详细路由信息:');
|
|
for (const [moduleName, stats] of Object.entries(moduleStats)) {
|
|
console.log(`\n${moduleName} 模块 (${stats.routeCount} 个路由):`);
|
|
stats.routes.forEach(route => {
|
|
console.log(` ${route.method.toUpperCase()} ${route.path} (第${route.line}行)`);
|
|
});
|
|
} |