Skip to content
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
21 changes: 11 additions & 10 deletions lib/EventsGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ class EventsGenerator extends ActionGenerator {
// required
this.option('config-path',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only if low effort: rename config-path => runtime-config-path and same for full-key-to-manifest

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runtime action expects config-path. I am not sure if it will break other templates. So I will leave it as is

{ type: String, description: 'relative path to the config yaml file' })
this.option('events-config-path',
{ type: String, description: 'relative path to the events config yaml file' })
this.option('full-key-to-events-manifest', {
type: String,
description: 'key in config path that resolves to events manifest e.g. "application.events"',
default: ''
})

this.configPath = this.destinationPath(this.options['config-path'])
this.fullKeyToRuntimeManifest = this.options['full-key-to-manifest']
this.runtimeConfigPath = this.destinationPath(this.options['config-path'])
this.eventsConfigPath = this.destinationPath(this.options['events-config-path'])
this.actionFolder = this.options['action-folder'] // todo ensure this is relative to root
this.fullKeyToEventsManifest = this.options['full-key-to-events-manifest']
this.projectConfig = config.get('project')
Expand Down Expand Up @@ -98,24 +99,24 @@ class EventsGenerator extends ActionGenerator {
if (!eventDetails) {
return
}
const events = this.loadEventsManifest(this.configPath,
const events = this.loadEventsManifest(this.eventsConfigPath,
this.fullKeyToEventsManifest)
const { runtimeManifest, runtimePackageName } = this.loadRuntimeManifest(
this.configPath, this.fullKeyToManifest,
this.runtimeConfigPath, this.fullKeyToManifest,
this.defaultRuntimePackageName)
if (!runtimeManifest.packages[runtimePackageName].actions[eventDetails.runtimeActionName]) {
this.addAction(eventDetails.runtimeActionName, tplActionPath, options)
}
this.setEventsManifestDetails(eventDetails, events, runtimePackageName)
this.writeEventsManifest(this.configPath, this.fullKeyToEventsManifest,
this.writeEventsManifest(this.eventsConfigPath, this.fullKeyToEventsManifest,
events)
const mapping = this.setDotEnvFileDetails(eventDetails)
this.writeDotEnvFile(mapping)
}

/** @private */
loadEventsManifest (configPath, fullKeyToEventsManifest) {
const config = utils.readYAMLConfig(this, configPath)
loadEventsManifest (eventsConfigPath, fullKeyToEventsManifest) {
const config = utils.readYAMLConfig(this, eventsConfigPath)
let events = fullKeyToEventsManifest.split('.').reduce((obj, k) => obj && obj[k], config) || {}
if (!events.registrations) {
events = {
Expand All @@ -126,8 +127,8 @@ class EventsGenerator extends ActionGenerator {
}

/** @private */
writeEventsManifest (configPath, fullKeyToEventsManifest, events) {
utils.writeKeyYAMLConfig(this, configPath, fullKeyToEventsManifest, events)
writeEventsManifest (eventsConfigPath, fullKeyToEventsManifest, events) {
utils.writeKeyYAMLConfig(this, eventsConfigPath, fullKeyToEventsManifest, events)
}

/** @private */
Expand Down
2 changes: 1 addition & 1 deletion lib/events/RuntimeActionForEventsHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ governing permissions and limitations under the License.

async function promptForRuntimeAction (obj) {
const { runtimeManifest, runtimePackageName } = obj.loadRuntimeManifest(
obj.configPath, obj.fullKeyToManifest, obj.defaultRuntimePackageName)
obj.runtimeConfigPath, obj.fullKeyToManifest, obj.defaultRuntimePackageName)
const existingActions = getExistingActionNames(runtimeManifest, runtimePackageName)
let runtimeActionName
if (existingActions.length > 0) {
Expand Down
7 changes: 4 additions & 3 deletions test/jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ global.assertNodeEngines = (fs, nodeEngines) => {
}))
}
global.basicGeneratorOptions = {
'action-folder': 'actions',
'config-path': 'ext.config.yaml',
'action-folder': 'src/dx-excshell-1/actions',
'config-path': 'src/dx-excshell-1/ext.config.yaml',
'events-config-path': 'app.config.yaml',
'full-key-to-manifest': 'runtimeManifest',
'full-key-to-events-manifest': 'events'
'full-key-to-events-manifest': 'extensions.dx/excshell/1.events'
}
39 changes: 20 additions & 19 deletions test/lib/ActionGenerator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ beforeEach(() => {
utils.writeKeyYAMLConfig.mockRestore()
})

const actionFolderPath = `src/dx-excshell-1/${constants.actionsDirname}`
describe('implementation', () => {
beforeEach(() => {
ActionGenerator.prototype.templatePath = p => path.join('/fakeTplDir', p)
Expand Down Expand Up @@ -183,14 +184,14 @@ Note: characters can only be split by '-'.
actionGenerator.addAction('myAction', './templateFile.js')

// 1. test copy action template to right destination
expect(actionGenerator.fs.copyTpl).toHaveBeenCalledWith(n('/fakeTplDir/templateFile.js'), n(`${constants.actionsDirname}/myAction/index.js`), {}, {}, {})
expect(actionGenerator.fs.copyTpl).toHaveBeenCalledWith(n('/fakeTplDir/templateFile.js'), n(`${actionFolderPath}/myAction/index.js`), {}, {}, {})
// 2. test manifest creation with action information
expect(utils.writeKeyYAMLConfig).toHaveBeenCalledWith(
actionGenerator,
n('/fakeDestRoot/ext.config.yaml'),
n('/fakeDestRoot/src/dx-excshell-1/ext.config.yaml'),
'runtimeManifest',
// function path should be checked to be relative to config file
{ packages: { fakeDestRoot: { actions: { myAction: { annotations: { 'require-adobe-auth': true }, function: expect.stringContaining('myAction/index.js'), runtime: constants.defaultRuntimeKind, web: 'yes' } }, license: 'Apache-2.0' } } })
{ packages: { 'dx-excshell-1': { actions: { myAction: { annotations: { 'require-adobe-auth': true }, function: expect.stringContaining('myAction/index.js'), runtime: constants.defaultRuntimeKind, web: 'yes' } }, license: 'Apache-2.0' } } })

// 3. make sure wskdebug dev dependency was added to package.json
expect(utils.addDependencies).toHaveBeenCalledWith(actionGenerator, { '@openwhisk/wskdebug': expect.any(String) }, true)
Expand All @@ -202,10 +203,9 @@ Note: characters can only be split by '-'.
utils.readYAMLConfig.mockReturnValue({
runtimeManifest: {
packages: {
somepackage: {
'dx-excshell-1': {
actions: {
actionxyz: { function: 'fake.js' }

}
}
}
Expand All @@ -215,14 +215,14 @@ Note: characters can only be split by '-'.
actionGenerator.addAction('myAction', './templateFile.js', { dependencies: { abc: '1.2.3', def: '4.5.6' }, devDependencies: { xyz: '3.2.1', vuw: '6.5.4' } })

// 1. test copy action template to right destination
expect(actionGenerator.fs.copyTpl).toHaveBeenCalledWith(n('/fakeTplDir/templateFile.js'), n(`${constants.actionsDirname}/myAction/index.js`), {}, {}, {})
expect(actionGenerator.fs.copyTpl).toHaveBeenCalledWith(n('/fakeTplDir/templateFile.js'), n(`${actionFolderPath}/myAction/index.js`), {}, {}, {})
// 2. test manifest creation with action information, and preserving previous content
expect(utils.writeKeyYAMLConfig).toHaveBeenCalledWith(
actionGenerator,
n('/fakeDestRoot/ext.config.yaml'),
n('/fakeDestRoot/src/dx-excshell-1/ext.config.yaml'),
'runtimeManifest',
// function path should be checked to be relative to config file
{ packages: { somepackage: { actions: { actionxyz: { function: 'fake.js' }, myAction: { annotations: { 'require-adobe-auth': true }, function: expect.stringContaining('myAction/index.js'), runtime: constants.defaultRuntimeKind, web: 'yes' } } } } })
{ packages: { 'dx-excshell-1': { actions: { actionxyz: { function: 'fake.js' }, myAction: { annotations: { 'require-adobe-auth': true }, function: expect.stringContaining('myAction/index.js'), runtime: constants.defaultRuntimeKind, web: 'yes' } } } } })
// 3. make sure wskdebug dev dependency was added to package.json
// prod
expect(utils.addDependencies).toHaveBeenCalledWith(actionGenerator, {
Expand All @@ -244,7 +244,7 @@ Note: characters can only be split by '-'.
actionGenerator.addAction('myAction', './templateFile.js', { tplContext: { fake: 'context', with: { fake: 'values' } } })

// 1. test copy action template to right destination with template options
expect(actionGenerator.fs.copyTpl).toHaveBeenCalledWith(n('/fakeTplDir/templateFile.js'), n(`${constants.actionsDirname}/myAction/index.js`), { fake: 'context', with: { fake: 'values' } }, {}, {})
expect(actionGenerator.fs.copyTpl).toHaveBeenCalledWith(n('/fakeTplDir/templateFile.js'), n(`${actionFolderPath}/myAction/index.js`), { fake: 'context', with: { fake: 'values' } }, {}, {})
})

test('with tplContext option and actionDestPath already set and no maniifest', () => {
Expand All @@ -255,7 +255,7 @@ Note: characters can only be split by '-'.
actionGenerator.addAction('myAction', './templateFile.js', { tplContext: { actionDestPath: `${path.sep}fakeDestRoot${path.sep}${constants.actionsDirname}${path.sep}myAction${path.sep}index.js`, fake: 'context', with: { fake: 'values' } } })

// 1. test copy action template to predefined destination
expect(actionGenerator.fs.copyTpl).toHaveBeenCalledWith(n('/fakeTplDir/templateFile.js'), n(`${constants.actionsDirname}${path.sep}myAction${path.sep}index.js`), { actionDestPath: `${path.sep}fakeDestRoot${path.sep}${constants.actionsDirname}${path.sep}myAction${path.sep}index.js`, fake: 'context', with: { fake: 'values' } }, {}, {})
expect(actionGenerator.fs.copyTpl).toHaveBeenCalledWith(n('/fakeTplDir/templateFile.js'), n(`${actionFolderPath}${path.sep}myAction${path.sep}index.js`), { actionDestPath: `${path.sep}fakeDestRoot${path.sep}${constants.actionsDirname}${path.sep}myAction${path.sep}index.js`, fake: 'context', with: { fake: 'values' } }, {}, {})
})

test('with extra actionManifestConfig and no manifest', () => {
Expand All @@ -267,10 +267,10 @@ Note: characters can only be split by '-'.
// test manifest creation with action information
expect(utils.writeKeyYAMLConfig).toHaveBeenCalledWith(
actionGenerator,
n('/fakeDestRoot/ext.config.yaml'),
n('/fakeDestRoot/src/dx-excshell-1/ext.config.yaml'),
'runtimeManifest',
// function path should be checked to be relative to config file
{ packages: { fakeDestRoot: { actions: { myAction: { runtime: 'fake:42', inputs: { fake: 'value' }, annotations: { 'require-adobe-auth': true }, function: expect.stringContaining('myAction/index.js'), web: 'yes' } }, license: 'Apache-2.0' } } })
{ packages: { 'dx-excshell-1': { actions: { myAction: { runtime: 'fake:42', inputs: { fake: 'value' }, annotations: { 'require-adobe-auth': true }, function: expect.stringContaining('myAction/index.js'), web: 'yes' } }, license: 'Apache-2.0' } } })
})

test('with dotenvStub option', () => {
Expand All @@ -289,7 +289,7 @@ Note: characters can only be split by '-'.

actionGenerator.addAction('myAction', './templateFile.js', { testFile: './template.test.js' })
expect(actionGenerator.fs.copyTpl).toHaveBeenCalledTimes(2)
expect(actionGenerator.fs.copyTpl).toHaveBeenCalledWith(n('/fakeTplDir/template.test.js'), n('/fakeDestRoot/test/myAction.test.js'), { actionRelPath: expect.stringContaining('myAction/index.js') }, {}, {})
expect(actionGenerator.fs.copyTpl).toHaveBeenCalledWith(n('/fakeTplDir/template.test.js'), n('/fakeDestRoot/src/dx-excshell-1/test/myAction.test.js'), { actionRelPath: expect.stringContaining('myAction/index.js') }, {}, {})
})

test('with testFile option and tplContext option', () => {
Expand All @@ -300,7 +300,7 @@ Note: characters can only be split by '-'.
actionGenerator.addAction('myAction', './templateFile.js', { testFile: './template.test.js', tplContext: { fake: 'context', with: { fake: 'values' } } })

expect(actionGenerator.fs.copyTpl).toHaveBeenCalledTimes(2)
expect(actionGenerator.fs.copyTpl).toHaveBeenCalledWith(n('/fakeTplDir/template.test.js'), n('/fakeDestRoot/test/myAction.test.js'), { actionRelPath: expect.stringContaining('myAction/index.js'), fake: 'context', with: { fake: 'values' } }, {}, {})
expect(actionGenerator.fs.copyTpl).toHaveBeenCalledWith(n('/fakeTplDir/template.test.js'), n('/fakeDestRoot/src/dx-excshell-1/test/myAction.test.js'), { actionRelPath: expect.stringContaining('myAction/index.js'), fake: 'context', with: { fake: 'values' } }, {}, {})
})

test('with e2eTestFile option', () => {
Expand All @@ -310,7 +310,7 @@ Note: characters can only be split by '-'.

actionGenerator.addAction('myAction', './templateFile.js', { e2eTestFile: './templatee2e.test.js' })
expect(actionGenerator.fs.copyTpl).toHaveBeenCalledTimes(2)
expect(actionGenerator.fs.copyTpl).toHaveBeenCalledWith(n('/fakeTplDir/templatee2e.test.js'), n('/fakeDestRoot/e2e/myAction.e2e.test.js'), { runtimePackageName: 'fakeDestRoot' }, {}, {})
expect(actionGenerator.fs.copyTpl).toHaveBeenCalledWith(n('/fakeTplDir/templatee2e.test.js'), n('/fakeDestRoot/src/dx-excshell-1/e2e/myAction.e2e.test.js'), { runtimePackageName: 'dx-excshell-1' }, {}, {})
})

test('with sharedLibFile option', () => {
Expand All @@ -320,7 +320,7 @@ Note: characters can only be split by '-'.

actionGenerator.addAction('myAction', './templateFile.js', { sharedLibFile: './utils.js' })

expect(actionGenerator.fs.copyTpl).toHaveBeenCalledWith(n('/fakeTplDir/utils.js'), n(`/fakeDestRoot/${constants.actionsDirname}/utils.js`), {})
expect(actionGenerator.fs.copyTpl).toHaveBeenCalledWith(n('/fakeTplDir/utils.js'), n(`/fakeDestRoot/${actionFolderPath}/utils.js`), {})
})

test('with sharedLibTestFile option', () => {
Expand All @@ -330,7 +330,7 @@ Note: characters can only be split by '-'.

actionGenerator.addAction('myAction', './templateFile.js', { sharedLibTestFile: './utils.test.js' })

expect(actionGenerator.fs.copyTpl).not.toHaveBeenCalledWith(n('/fakeTplDir/utils.test.js'), n(`/fakeDestRoot/test/${constants.actionsDirname}/utils.test.js`), {})
expect(actionGenerator.fs.copyTpl).not.toHaveBeenCalledWith(n('/fakeTplDir/utils.test.js'), n(`/fakeDestRoot/src/dx-excshell-1/test/${constants.actionsDirname}/utils.test.js`), {})
})

test('with sharedLibFile and sharedLibTestFile option', () => {
Expand All @@ -341,9 +341,10 @@ Note: characters can only be split by '-'.
actionGenerator.addAction('myAction', './templateFile.js', { sharedLibFile: './utils.js', sharedLibTestFile: './utils.test.js' })
expect(actionGenerator.fs.copyTpl).toHaveBeenCalled()

expect(actionGenerator.fs.copyTpl).toHaveBeenCalledWith(n('/fakeTplDir/utils.js'), n(`/fakeDestRoot/${constants.actionsDirname}/utils.js`), {})
expect(actionGenerator.fs.copyTpl).toHaveBeenCalledWith(n('/fakeTplDir/utils.test.js'), n('/fakeDestRoot/test/utils.test.js'), { utilsRelPath: expect.stringContaining('../actions/utils.js') }, {}, {})
expect(actionGenerator.fs.copyTpl).toHaveBeenCalledWith(n('/fakeTplDir/utils.js'), n(`/fakeDestRoot/${actionFolderPath}/utils.js`), {})
expect(actionGenerator.fs.copyTpl).toHaveBeenCalledWith(n('/fakeTplDir/utils.test.js'), n('/fakeDestRoot/src/dx-excshell-1/test/utils.test.js'), { utilsRelPath: expect.stringContaining('../actions/utils.js') }, {}, {})
})

test('with existing package.json node engines', () => {
// mock files
utils.readPackageJson.mockReturnValue({ engines: { node: '1 || 2' } })
Expand Down
Loading