Skip to content

Commit f47560a

Browse files
authored
fix: init command - add flag --template-options, unhide flags --org and --project (#883)
* fix: update README for updated app init flags
1 parent dc26a1a commit f47560a

File tree

3 files changed

+107
-10
lines changed

3 files changed

+107
-10
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,15 +539,17 @@ Create a new Adobe I/O App
539539
```
540540
USAGE
541541
$ aio app init [PATH] [-v] [--version] [--install] [-y] [--login] [-e <value>... | -t <value>... | --repo
542-
<value>] [--standalone-app | | ] [-w <value> | -i <value>] [--confirm-new-workspace] [--use-jwt] [--github-pat
543-
<value> ] [--linter none|basic|adobe-recommended]
542+
<value>] [--standalone-app | | ] [--template-options <value>] [-o <value> | -i <value> | ] [-p <value> | | ] [-w
543+
<value> | | ] [--confirm-new-workspace] [--use-jwt] [--github-pat <value> ] [--linter none|basic|adobe-recommended]
544544
545545
ARGUMENTS
546546
PATH [default: .] Path to the app directory
547547
548548
FLAGS
549549
-e, --extension=<value>... Extension point(s) to implement
550550
-i, --import=<value> Import an Adobe I/O Developer Console configuration file
551+
-o, --org=<value> Specify the Adobe Developer Console Org to init from (orgId, or orgCode)
552+
-p, --project=<value> Specify the Adobe Developer Console Project to init from (projectId, or projectName)
551553
-t, --template=<value>... Specify a link to a template that will be installed
552554
-v, --verbose Verbose output
553555
-w, --workspace=<value> [default: Stage] Specify the Adobe Developer Console Workspace to init from,
@@ -561,6 +563,7 @@ FLAGS
561563
--[no-]login Login using your Adobe ID for interacting with Adobe I/O Developer Console
562564
--repo=<value> Init from gh quick-start repo. Expected to be of the form <owner>/<repo>/<path>
563565
--standalone-app Create a stand-alone application
566+
--template-options=<value> Optional template options, as a base64-encoded json string
564567
--use-jwt if the config has both jwt and OAuth Server to Server Credentials (while migrating),
565568
prefer the JWT credentials
566569
--version Show version

src/commands/app/init.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class InitCommand extends TemplatesCommand {
122122
useDefaultValues: flags.yes,
123123
installNpm: flags.install,
124124
installConfig: flags.login,
125+
templateOptions: flags['template-options'],
125126
templates
126127
})
127128
}
@@ -174,6 +175,7 @@ class InitCommand extends TemplatesCommand {
174175
await this.installTemplates({
175176
useDefaultValues: flags.yes,
176177
installNpm: flags.install,
178+
templateOptions: flags['template-options'],
177179
templates
178180
})
179181
}
@@ -456,21 +458,33 @@ InitCommand.flags = {
456458
char: 't',
457459
multiple: true
458460
}),
461+
'template-options': Flags.string({
462+
description: 'Optional template options, as a base64-encoded json string',
463+
parse: input => {
464+
try {
465+
const decoded = Buffer.from(input, 'base64').toString('utf8')
466+
aioLogger.debug(`--template-options: ${input} decoded as ${decoded}`)
467+
return JSON.parse(decoded)
468+
} catch (e) {
469+
throw new Error(`--template-options: ${input} is not a base64 encoded JSON object.`)
470+
}
471+
}
472+
}),
459473
org: Flags.string({
460-
description: 'Specify the Adobe Developer Console Org to init from',
461-
hidden: true,
462-
exclusive: ['import'] // also no-login
474+
description: 'Specify the Adobe Developer Console Org to init from (orgId, or orgCode)',
475+
char: 'o',
476+
exclusive: ['import', 'no-login']
463477
}),
464478
project: Flags.string({
465-
description: 'Specify the Adobe Developer Console Project to init from',
466-
hidden: true,
467-
exclusive: ['import'] // also no-login
479+
description: 'Specify the Adobe Developer Console Project to init from (projectId, or projectName)',
480+
char: 'p',
481+
exclusive: ['import', 'no-login']
468482
}),
469483
workspace: Flags.string({
470484
description: 'Specify the Adobe Developer Console Workspace to init from, defaults to Stage',
471485
default: DEFAULT_WORKSPACE,
472486
char: 'w',
473-
exclusive: ['import'] // also no-login
487+
exclusive: ['import', 'no-login']
474488
}),
475489
'confirm-new-workspace': Flags.boolean({
476490
description: 'Prompt to confirm before creating a new workspace',

test/commands/app/init.test.js

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,20 @@ describe('Command Prototype', () => {
223223

224224
expect(TheCommand.flags.workspace.default).toBe('Stage')
225225
expect(TheCommand.flags.workspace.char).toBe('w')
226-
expect(TheCommand.flags.workspace.exclusive).toEqual(['import'])
226+
expect(TheCommand.flags.workspace.exclusive).toEqual(['import', 'no-login'])
227+
228+
expect(TheCommand.flags.org).toBeDefined()
229+
expect(TheCommand.flags.org.hidden).toBeFalsy()
230+
expect(TheCommand.flags.org.char).toBe('o')
231+
expect(TheCommand.flags.org.exclusive).toEqual(['import', 'no-login'])
232+
233+
expect(TheCommand.flags.project).toBeDefined()
234+
expect(TheCommand.flags.project.hidden).toBeFalsy()
235+
expect(TheCommand.flags.project.char).toBe('p')
236+
expect(TheCommand.flags.project.exclusive).toEqual(['import', 'no-login'])
237+
238+
expect(TheCommand.flags['template-options']).toBeDefined()
239+
expect(TheCommand.flags['template-options'].type).toBe('option')
227240

228241
expect(TheCommand.flags['confirm-new-workspace'].type).toBe('boolean')
229242
expect(TheCommand.flags['confirm-new-workspace'].default).toBe(true)
@@ -801,3 +814,70 @@ describe('dev terms', () => {
801814
await expect(command.run()).rejects.toThrow('The Developer Terms of Service could not be accepted')
802815
})
803816
})
817+
818+
describe('template-options', () => {
819+
test('no flag', async () => {
820+
command.argv = ['--template', 'some-template']
821+
822+
const installOptions = {
823+
installNpm: true,
824+
templates: ['some-template'],
825+
useDefaultValues: false
826+
}
827+
828+
await command.run()
829+
expect(command.installTemplates).toHaveBeenCalledWith(installOptions)
830+
})
831+
832+
test('valid base64', async () => {
833+
const templateOptions = {
834+
text: 'base-text'
835+
}
836+
const base64 = Buffer.from(JSON.stringify(templateOptions)).toString('base64')
837+
command.argv = ['--template', 'some-template', '--template-options', `${base64}`]
838+
839+
const installOptions = {
840+
installNpm: true,
841+
templates: ['some-template'],
842+
useDefaultValues: false,
843+
templateOptions
844+
}
845+
846+
await command.run()
847+
expect(command.installTemplates).toHaveBeenCalledWith(installOptions)
848+
})
849+
850+
test('valid base64 --no-login', async () => {
851+
const templateOptions = {
852+
text: 'base-text'
853+
}
854+
const base64 = Buffer.from(JSON.stringify(templateOptions)).toString('base64')
855+
command.argv = ['--no-login', '--template', 'some-template', '--template-options', `${base64}`]
856+
857+
const installOptions = {
858+
installConfig: false,
859+
installNpm: true,
860+
templates: ['some-template'],
861+
useDefaultValues: false,
862+
templateOptions
863+
}
864+
865+
await command.run()
866+
expect(command.installTemplates).toHaveBeenCalledWith(installOptions)
867+
})
868+
869+
test('invalid base64', async () => {
870+
command.argv = ['--template', 'some-template', '--template-options=%'] // % is an invalid base64 character
871+
872+
expect.assertions(1)
873+
await expect(command.run()).rejects.toThrow('--template-options: % is not a base64 encoded JSON object.')
874+
})
875+
876+
test('malformed json', async () => {
877+
const options = '{' // ew== in base64
878+
command.argv = ['--template', 'some-template', `--template-options=${Buffer.from(options).toString('base64')}`]
879+
880+
expect.assertions(1)
881+
await expect(command.run()).rejects.toThrow('--template-options: ew== is not a base64 encoded JSON object.')
882+
})
883+
})

0 commit comments

Comments
 (0)