Skip to content

Commit

Permalink
feat: make available plugins list sortable
Browse files Browse the repository at this point in the history
  • Loading branch information
pviti committed Nov 22, 2024
1 parent 55df7e7 commit aed1312
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions src/commands/plugins/available.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ export default class PluginsAvailable extends Command {
hidden: Flags.boolean({
char: 'H',
description: 'show also enabled but hidden plugins',
hidden: true,
hidden: true
}),
sort: Flags.boolean({
char: 'S',
description: 'order by plugin name'
})
}


Expand All @@ -33,11 +37,12 @@ export default class PluginsAvailable extends Command {
const availablePlugins = AvailablePlugins.filter(p => ((!p.hidden || flags.hidden) && p.enabled))

if (availablePlugins && (availablePlugins.length > 0)) {
if (flags.sort) availablePlugins.sort((a, b) => a.name.localeCompare(b.name))
cliux.Table.table(availablePlugins, {
key: { header: 'PLUGIN (KEY)', minWidth: 20, get: row => (row.hidden ? clColor.dim : clColor).blueBright(row.name) },
description: { header: 'DESCRIPTION', get: row => (row.hidden ? clColor.dim(row.description) : row.description) },
}, {
printLine: clUtil.log,
key: { header: 'PLUGIN (KEY)', minWidth: 20, get: row => (row.hidden ? clColor.dim : clColor).blueBright(row.name) },
description: { header: 'DESCRIPTION', get: row => (row.hidden ? clColor.dim(row.description) : row.description) },
}, {
printLine: clUtil.log,
})
} else this.log(clColor.italic('No available plugins'))

Expand All @@ -58,20 +63,20 @@ type PluginRelease = {
}

const AvailablePlugins: PluginRelease[] = [
{ name: 'resources', plugin: '@commercelayer/cli-plugin-resources', description: 'CRUD operations on API resources', enabled: true },
{ name: 'seeder', plugin: '@commercelayer/cli-plugin-seeder', description: 'Organization data seeder', enabled: true },
{ name: 'imports', plugin: '@commercelayer/cli-plugin-imports', description: 'Organization imports manager', enabled: true },
{ name: 'webhooks', plugin: '@commercelayer/cli-plugin-webhooks', description: 'Organization webhooks analyzer', enabled: true },
{ name: 'orders', plugin: '@commercelayer/cli-plugin-orders', description: 'Organization orders management', enabled: true },
{ name: 'checkout', plugin: '@commercelayer/cli-plugin-checkout', description: 'Checkout URLs generation', enabled: true },
{ name: 'triggers', plugin: '@commercelayer/cli-plugin-triggers', description: 'Execute actions on resources', enabled: true },
{ name: 'token', plugin: '@commercelayer/cli-plugin-token', description: 'Manage Commerce Layer access tokens', enabled: true },
{ name: 'microstore', plugin: '@commercelayer/cli-plugin-microstore', description: 'Microstore URLs generation', enabled: true },
{ name: 'exports', plugin: '@commercelayer/cli-plugin-exports', description: 'Organization exports manager', enabled: true },
{ name: 'cleanups', plugin: '@commercelayer/cli-plugin-cleanups', description: 'Organization cleanups manager', enabled: true },
{ name: 'tags', plugin: '@commercelayer/cli-plugin-tags', description: 'Manage resources tags', enabled: true },
{ name: 'provisioning', plugin: '@commercelayer/cli-plugin-provisioning', description: 'Add support for Provisioning API', enabled: true },
{ name: 'links', plugin: '@commercelayer/cli-plugin-links', description: 'Manage links to resources', enabled: true }
{ name: 'resources', plugin: '@commercelayer/cli-plugin-resources', description: 'CRUD operations on API resources', enabled: true },
{ name: 'seeder', plugin: '@commercelayer/cli-plugin-seeder', description: 'Organization data seeder', enabled: true },
{ name: 'imports', plugin: '@commercelayer/cli-plugin-imports', description: 'Organization imports manager', enabled: true },
{ name: 'webhooks', plugin: '@commercelayer/cli-plugin-webhooks', description: 'Organization webhooks analyzer', enabled: true },
{ name: 'orders', plugin: '@commercelayer/cli-plugin-orders', description: 'Organization orders management', enabled: true },
{ name: 'checkout', plugin: '@commercelayer/cli-plugin-checkout', description: 'Checkout URLs generation', enabled: true },
{ name: 'triggers', plugin: '@commercelayer/cli-plugin-triggers', description: 'Execute actions on resources', enabled: true },
{ name: 'token', plugin: '@commercelayer/cli-plugin-token', description: 'Manage Commerce Layer access tokens', enabled: true },
{ name: 'microstore', plugin: '@commercelayer/cli-plugin-microstore', description: 'Microstore URLs generation', enabled: true },
{ name: 'exports', plugin: '@commercelayer/cli-plugin-exports', description: 'Organization exports manager', enabled: true },
{ name: 'cleanups', plugin: '@commercelayer/cli-plugin-cleanups', description: 'Organization cleanups manager', enabled: true },
{ name: 'tags', plugin: '@commercelayer/cli-plugin-tags', description: 'Manage resources tags', enabled: true },
{ name: 'provisioning', plugin: '@commercelayer/cli-plugin-provisioning', description: 'Add support for Provisioning API', enabled: true },
{ name: 'links', plugin: '@commercelayer/cli-plugin-links', description: 'Manage links to resources', enabled: true }
]


Expand Down Expand Up @@ -105,8 +110,8 @@ const getInstalledPlugins = (config: Config): PluginRelease[] => {
}

const isPluginInstalled = (name: string, config: Config): boolean => {
const plugin = name.startsWith(PLUGIN_PREFIX)? name : `${PLUGIN_PREFIX}${name}`
return (getInstalledPlugins(config).findIndex(p => (p.plugin === plugin)) > -1)
const plugin = name.startsWith(PLUGIN_PREFIX) ? name : `${PLUGIN_PREFIX}${name}`
return (getInstalledPlugins(config).findIndex(p => (p.plugin === plugin)) > -1)
}


Expand Down

0 comments on commit aed1312

Please sign in to comment.