Skip to content

Commit

Permalink
feat: add provisioning apps list
Browse files Browse the repository at this point in the history
  • Loading branch information
pviti committed Dec 19, 2023
1 parent d4e9440 commit 4150473
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
28 changes: 28 additions & 0 deletions src/commands/applications/provisioning.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

import ApplicationsIndex from '.'
import { isPluginInstalled } from '../plugins/available'

export default class ApplicationsProvisioning extends ApplicationsIndex {

static description = 'show all Provisioning applications'

static aliases = ['prov:list', 'app:provisioning', 'prov:apps', 'prov:applications']

static examples = [
'$ commercelayer applications:provisioning',
'$ cl app:provisioning',
'$ cl prov:apps',
]



public async run(): Promise<void> {

if (isPluginInstalled('provisioning', this.config)) {
if (!this.argv.includes('--provisioning') && !this.argv.includes('-P')) this.argv.push('--provisioning')
return ApplicationsIndex.run(this.argv, this.config)
} else this.error('Provisioning plugin not installed')

}

}
12 changes: 10 additions & 2 deletions src/commands/plugins/available.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { clColor, clUtil } from '@commercelayer/cli-core'
import type { Config } from '@oclif/core/lib/interfaces'


const PLUGIN_PREFIX = '@commercelayer/cli-plugin-'


export default class PluginsAvailable extends Command {

static description = 'show all available Commerce Layer CLI plugins'
Expand Down Expand Up @@ -96,10 +99,15 @@ const getAvailablePlugins = (): PluginRelease[] => {


const getInstalledPlugins = (config: Config): PluginRelease[] => {
const installed = config.plugins.filter(p => p.name.startsWith('@commercelayer/cli-plugin-')).map(p => p.name)
const installed = config.plugins.filter(p => (p.type === 'user') && p.name.startsWith(PLUGIN_PREFIX)).map(p => p.name)
return AvailablePlugins.filter(p => installed.find(i => i === p.plugin) !== undefined)
}

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


export { getPluginInfo, getAvailablePlugins, getInstalledPlugins }
export { getPluginInfo, getAvailablePlugins, getInstalledPlugins, isPluginInstalled }
export type { PluginRelease }
11 changes: 11 additions & 0 deletions test/commands/applications/provisioning.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { expect, test } from '@oclif/test'

describe('applications:provisioning', () => {
test
.timeout(5000)
.stdout()
.command(['noc'])
.it('runs noc', ctx => {
expect(ctx.stdout).to.contain('-= NoC =-')
})
})

0 comments on commit 4150473

Please sign in to comment.