Files
puter/extensions/extension-util.js
KernelDeimos cb31c1d44e dev: add command to list extensions
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.
2025-09-26 15:27:59 -04:00

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);
}
},
});
});