@lvnt/release-radar 1.6.0 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +34 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3,15 +3,22 @@ import { config } from 'dotenv';
|
|
|
3
3
|
config();
|
|
4
4
|
import TelegramBot from 'node-telegram-bot-api';
|
|
5
5
|
import cron from 'node-cron';
|
|
6
|
-
import { readFileSync, writeFileSync } from 'fs';
|
|
6
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'fs';
|
|
7
|
+
import { fileURLToPath } from 'url';
|
|
8
|
+
import { dirname, join } from 'path';
|
|
7
9
|
import { Storage } from './storage.js';
|
|
8
10
|
import { Notifier } from './notifier.js';
|
|
9
11
|
import { Checker } from './checker.js';
|
|
10
12
|
import { generateVersionsJson } from './versions-generator.js';
|
|
11
13
|
import { CliPublisher } from './cli-publisher.js';
|
|
14
|
+
// Get package directory for resolving config paths
|
|
15
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
16
|
+
const __dirname = dirname(__filename);
|
|
17
|
+
const PKG_ROOT = join(__dirname, '..'); // dist/../ = package root
|
|
18
|
+
console.log(`ReleaseRadar package root: ${PKG_ROOT}`);
|
|
12
19
|
const BOT_TOKEN = process.env.TELEGRAM_BOT_TOKEN;
|
|
13
20
|
const CHAT_ID = process.env.TELEGRAM_CHAT_ID;
|
|
14
|
-
const CONFIG_PATH = '
|
|
21
|
+
const CONFIG_PATH = join(PKG_ROOT, 'config', 'tools.json');
|
|
15
22
|
if (!BOT_TOKEN || !CHAT_ID) {
|
|
16
23
|
console.error('Missing TELEGRAM_BOT_TOKEN or TELEGRAM_CHAT_ID environment variables');
|
|
17
24
|
process.exit(1);
|
|
@@ -19,21 +26,41 @@ if (!BOT_TOKEN || !CHAT_ID) {
|
|
|
19
26
|
// Type-safe constants after validation
|
|
20
27
|
const validatedChatId = CHAT_ID;
|
|
21
28
|
// Load config
|
|
22
|
-
|
|
23
|
-
|
|
29
|
+
console.log(`Loading config from: ${CONFIG_PATH}`);
|
|
30
|
+
if (!existsSync(CONFIG_PATH)) {
|
|
31
|
+
console.error(`Config file not found: ${CONFIG_PATH}`);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
let configData;
|
|
35
|
+
try {
|
|
36
|
+
configData = JSON.parse(readFileSync(CONFIG_PATH, 'utf-8'));
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
console.error(`Failed to parse config: ${error}`);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
const DOWNLOADS_PATH = join(PKG_ROOT, 'config', 'downloads.json');
|
|
43
|
+
console.log(`Loading downloads config from: ${DOWNLOADS_PATH}`);
|
|
24
44
|
let downloadsConfig = {};
|
|
25
45
|
try {
|
|
26
46
|
downloadsConfig = JSON.parse(readFileSync(DOWNLOADS_PATH, 'utf-8'));
|
|
47
|
+
console.log(`Loaded ${Object.keys(downloadsConfig).length} download configs`);
|
|
27
48
|
}
|
|
28
49
|
catch {
|
|
29
50
|
console.log('No downloads.json found, CLI generation disabled');
|
|
30
51
|
}
|
|
52
|
+
// Data directory - use package root for now, could be made configurable
|
|
53
|
+
const DATA_DIR = join(PKG_ROOT, 'data');
|
|
54
|
+
if (!existsSync(DATA_DIR)) {
|
|
55
|
+
mkdirSync(DATA_DIR, { recursive: true });
|
|
56
|
+
}
|
|
57
|
+
console.log(`Data directory: ${DATA_DIR}`);
|
|
31
58
|
// Initialize components
|
|
32
59
|
const bot = new TelegramBot(BOT_TOKEN, { polling: true });
|
|
33
|
-
const storage = new Storage('
|
|
60
|
+
const storage = new Storage(join(DATA_DIR, 'versions.json'));
|
|
34
61
|
const notifier = new Notifier(bot, validatedChatId);
|
|
35
62
|
const checker = new Checker(configData.tools, storage, notifier);
|
|
36
|
-
const cliPublisher = new CliPublisher(downloadsConfig);
|
|
63
|
+
const cliPublisher = new CliPublisher(downloadsConfig, join(PKG_ROOT, 'cli'));
|
|
37
64
|
// Track scheduled task for rescheduling
|
|
38
65
|
let scheduledTask = null;
|
|
39
66
|
let lastCheckTime = null;
|
|
@@ -157,7 +184,7 @@ bot.onText(/\/generate/, async (msg) => {
|
|
|
157
184
|
}
|
|
158
185
|
const state = storage.load();
|
|
159
186
|
const versionsJson = generateVersionsJson(state.versions, downloadsConfig);
|
|
160
|
-
const outputPath = '
|
|
187
|
+
const outputPath = join(DATA_DIR, 'cli-versions.json');
|
|
161
188
|
writeFileSync(outputPath, JSON.stringify(versionsJson, null, 2));
|
|
162
189
|
await bot.sendMessage(CHAT_ID, `Generated versions.json with ${versionsJson.tools.length} tools.\nPath: ${outputPath}`);
|
|
163
190
|
});
|