Skip to content

Commit

Permalink
feat: enhance package extraction with file persistence and CLI support
Browse files Browse the repository at this point in the history
- Add automatic package list persistence when changes are detected
- Implement direct CLI execution support for the extractor
- Add proper error handling and exit codes for CLI usage
- Add feedback messages for file updates and extraction status
  • Loading branch information
michaellatman committed Nov 27, 2024
1 parent dcb5aae commit e9a2441
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/extractors/modelcontextprotocol-extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ export async function extractPackageInfo(): Promise<PackageInfo[]> {
}
}

// Write updated packages to file if there are changes
if (hasChanges) {
fs.writeFileSync(outputPath, JSON.stringify(mergedPackages, null, 2));
console.log('Package list updated successfully');
} else {
console.log('No changes detected in package list');
}

// Cleanup
fs.rmSync(tempDir, { recursive: true, force: true });
console.log('Temporary files cleaned up');
Expand All @@ -100,4 +108,14 @@ export async function extractPackageInfo(): Promise<PackageInfo[]> {
}
throw error;
}
}
}

// Run the function if this file is executed directly
if (import.meta.url === `file://${__filename}`) {
extractPackageInfo()
.then(() => console.log('Package extraction completed'))
.catch(error => {
console.error('Failed to extract packages:', error);
process.exit(1);
});
}

0 comments on commit e9a2441

Please sign in to comment.