Files
makemd/check-services.js

50 lines
1.9 KiB
JavaScript
Raw Normal View History

const fs = require('fs');
const path = require('path');
// 读取serviceConfig.ts文件
const serviceConfigPath = path.join(__dirname, 'server/src/config/serviceConfig.ts');
const serviceConfigContent = fs.readFileSync(serviceConfigPath, 'utf8');
// 读取DomainBootstrap.ts文件
const domainBootstrapPath = path.join(__dirname, 'server/src/core/runtime/DomainBootstrap.ts');
const domainBootstrapContent = fs.readFileSync(domainBootstrapPath, 'utf8');
// 从serviceConfig.ts中提取服务名称
const serviceNameRegex = /name: '([^']+)'/g;
const serviceConfigs = [];
let match;
while ((match = serviceNameRegex.exec(serviceConfigContent)) !== null) {
serviceConfigs.push(match[1]);
}
// 从DomainBootstrap.ts中提取注册的服务名称
const registeredServiceRegex = /name: '([^']+)'/g;
const registeredServices = [];
let registeredMatch;
while ((registeredMatch = registeredServiceRegex.exec(domainBootstrapContent)) !== null) {
registeredServices.push(registeredMatch[1]);
}
// 找出未注册的服务
const unregisteredServices = serviceConfigs.filter(service => !registeredServices.includes(service));
// 找出多余注册的服务在DomainBootstrap中注册但不在serviceConfig中定义的服务
const extraRegisteredServices = registeredServices.filter(service => !serviceConfigs.includes(service));
// 输出结果
console.log('=== 服务注册一致性检查 ===');
console.log(`ServiceConfig中定义的服务数量: ${serviceConfigs.length}`);
console.log(`DomainBootstrap中注册的服务数量: ${registeredServices.length}`);
console.log('\n=== 未注册的服务 ===');
if (unregisteredServices.length > 0) {
console.log(unregisteredServices.join('\n'));
} else {
console.log('所有服务都已注册');
}
console.log('\n=== 多余注册的服务 ===');
if (extraRegisteredServices.length > 0) {
console.log(extraRegisteredServices.join('\n'));
} else {
console.log('没有多余注册的服务');
}