Skip to content

Commit

Permalink
fix: generate web or actions keys in app.config.yaml only when necess…
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelGoberling authored Jul 13, 2022
1 parent 9b43a3b commit dba9f6a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
25 changes: 14 additions & 11 deletions generators/application/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,22 @@ class Application extends Generator {
this.webSrcFolder = path.join(this.appFolder, 'web-src')
this.configPath = path.join(this.appFolder, 'app.config.yaml')
this.keyToManifest = 'application.' + runtimeManifestKey
this.components = ['actions', 'events', 'webAssets'] // defaults when skip prompt
}

async writing () {
// add basic config to point to path, relative to config file
utils.writeKeyAppConfig(this, 'application.actions', path.relative(this.appFolder, this.actionFolder))
utils.writeKeyAppConfig(this, 'application.web', path.relative(this.appFolder, this.webSrcFolder))
// add path to actions in app.config.yaml
if (this.components.includes('actions')) {
utils.writeKeyAppConfig(this, 'application.actions', path.relative(this.appFolder, this.actionFolder))
}

// add path to web assets in app.config.yaml
if (this.components.includes('webAssets')) {
utils.writeKeyAppConfig(this, 'application.web', path.relative(this.appFolder, this.webSrcFolder))
}
}

async composeWithAddGenerators () {
let components = ['actions', 'events', 'webAssets'] // defaults when skip prompt
if (!this.options['skip-prompt']) {
const res = await this.prompt([
{
Expand Down Expand Up @@ -81,15 +87,12 @@ class Application extends Generator {
validate: utils.atLeastOne
}
])
components = res.components
this.components = res.components
}
const addActions = components.includes('actions')
const addEvents = components.includes('events')
const addWebAssets = components.includes('webAssets')

// TODO cleanup unecessary params in all generators
// run add action and add ui generators when applicable
if (addActions) {
if (this.components.includes('actions')) {
this.composeWith(path.join(__dirname, '../add-action/index.js'), {
'skip-prompt': this.options['skip-prompt'],
'adobe-services': this.options['adobe-services'],
Expand All @@ -99,7 +102,7 @@ class Application extends Generator {
'full-key-to-manifest': this.keyToManifest
})
}
if (addEvents) {
if (this.components.includes('events')) {
this.composeWith(path.join(__dirname, '../add-events/index.js'), {
'skip-prompt': this.options['skip-prompt'],
'adobe-services': this.options['adobe-services'],
Expand All @@ -108,7 +111,7 @@ class Application extends Generator {
'full-key-to-manifest': this.keyToManifest
})
}
if (addWebAssets) {
if (this.components.includes('webAssets')) {
this.composeWith(path.join(__dirname, '../add-web-assets/index.js'), {
'skip-prompt': this.options['skip-prompt'],
'adobe-services': this.options['adobe-services'],
Expand Down
33 changes: 33 additions & 0 deletions test/generators/application/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,22 @@ const helpers = require('yeoman-test')

const theGeneratorPath = require.resolve('../../../generators/application')
const Generator = require('yeoman-generator')
const { utils } = require('@adobe/generator-app-common-lib')

// spies
const composeWith = jest.spyOn(Generator.prototype, 'composeWith')
const writeKeyAppConfig = jest.spyOn(utils, 'writeKeyAppConfig')
beforeAll(() => {
composeWith.mockReturnValue(undefined)
writeKeyAppConfig.mockReturnValue(undefined)
})
beforeEach(() => {
composeWith.mockClear()
writeKeyAppConfig.mockClear()
})
afterAll(() => {
composeWith.mockRestore()
writeKeyAppConfig.mockRestore()
})

jest.mock('@adobe/generator-app-common-lib', () => ({
Expand All @@ -51,6 +56,10 @@ describe('run', () => {
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(path.normalize('add-action/index.js')), expect.any(Object))
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(path.normalize('add-events/index.js')), expect.any(Object))
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(path.normalize('add-web-assets/index.js')), expect.any(Object))

expect(writeKeyAppConfig).toHaveBeenCalledTimes(2)
expect(writeKeyAppConfig).toHaveBeenCalledWith(expect.any(Generator), expect.stringContaining('application.actions'), 'actions')
expect(writeKeyAppConfig).toHaveBeenCalledWith(expect.any(Generator), expect.stringContaining('application.web'), 'web-src')
})

test('--skip-prompt --adobe-services some,string', async () => {
Expand All @@ -61,6 +70,10 @@ describe('run', () => {
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(path.normalize('add-web-assets/index.js')), expect.any(Object))
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(path.normalize('add-action/index.js')), expect.any(Object))
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(path.normalize('add-events/index.js')), expect.any(Object))

expect(writeKeyAppConfig).toHaveBeenCalledTimes(2)
expect(writeKeyAppConfig).toHaveBeenCalledWith(expect.any(Generator), expect.stringContaining('application.actions'), 'actions')
expect(writeKeyAppConfig).toHaveBeenCalledWith(expect.any(Generator), expect.stringContaining('application.web'), 'web-src')
})

test('--adobe-services some,string --supported-adobe-services="" and prompt selection "actions"', async () => {
Expand All @@ -70,6 +83,9 @@ describe('run', () => {

expect(composeWith).toHaveBeenCalledTimes(1)
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(path.normalize('add-action/index.js')), expect.any(Object))

expect(writeKeyAppConfig).toHaveBeenCalledTimes(1)
expect(writeKeyAppConfig).toHaveBeenCalledWith(expect.any(Generator), expect.stringContaining('application.actions'), 'actions')
})

test('--adobe-services some,string and prompt selection "events"', async () => {
Expand All @@ -79,6 +95,8 @@ describe('run', () => {

expect(composeWith).toHaveBeenCalledTimes(1)
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(path.normalize('add-events/index.js')), expect.any(Object))

expect(writeKeyAppConfig).toHaveBeenCalledTimes(0)
})

test('--adobe-services some,string and prompt selection "web-assets"', async () => {
Expand All @@ -88,6 +106,9 @@ describe('run', () => {

expect(composeWith).toHaveBeenCalledTimes(1)
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(path.normalize('add-web-assets/index.js')), expect.any(Object))

expect(writeKeyAppConfig).toHaveBeenCalledTimes(1)
expect(writeKeyAppConfig).toHaveBeenCalledWith(expect.any(Generator), expect.stringContaining('application.web'), 'web-src')
})
test('--adobe-services some,string --supported-adobe-service=some,other,string and prompt selection "web-assets, actions"', async () => {
await helpers.run(theGeneratorPath)
Expand All @@ -97,6 +118,10 @@ describe('run', () => {
expect(composeWith).toHaveBeenCalledTimes(2)
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(path.normalize('add-action/index.js')), expect.any(Object))
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(path.normalize('add-web-assets/index.js')), expect.any(Object))

expect(writeKeyAppConfig).toHaveBeenCalledTimes(2)
expect(writeKeyAppConfig).toHaveBeenCalledWith(expect.any(Generator), expect.stringContaining('application.actions'), 'actions')
expect(writeKeyAppConfig).toHaveBeenCalledWith(expect.any(Generator), expect.stringContaining('application.web'), 'web-src')
})
test('--adobe-services some,string --supported-adobe-service=some,other,string and prompt selection "web-assets, actions, events"', async () => {
await helpers.run(theGeneratorPath)
Expand All @@ -107,6 +132,10 @@ describe('run', () => {
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(path.normalize('add-action/index.js')), expect.any(Object))
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(path.normalize('add-web-assets/index.js')), expect.any(Object))
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(path.normalize('add-events/index.js')), expect.any(Object))

expect(writeKeyAppConfig).toHaveBeenCalledTimes(2)
expect(writeKeyAppConfig).toHaveBeenCalledWith(expect.any(Generator), expect.stringContaining('application.actions'), 'actions')
expect(writeKeyAppConfig).toHaveBeenCalledWith(expect.any(Generator), expect.stringContaining('application.web'), 'web-src')
})
test('--skip-prompt --skip-install', async () => {
await helpers.run(theGeneratorPath)
Expand All @@ -117,5 +146,9 @@ describe('run', () => {
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(path.normalize('add-action/index.js')), expect.any(Object))
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(path.normalize('add-events/index.js')), expect.any(Object))
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(path.normalize('add-web-assets/index.js')), expect.any(Object))

expect(writeKeyAppConfig).toHaveBeenCalledTimes(2)
expect(writeKeyAppConfig).toHaveBeenCalledWith(expect.any(Generator), expect.stringContaining('application.actions'), 'actions')
expect(writeKeyAppConfig).toHaveBeenCalledWith(expect.any(Generator), expect.stringContaining('application.web'), 'web-src')
})
})

0 comments on commit dba9f6a

Please sign in to comment.