mirror of
https://github.com/HeyPuter/puter.git
synced 2025-12-18 11:15:04 -06:00
This commit adds the `extension:list` command for listing extensions. This command is itself defined in an extension. To make this possible, an event called 'create.commands' is emitted form CommandService with the event object holding a function that can be used to add commands.
33 lines
1.0 KiB
JavaScript
33 lines
1.0 KiB
JavaScript
//@extension name extension
|
|
const { Context } = extension.import('core');
|
|
|
|
// The 'create.commands' event is fired by CommandService
|
|
extension.on('create.commands', event => {
|
|
|
|
// Add command to list available extensions
|
|
event.createCommand('list', {
|
|
description: 'list available extensions',
|
|
handler: async (_, console) => {
|
|
|
|
// Get extnsion information from context
|
|
const extensionInfos = Context.get('extensionInfo');
|
|
|
|
// Iterate over extension infos
|
|
for ( const info of Object.values(extensionInfos) ) {
|
|
|
|
// Construct a string
|
|
const moduleType = info.type === 'module'
|
|
? '\x1B[32;1m(ESM)\x1B[0m'
|
|
: '\x1B[33;1m(CJS)\x1B[0m';
|
|
let str = `- ${info.name} ${moduleType}`;
|
|
if ( info.priority !== 0 ) {
|
|
str += ` (priority ${info.priority})`;
|
|
}
|
|
|
|
// Print a string
|
|
console.log(str);
|
|
}
|
|
},
|
|
});
|
|
});
|