Skip to content

Commit

Permalink
feat: [ACNA-1249][ACNA-1251] Bootstrap extensions XOR extensionless &…
Browse files Browse the repository at this point in the history
… Add GH actions by default on init (#486)
  • Loading branch information
florind-ens authored Oct 13, 2021
1 parent 6fcbc23 commit 2f6e94e
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 27 deletions.
25 changes: 14 additions & 11 deletions src/commands/app/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
91 changes: 75 additions & 16 deletions test/commands/app/init.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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]

Expand Down Expand Up @@ -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 } }
Expand All @@ -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 } }
Expand All @@ -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 } }
Expand All @@ -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 } }
Expand All @@ -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 } }
Expand All @@ -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 } }
Expand Down Expand Up @@ -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 } }
Expand All @@ -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 } }
Expand Down Expand Up @@ -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 } }
Expand Down Expand Up @@ -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 } }
Expand Down Expand Up @@ -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 } }
Expand All @@ -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)
})
]
})])
Expand All @@ -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 } }
Expand Down Expand Up @@ -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 } }
Expand Down Expand Up @@ -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 } }
Expand Down

0 comments on commit 2f6e94e

Please sign in to comment.