添加 Kafka 消费者、数据库写入、Redis 集成等核心模块,实现设备上下线事件处理 - 创建项目基础目录结构与配置文件 - 实现 Kafka 消费逻辑与手动提交偏移量 - 添加 PostgreSQL 数据库连接与分区表管理 - 集成 Redis 用于错误队列和项目心跳 - 包含数据处理逻辑,区分重启与非重启数据 - 提供数据库初始化脚本与分区创建工具 - 添加单元测试与代码校验脚本
42 lines
1.0 KiB
JavaScript
42 lines
1.0 KiB
JavaScript
import fs from 'fs';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
import { spawnSync } from 'child_process';
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
const projectRoot = path.resolve(__dirname, '..');
|
|
const targets = ['src', 'tests'];
|
|
|
|
const collectFiles = (dir) => {
|
|
if (!fs.existsSync(dir)) {
|
|
return [];
|
|
}
|
|
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
return entries.flatMap((entry) => {
|
|
const fullPath = path.join(dir, entry.name);
|
|
if (entry.isDirectory()) {
|
|
return collectFiles(fullPath);
|
|
}
|
|
if (entry.isFile() && fullPath.endsWith('.js')) {
|
|
return [fullPath];
|
|
}
|
|
return [];
|
|
});
|
|
};
|
|
|
|
const files = targets.flatMap((target) => collectFiles(path.join(projectRoot, target)));
|
|
|
|
const failures = [];
|
|
|
|
files.forEach((file) => {
|
|
const result = spawnSync(process.execPath, ['--check', file], { stdio: 'inherit' });
|
|
if (result.status !== 0) {
|
|
failures.push(file);
|
|
}
|
|
});
|
|
|
|
if (failures.length > 0) {
|
|
process.exit(1);
|
|
}
|