diff --git a/src/commands/app/init.js b/src/commands/app/init.js index efa18ee5..07395741 100644 --- a/src/commands/app/init.js +++ b/src/commands/app/init.js @@ -139,7 +139,7 @@ class InitCommand extends AddCommand { } return extList } else { - const choices = cloneDeep(implPromptChoices).filter(i => i.value.name !== 'application') + const choices = cloneDeep(implPromptChoices) // disable extensions that lack required services if (orgSupportedServices) { @@ -241,16 +241,19 @@ class InitCommand extends AddCommand { async runCodeGenerators (flags, extensionPoints, projectName) { let env = yeoman.createEnv() - // first run app generator that will generate the root skeleton - const appGen = env.instantiate(generators['base-app'], { - options: { - 'skip-prompt': flags.yes, - 'project-name': projectName, - // by default yeoman runs the install, we control installation from the app plugin - 'skip-install': true - } - }) - await env.runGenerator(appGen) + const initialGenerators = ['base-app', 'add-ci'] + // first run app generator that will generate the root skeleton + ci + for (const generatorKey of initialGenerators) { + const appGen = env.instantiate(generators[generatorKey], { + options: { + 'skip-prompt': flags.yes, + 'project-name': projectName, + // by default yeoman runs the install, we control installation from the app plugin + 'skip-install': true + } + }) + await env.runGenerator(appGen) + } // Creating new Yeoman env here to workaround an issue where yeoman reuses the conflicter from previous environment. // https://github.com/yeoman/environment/issues/324 diff --git a/test/commands/app/init.test.js b/test/commands/app/init.test.js index ff841df7..81101df3 100644 --- a/test/commands/app/init.test.js +++ b/test/commands/app/init.test.js @@ -65,6 +65,7 @@ function resetMockConsoleCLI () { jest.mock('@adobe/generator-aio-app', () => ({ application: 'fake-gen-application', 'base-app': 'fake-gen-base-app', + 'add-ci': 'fake-gen-add-ci', extensions: { 'dx/excshell/1': 'fake-gen-excshell', 'dx/asset-compute/worker/1': 'fake-gen-nui' @@ -77,7 +78,7 @@ const inquirer = require('inquirer') const mockExtensionPrompt = jest.fn() inquirer.createPromptModule = jest.fn().mockReturnValue(mockExtensionPrompt) const { implPromptChoices } = require('../../../src/lib/defaults') -const extChoices = implPromptChoices.filter(c => c.value.name !== 'application') +const extChoices = implPromptChoices const excshellSelection = [implPromptChoices.find(c => c.value.name === 'dx/excshell/1').value] const assetComputeSelection = [implPromptChoices.find(c => c.value.name === 'dx/asset-compute/worker/1').value] @@ -187,11 +188,15 @@ describe('run', () => { test('--no-login, select excshell', async () => { mockExtensionPrompt.mockReturnValue({ res: excshellSelection }) await TheCommand.run(['--no-login']) - expect(mockGenInstantiate).toHaveBeenCalledTimes(2) + expect(mockGenInstantiate).toHaveBeenCalledTimes(3) expect(mockGenInstantiate).toHaveBeenCalledWith( 'fake-gen-base-app', { options: { 'skip-prompt': false, 'project-name': 'cwd', 'skip-install': true } } ) + expect(mockGenInstantiate).toHaveBeenCalledWith( + 'fake-gen-add-ci', + { options: { 'skip-prompt': false, 'project-name': 'cwd', 'skip-install': true } } + ) expect(mockGenInstantiate).toHaveBeenCalledWith( 'fake-gen-excshell', { options: { 'skip-prompt': false, force: true, 'skip-install': true } } @@ -205,11 +210,15 @@ describe('run', () => { test('--no-login, select excshell, arg: /otherdir', async () => { mockExtensionPrompt.mockReturnValue({ res: excshellSelection }) await TheCommand.run(['--no-login', '/otherdir']) - expect(mockGenInstantiate).toHaveBeenCalledTimes(2) + expect(mockGenInstantiate).toHaveBeenCalledTimes(3) expect(mockGenInstantiate).toHaveBeenCalledWith( 'fake-gen-base-app', { options: { 'skip-prompt': false, 'project-name': 'otherdir', 'skip-install': true } } ) + expect(mockGenInstantiate).toHaveBeenCalledWith( + 'fake-gen-add-ci', + { options: { 'skip-prompt': false, 'project-name': 'otherdir', 'skip-install': true } } + ) expect(mockGenInstantiate).toHaveBeenCalledWith( 'fake-gen-excshell', { options: { 'skip-prompt': false, force: true, 'skip-install': true } } @@ -226,11 +235,15 @@ describe('run', () => { test('--no-login, select both', async () => { mockExtensionPrompt.mockReturnValue({ res: excshellSelection.concat(assetComputeSelection) }) await TheCommand.run(['--no-login']) - expect(mockGenInstantiate).toHaveBeenCalledTimes(3) + expect(mockGenInstantiate).toHaveBeenCalledTimes(4) expect(mockGenInstantiate).toHaveBeenCalledWith( 'fake-gen-base-app', { options: { 'skip-prompt': false, 'project-name': 'cwd', 'skip-install': true } } ) + expect(mockGenInstantiate).toHaveBeenCalledWith( + 'fake-gen-add-ci', + { options: { 'skip-prompt': false, 'project-name': 'cwd', 'skip-install': true } } + ) expect(mockGenInstantiate).toHaveBeenCalledWith( 'fake-gen-excshell', { options: { 'skip-prompt': false, force: true, 'skip-install': true } } @@ -247,11 +260,15 @@ describe('run', () => { test('--no-login --no-extensions', async () => { await TheCommand.run(['--no-login', '--no-extensions']) - expect(mockGenInstantiate).toHaveBeenCalledTimes(2) + expect(mockGenInstantiate).toHaveBeenCalledTimes(3) expect(mockGenInstantiate).toHaveBeenCalledWith( 'fake-gen-base-app', { options: { 'skip-prompt': false, 'project-name': 'cwd', 'skip-install': true } } ) + expect(mockGenInstantiate).toHaveBeenCalledWith( + 'fake-gen-add-ci', + { options: { 'skip-prompt': false, 'project-name': 'cwd', 'skip-install': true } } + ) expect(mockGenInstantiate).toHaveBeenCalledWith( 'fake-gen-application', { options: { 'skip-prompt': false, force: true, 'skip-install': true } } @@ -265,11 +282,15 @@ describe('run', () => { test('--no-login --yes --skip-install, select excshell', async () => { mockExtensionPrompt.mockReturnValue({ res: excshellSelection }) await TheCommand.run(['--no-login', '--yes', '--skip-install']) - expect(mockGenInstantiate).toHaveBeenCalledTimes(2) + expect(mockGenInstantiate).toHaveBeenCalledTimes(3) expect(mockGenInstantiate).toHaveBeenCalledWith( 'fake-gen-base-app', { options: { 'skip-prompt': true, 'project-name': 'cwd', 'skip-install': true } } ) + expect(mockGenInstantiate).toHaveBeenCalledWith( + 'fake-gen-add-ci', + { options: { 'skip-prompt': true, 'project-name': 'cwd', 'skip-install': true } } + ) expect(mockGenInstantiate).toHaveBeenCalledWith( 'fake-gen-excshell', { options: { 'skip-prompt': true, force: true, 'skip-install': true } } @@ -283,11 +304,15 @@ describe('run', () => { test('--no-login --yes --skip-install, --extension dx/asset-compute/worker/1', async () => { mockExtensionPrompt.mockReturnValue({ res: excshellSelection }) await TheCommand.run(['--no-login', '--yes', '--skip-install', '--extension', 'dx/asset-compute/worker/1']) - expect(mockGenInstantiate).toHaveBeenCalledTimes(2) + expect(mockGenInstantiate).toHaveBeenCalledTimes(3) expect(mockGenInstantiate).toHaveBeenCalledWith( 'fake-gen-base-app', { options: { 'skip-prompt': true, 'project-name': 'cwd', 'skip-install': true } } ) + expect(mockGenInstantiate).toHaveBeenCalledWith( + 'fake-gen-add-ci', + { options: { 'skip-prompt': true, 'project-name': 'cwd', 'skip-install': true } } + ) expect(mockGenInstantiate).toHaveBeenCalledWith( 'fake-gen-nui', { options: { 'skip-prompt': true, force: true, 'skip-install': true } } @@ -333,11 +358,15 @@ describe('run', () => { mockImport.loadAndValidateConfigFile.mockReturnValue({ values: fakeConfig }) mockExtensionPrompt.mockReturnValue({ res: excshellSelection }) await TheCommand.run(['--import', 'fakeconfig.json']) - expect(mockGenInstantiate).toHaveBeenCalledTimes(2) + expect(mockGenInstantiate).toHaveBeenCalledTimes(3) expect(mockGenInstantiate).toHaveBeenCalledWith( 'fake-gen-base-app', { options: { 'skip-prompt': false, 'project-name': 'hola', 'skip-install': true } } ) + expect(mockGenInstantiate).toHaveBeenCalledWith( + 'fake-gen-add-ci', + { options: { 'skip-prompt': false, 'project-name': 'hola', 'skip-install': true } } + ) expect(mockGenInstantiate).toHaveBeenCalledWith( 'fake-gen-excshell', { options: { 'skip-prompt': false, force: true, 'skip-install': true } } @@ -357,11 +386,15 @@ describe('run', () => { mockImport.loadAndValidateConfigFile.mockReturnValue({ values: fakeConfigNoCredentials }) mockExtensionPrompt.mockReturnValue({ res: excshellSelection }) await TheCommand.run(['--import', 'fakeconfig.json']) - expect(mockGenInstantiate).toHaveBeenCalledTimes(2) + expect(mockGenInstantiate).toHaveBeenCalledTimes(3) expect(mockGenInstantiate).toHaveBeenCalledWith( 'fake-gen-base-app', { options: { 'skip-prompt': false, 'project-name': 'hola', 'skip-install': true } } ) + expect(mockGenInstantiate).toHaveBeenCalledWith( + 'fake-gen-add-ci', + { options: { 'skip-prompt': false, 'project-name': 'hola', 'skip-install': true } } + ) expect(mockGenInstantiate).toHaveBeenCalledWith( 'fake-gen-excshell', { options: { 'skip-prompt': false, force: true, 'skip-install': true } } @@ -395,11 +428,15 @@ describe('run', () => { mockExtensionPrompt.mockReturnValue({ res: excshellSelection }) await TheCommand.run([]) - expect(mockGenInstantiate).toHaveBeenCalledTimes(2) + expect(mockGenInstantiate).toHaveBeenCalledTimes(3) expect(mockGenInstantiate).toHaveBeenCalledWith( 'fake-gen-base-app', { options: { 'skip-prompt': false, 'project-name': 'hola', 'skip-install': true } } ) + expect(mockGenInstantiate).toHaveBeenCalledWith( + 'fake-gen-add-ci', + { options: { 'skip-prompt': false, 'project-name': 'hola', 'skip-install': true } } + ) expect(mockGenInstantiate).toHaveBeenCalledWith( 'fake-gen-excshell', { options: { 'skip-prompt': false, force: true, 'skip-install': true } } @@ -429,11 +466,15 @@ describe('run', () => { mockExtensionPrompt.mockReturnValue({ res: assetComputeSelection }) await TheCommand.run([]) - expect(mockGenInstantiate).toHaveBeenCalledTimes(2) + expect(mockGenInstantiate).toHaveBeenCalledTimes(3) expect(mockGenInstantiate).toHaveBeenCalledWith( 'fake-gen-base-app', { options: { 'skip-prompt': false, 'project-name': 'hola', 'skip-install': true } } ) + expect(mockGenInstantiate).toHaveBeenCalledWith( + 'fake-gen-add-ci', + { options: { 'skip-prompt': false, 'project-name': 'hola', 'skip-install': true } } + ) expect(mockGenInstantiate).toHaveBeenCalledWith( 'fake-gen-nui', { options: { 'skip-prompt': false, force: true, 'skip-install': true } } @@ -469,11 +510,15 @@ describe('run', () => { mockExtensionPrompt.mockReturnValue({ res: excshellSelection }) await TheCommand.run([]) - expect(mockGenInstantiate).toHaveBeenCalledTimes(2) + expect(mockGenInstantiate).toHaveBeenCalledTimes(3) expect(mockGenInstantiate).toHaveBeenCalledWith( 'fake-gen-base-app', { options: { 'skip-prompt': false, 'project-name': 'hola', 'skip-install': true } } ) + expect(mockGenInstantiate).toHaveBeenCalledWith( + 'fake-gen-add-ci', + { options: { 'skip-prompt': false, 'project-name': 'hola', 'skip-install': true } } + ) expect(mockGenInstantiate).toHaveBeenCalledWith( 'fake-gen-excshell', { options: { 'skip-prompt': false, force: true, 'skip-install': true } } @@ -485,10 +530,12 @@ describe('run', () => { choices: [ // exc shell extChoices[0], + extChoices[1], // disabled nui expect.objectContaining({ disabled: true, - name: expect.stringContaining('missing service(s) in Org: \'AssetComputeSDK\'') + name: expect.stringContaining('missing service(s) in Org: \'AssetComputeSDK\''), + value: expect.any(Object) }) ] })]) @@ -515,11 +562,15 @@ describe('run', () => { mockConsoleCLIInstance.promptForCreateProjectDetails.mockResolvedValue('fakedetails') mockExtensionPrompt.mockReturnValue({ res: excshellSelection }) await TheCommand.run([]) - expect(mockGenInstantiate).toHaveBeenCalledTimes(2) + expect(mockGenInstantiate).toHaveBeenCalledTimes(3) expect(mockGenInstantiate).toHaveBeenCalledWith( 'fake-gen-base-app', { options: { 'skip-prompt': false, 'project-name': 'hola', 'skip-install': true } } ) + expect(mockGenInstantiate).toHaveBeenCalledWith( + 'fake-gen-add-ci', + { options: { 'skip-prompt': false, 'project-name': 'hola', 'skip-install': true } } + ) expect(mockGenInstantiate).toHaveBeenCalledWith( 'fake-gen-excshell', { options: { 'skip-prompt': false, force: true, 'skip-install': true } } @@ -551,11 +602,15 @@ describe('run', () => { mockExtensionPrompt.mockReturnValue({}) await TheCommand.run(['--extension', 'dx/excshell/1']) - expect(mockGenInstantiate).toHaveBeenCalledTimes(2) + expect(mockGenInstantiate).toHaveBeenCalledTimes(3) expect(mockGenInstantiate).toHaveBeenCalledWith( 'fake-gen-base-app', { options: { 'skip-prompt': false, 'project-name': 'hola', 'skip-install': true } } ) + expect(mockGenInstantiate).toHaveBeenCalledWith( + 'fake-gen-add-ci', + { options: { 'skip-prompt': false, 'project-name': 'hola', 'skip-install': true } } + ) expect(mockGenInstantiate).toHaveBeenCalledWith( 'fake-gen-excshell', { options: { 'skip-prompt': false, force: true, 'skip-install': true } } @@ -585,11 +640,15 @@ describe('run', () => { mockExtensionPrompt.mockReturnValue({ res: excshellSelection }) await TheCommand.run(['-w', 'dev']) - expect(mockGenInstantiate).toHaveBeenCalledTimes(2) + expect(mockGenInstantiate).toHaveBeenCalledTimes(3) expect(mockGenInstantiate).toHaveBeenCalledWith( 'fake-gen-base-app', { options: { 'skip-prompt': false, 'project-name': 'hola', 'skip-install': true } } ) + expect(mockGenInstantiate).toHaveBeenCalledWith( + 'fake-gen-add-ci', + { options: { 'skip-prompt': false, 'project-name': 'hola', 'skip-install': true } } + ) expect(mockGenInstantiate).toHaveBeenCalledWith( 'fake-gen-excshell', { options: { 'skip-prompt': false, force: true, 'skip-install': true } }