-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·109 lines (92 loc) · 3 KB
/
index.js
File metadata and controls
executable file
·109 lines (92 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env node
/**
* Mastery CLI - A beginner-friendly learning tool
*
* Transform your study notes into interactive flashcards and practice
* coding problems right from your terminal!
*
* Quick start:
* - mastery term : Study flashcards
* - mastery dsa : Practice coding problems
* - mastery --help : See all commands
*/
const path = require('path');
const cli = require('./src/cli');
const log = require('./src/log');
const utils = require('./src/utils');
const demos = require('./src/demo');
const Settings = require('./src/settings');
const cli_meow = cli[0];
const cmInfo = cli[1];
const flags = cli_meow.flags;
const input = cli_meow.input;
const { Mastery } = utils;
const { ExtensionManager } = require('./src/extensions/ExtensionManager');
(async () => {
try {
// Initialize with empty deck, will be lazily loaded when needed
const mastery = new Mastery(Settings, null);
// Initialize extension manager
const extensionManager = new ExtensionManager(
path.join(__dirname, 'src', 'extensions'),
{ info: () => {}, error: console.error, warn: console.warn }
);
// Load all extensions automatically
const context = {
flags: flags,
masteryManager: mastery,
settings: Settings
};
extensionManager.loadAllExtensions(context);
// Merge extension commands with mastery commands
const extensionCommands = {};
for (const command of extensionManager.getRegisteredCommands()) {
extensionCommands[command] =
extensionManager.getCommandHandler(command);
}
// Add extension management command
extensionCommands['extensions'] = () => {
console.log('\n=== Extension System Status ===');
const status = extensionManager.getStatus();
console.log(`Extensions Loaded: ${status.extensionsLoaded}`);
console.log(`Commands Registered: ${status.commandsRegistered}`);
console.log(`Hooks Registered: ${status.hooksRegistered}`);
if (status.extensions.length > 0) {
console.log('\n=== Loaded Extensions ===');
status.extensions.forEach(ext => {
console.log(
`• ${ext.name} v${ext.version} by ${ext.author}`
);
console.log(` ${ext.description}`);
});
}
console.log('\n=== Available Extension Commands ===');
extensionManager.getRegisteredCommands().forEach(cmd => {
console.log(`• mastery ${cmd}`);
});
};
// Combine built-in and extension commands
const allCommandHandlers = {
...mastery.commandHandlers,
...extensionCommands
};
const options = Object.keys(cmInfo.commands);
input.includes(options[0]) && cli_meow.showHelp(0);
mastery.clearOnTalk = true;
var functionCalled = false;
for (const command of Object.keys(allCommandHandlers)) {
if (input.includes(command)) {
functionCalled = true;
const res = await allCommandHandlers[command]();
return; // Stop after executing the first matched command
}
}
if (!functionCalled) {
cli_meow.showHelp(0);
mastery.askToClean();
}
} catch (error) {
console.error('Application error:', error.message);
process.exit(1);
}
})();