Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ACNA-1764 - update aio app:list:extension and aio app list:extension-points commands #571

Merged
merged 5 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/commands/app/list/extension-points.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const BaseCommand = require('../../../BaseCommand')
const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-app:list:extension-points', { provider: 'debug' })
const { Flags } = require('@oclif/core')

const { EXTENSION_POINT_LIST } = require('../../../lib/defaults')
shazron marked this conversation as resolved.
Show resolved Hide resolved
const chalk = require('chalk')
const yaml = require('js-yaml')

Expand All @@ -23,17 +22,28 @@ class ListExtensionPointsCommand extends BaseCommand {
const { flags } = await this.parse(ListExtensionPointsCommand)
aioLogger.debug(`list all extensions points with flags: ${JSON.stringify(flags)}`)

const extConfig = this.getAppExtConfigs(flags)
const extPointList = {}

Object.keys(extConfig).forEach(name => {
if (name !== 'application') {
extPointList[name] = {
operations: Object.keys(extConfig[name].operations)
}
}
})

// print
if (flags.json) {
this.log(JSON.stringify(EXTENSION_POINT_LIST))
this.log(JSON.stringify(extPointList))
} else if (flags.yml) {
this.log(yaml.dump(EXTENSION_POINT_LIST))
this.log(yaml.dump(extPointList))
} else {
this.log(chalk.bold('Extensions Points'))
Object.keys(EXTENSION_POINT_LIST).forEach(key => {
Object.keys(extPointList).forEach(key => {
this.log(key)
this.log(' operations')
EXTENSION_POINT_LIST[key].operations.forEach(opr => {
extPointList[key].operations.forEach(opr => {
this.log(' -> ' + opr)
})
})
Expand Down
43 changes: 22 additions & 21 deletions src/commands/app/list/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const BaseCommand = require('../../../BaseCommand')
const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-app:list:extensions', { provider: 'debug' })
const { Flags } = require('@oclif/core')

const { EXTENSION_POINT_LIST } = require('../../../lib/defaults')
const chalk = require('chalk')
const yaml = require('js-yaml')

Expand All @@ -26,28 +25,30 @@ class ListExtensionCommand extends BaseCommand {
const extConfig = this.getAppExtConfigs(flags)
const extSummary = {}

Object.keys(EXTENSION_POINT_LIST).forEach(extPoint => {
Object.keys(extConfig).forEach(extPoint => {
if (extPoint === 'application') {
return
}

const extension = extConfig[extPoint]
if (extension) {
const extDetails = { operations: {} }
extSummary[extPoint] = extDetails
const extDetails = { operations: {} }
extSummary[extPoint] = extDetails

// get view impl details
if (extension.operations.view) {
extDetails.operations.view = [
{
impl: extension.operations.view[0].impl
}
]
}
// get worker impl details
if (extension.operations.workerProcess) {
extDetails.operations.workerProcess = [
{
impl: extension.operations.workerProcess[0].impl
}
]
}
// get view impl details
if (extension.operations.view) {
extDetails.operations.view = [
{
impl: extension.operations.view[0].impl
}
]
}
// get worker impl details
if (extension.operations.workerProcess) {
extDetails.operations.workerProcess = [
{
impl: extension.operations.workerProcess[0].impl
}
]
}
})
// print
Expand Down
9 changes: 0 additions & 9 deletions src/lib/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@ module.exports = {
APPLICATION_CONFIG_KEY: 'application',
EXTENSIONS_CONFIG_KEY: 'extensions',

EXTENSION_POINT_LIST: {
'dx/excshell/1': {
operations: ['view']
},
'dx/asset-compute/worker/1': {
operations: ['workerProcess']
}
},

implPromptChoices: [
// we abuse the extension command to also let users add a standalone app
{
Expand Down
38 changes: 12 additions & 26 deletions test/commands/app/list/extension-points.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,12 @@ const LibConsoleCLI = require('@adobe/aio-cli-lib-console')
const mockConsoleCLIInstance = {}
LibConsoleCLI.init.mockResolvedValue(mockConsoleCLIInstance)

const createFullConfig = (aioConfig = {}, appFixtureName = 'legacy-app') => {
const appConfig = dataMocks(appFixtureName, aioConfig)
const createAppConfig = (aioConfig = {}, appFixtureName = 'legacy-app') => {
const appConfig = dataMocks(appFixtureName, aioConfig).all
appConfig.application = { ...appConfig.application, ...aioConfig }
return appConfig
}

const fakeAioConfig = {
console: {
project: {
org_id: 'fakeOrg'
}
}
}

test('exports', async () => {
expect(typeof TheCommand).toEqual('function')
expect(TheCommand.prototype instanceof BaseCommand).toBeTruthy()
Expand Down Expand Up @@ -69,13 +62,12 @@ describe('run', () => {
command = new TheCommand([])
command.error = jest.fn()
command.log = jest.fn()
command.getFullConfig = jest.fn()
const appConfig = createFullConfig({})
appConfig.aio = fakeAioConfig
command.getFullConfig.mockReturnValue(appConfig)
command.getAppExtConfigs = jest.fn()
})

test('get all extension points', async () => {
command.getAppExtConfigs.mockReturnValue(createAppConfig(command.appConfig, 'app-exc-nui'))

await command.run()
expect(command.error).toHaveBeenCalledTimes(0)
expect(command.log).toHaveBeenCalledWith(expect.stringContaining('Extensions Points'))
Expand All @@ -88,26 +80,20 @@ describe('run', () => {
})

test('get all extension points --json', async () => {
command = new TheCommand(['--json'])
command.error = jest.fn()
command.log = jest.fn()
command.getFullConfig = jest.fn()
const appConfig = createFullConfig({})
appConfig.aio = fakeAioConfig
command.getFullConfig.mockReturnValue(appConfig)
command.getAppExtConfigs.mockReturnValue(createAppConfig(command.appConfig, 'app-exc-nui'))
command.argv = ['--json']

await command.run()
expect(command.error).toHaveBeenCalledTimes(0)
expect(command.log).toHaveBeenCalledWith(JSON.stringify(extOutPut))
})

test('get all extension points --yml', async () => {
command = new TheCommand(['--yml'])
command.getAppExtConfigs.mockReturnValue(createAppConfig(command.appConfig, 'app-exc-nui'))
command.argv = ['--yml']
command.error = jest.fn()
command.log = jest.fn()
command.getFullConfig = jest.fn()
const appConfig = createFullConfig({})
appConfig.aio = fakeAioConfig
command.getFullConfig.mockReturnValue(appConfig)

await command.run()
expect(command.error).toHaveBeenCalledTimes(0)
expect(command.log).toHaveBeenCalledWith(yaml.dump(extOutPut))
Expand Down