Skip to content

Commit 7817ce3

Browse files
feat: Add script categorization to auto-sync notifications
- Added loadCategories() method to load category definitions from metadata.json - Added groupScriptsByCategory() method to group scripts by their categories - Modified scriptDownloaderService to return full script objects instead of just names - Updated notification format to show scripts grouped by category with proper formatting - Scripts are now displayed as: **Category Name:** • Script Name 1 • Script Name 2 This provides much better organization in notifications, making it easier to see what types of scripts were downloaded or updated.
1 parent 82b2012 commit 7817ce3

File tree

2 files changed

+75
-4
lines changed

2 files changed

+75
-4
lines changed

src/server/services/autoSyncService.js

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,46 @@ export class AutoSyncService {
356356
}
357357
}
358358

359+
/**
360+
* Load categories from metadata.json
361+
*/
362+
loadCategories() {
363+
try {
364+
const metadataPath = join(process.cwd(), 'scripts', 'json', 'metadata.json');
365+
const metadataContent = readFileSync(metadataPath, 'utf8');
366+
const metadata = JSON.parse(metadataContent);
367+
return metadata.categories || [];
368+
} catch (error) {
369+
console.error('Error loading categories:', error);
370+
return [];
371+
}
372+
}
373+
374+
/**
375+
* Group scripts by category
376+
* @param {Array} scripts - Array of script objects
377+
* @param {Array} categories - Array of category objects
378+
*/
379+
groupScriptsByCategory(scripts, categories) {
380+
const categoryMap = new Map();
381+
categories.forEach(cat => categoryMap.set(cat.id, cat.name));
382+
383+
const grouped = new Map();
384+
385+
scripts.forEach(script => {
386+
const scriptCategories = script.categories || [0]; // Default to Miscellaneous (id: 0)
387+
scriptCategories.forEach(catId => {
388+
const categoryName = categoryMap.get(catId) || 'Miscellaneous';
389+
if (!grouped.has(categoryName)) {
390+
grouped.set(categoryName, []);
391+
}
392+
grouped.get(categoryName).push(script.name);
393+
});
394+
});
395+
396+
return grouped;
397+
}
398+
359399
/**
360400
* Send notification about sync results
361401
* @param {Object} results - Sync results object
@@ -383,20 +423,51 @@ export class AutoSyncService {
383423
body += '\n';
384424
}
385425

426+
// Load categories for grouping
427+
const categories = this.loadCategories();
428+
386429
// @ts-ignore - Dynamic property access
387430
if (results.newScripts?.length > 0) {
388431
// @ts-ignore - Dynamic property access
389432
body += `New scripts downloaded: ${results.newScripts.length}\n`;
433+
434+
// Group new scripts by category
390435
// @ts-ignore - Dynamic property access
391-
body += `• ${results.newScripts.join('\n• ')}\n\n`;
436+
const newScriptsGrouped = this.groupScriptsByCategory(results.newScripts, categories);
437+
438+
// Sort categories by name for consistent ordering
439+
const sortedCategories = Array.from(newScriptsGrouped.keys()).sort();
440+
441+
sortedCategories.forEach(categoryName => {
442+
const scripts = newScriptsGrouped.get(categoryName);
443+
body += `\n**${categoryName}:**\n`;
444+
scripts.forEach(scriptName => {
445+
body += `• ${scriptName}\n`;
446+
});
447+
});
448+
body += '\n';
392449
}
393450

394451
// @ts-ignore - Dynamic property access
395452
if (results.updatedScripts?.length > 0) {
396453
// @ts-ignore - Dynamic property access
397454
body += `Scripts updated: ${results.updatedScripts.length}\n`;
455+
456+
// Group updated scripts by category
398457
// @ts-ignore - Dynamic property access
399-
body += `• ${results.updatedScripts.join('\n• ')}\n\n`;
458+
const updatedScriptsGrouped = this.groupScriptsByCategory(results.updatedScripts, categories);
459+
460+
// Sort categories by name for consistent ordering
461+
const sortedCategories = Array.from(updatedScriptsGrouped.keys()).sort();
462+
463+
sortedCategories.forEach(categoryName => {
464+
const scripts = updatedScriptsGrouped.get(categoryName);
465+
body += `\n**${categoryName}:**\n`;
466+
scripts.forEach(scriptName => {
467+
body += `• ${scriptName}\n`;
468+
});
469+
});
470+
body += '\n';
400471
}
401472

402473
// @ts-ignore - Dynamic property access

src/server/services/scriptDownloader.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ echo "Script downloaded: ${filePath}"
161161
if (!isDownloaded) {
162162
const result = await this.loadScript(script);
163163
if (result.success) {
164-
downloaded.push(script.name || script.slug);
164+
downloaded.push(script); // Return full script object instead of just name
165165
console.log(`Auto-downloaded new script: ${script.name || script.slug}`);
166166
} else {
167167
errors.push(`${script.name || script.slug}: ${result.message}`);
@@ -197,7 +197,7 @@ echo "Script downloaded: ${filePath}"
197197
if (needsUpdate) {
198198
const result = await this.loadScript(script);
199199
if (result.success) {
200-
updated.push(script.name || script.slug);
200+
updated.push(script); // Return full script object instead of just name
201201
console.log(`Auto-updated script: ${script.name || script.slug}`);
202202
} else {
203203
errors.push(`${script.name || script.slug}: ${result.message}`);

0 commit comments

Comments
 (0)