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
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -539,15 +539,17 @@ Create a new Adobe I/O App
```
USAGE
$ aio app init [PATH] [-v] [--version] [--install] [-y] [--login] [-e <value>... | -t <value>... | --repo
<value>] [--standalone-app | | ] [-w <value> | -i <value>] [--confirm-new-workspace] [--use-jwt] [--github-pat
<value> ] [--linter none|basic|adobe-recommended]
<value>] [--standalone-app | | ] [--template-options <value>] [-o <value> | -i <value> | ] [-p <value> | | ] [-w
<value> | | ] [--confirm-new-workspace] [--use-jwt] [--github-pat <value> ] [--linter none|basic|adobe-recommended]

ARGUMENTS
PATH [default: .] Path to the app directory

FLAGS
-e, --extension=<value>... Extension point(s) to implement
-i, --import=<value> Import an Adobe I/O Developer Console configuration file
-o, --org=<value> Specify the Adobe Developer Console Org to init from (orgId, or orgCode)
-p, --project=<value> Specify the Adobe Developer Console Project to init from (projectId, or projectName)
Comment thread
shazron marked this conversation as resolved.
-t, --template=<value>... Specify a link to a template that will be installed
-v, --verbose Verbose output
-w, --workspace=<value> [default: Stage] Specify the Adobe Developer Console Workspace to init from,
Expand All @@ -561,6 +563,7 @@ FLAGS
--[no-]login Login using your Adobe ID for interacting with Adobe I/O Developer Console
--repo=<value> Init from gh quick-start repo. Expected to be of the form <owner>/<repo>/<path>
--standalone-app Create a stand-alone application
--template-options=<value> Optional template options, as a base64-encoded json string
--use-jwt if the config has both jwt and OAuth Server to Server Credentials (while migrating),
prefer the JWT credentials
--version Show version
Expand Down
28 changes: 21 additions & 7 deletions src/commands/app/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class InitCommand extends TemplatesCommand {
useDefaultValues: flags.yes,
installNpm: flags.install,
installConfig: flags.login,
templateOptions: flags['template-options'],
templates
})
}
Expand Down Expand Up @@ -174,6 +175,7 @@ class InitCommand extends TemplatesCommand {
await this.installTemplates({
useDefaultValues: flags.yes,
installNpm: flags.install,
templateOptions: flags['template-options'],
templates
})
}
Expand Down Expand Up @@ -456,21 +458,33 @@ InitCommand.flags = {
char: 't',
multiple: true
}),
'template-options': Flags.string({
description: 'Optional template options, as a base64-encoded json string',
parse: input => {
try {
const decoded = Buffer.from(input, 'base64').toString('utf8')
aioLogger.debug(`--template-options: ${input} decoded as ${decoded}`)
return JSON.parse(decoded)
} catch (e) {
throw new Error(`--template-options: ${input} is not a base64 encoded JSON object.`)
}
}
}),
org: Flags.string({
description: 'Specify the Adobe Developer Console Org to init from',
hidden: true,
exclusive: ['import'] // also no-login
description: 'Specify the Adobe Developer Console Org to init from (orgId, or orgCode)',
char: 'o',
exclusive: ['import', 'no-login']
}),
project: Flags.string({
description: 'Specify the Adobe Developer Console Project to init from',
hidden: true,
exclusive: ['import'] // also no-login
description: 'Specify the Adobe Developer Console Project to init from (projectId, or projectName)',
char: 'p',
exclusive: ['import', 'no-login']
}),
workspace: Flags.string({
description: 'Specify the Adobe Developer Console Workspace to init from, defaults to Stage',
default: DEFAULT_WORKSPACE,
char: 'w',
exclusive: ['import'] // also no-login
exclusive: ['import', 'no-login']
}),
'confirm-new-workspace': Flags.boolean({
description: 'Prompt to confirm before creating a new workspace',
Expand Down
82 changes: 81 additions & 1 deletion test/commands/app/init.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,20 @@ describe('Command Prototype', () => {

expect(TheCommand.flags.workspace.default).toBe('Stage')
expect(TheCommand.flags.workspace.char).toBe('w')
expect(TheCommand.flags.workspace.exclusive).toEqual(['import'])
expect(TheCommand.flags.workspace.exclusive).toEqual(['import', 'no-login'])

expect(TheCommand.flags.org).toBeDefined()
expect(TheCommand.flags.org.hidden).toBeFalsy()
expect(TheCommand.flags.org.char).toBe('o')
expect(TheCommand.flags.org.exclusive).toEqual(['import', 'no-login'])

expect(TheCommand.flags.project).toBeDefined()
expect(TheCommand.flags.project.hidden).toBeFalsy()
expect(TheCommand.flags.project.char).toBe('p')
expect(TheCommand.flags.project.exclusive).toEqual(['import', 'no-login'])

expect(TheCommand.flags['template-options']).toBeDefined()
expect(TheCommand.flags['template-options'].type).toBe('option')

expect(TheCommand.flags['confirm-new-workspace'].type).toBe('boolean')
expect(TheCommand.flags['confirm-new-workspace'].default).toBe(true)
Expand Down Expand Up @@ -801,3 +814,70 @@ describe('dev terms', () => {
await expect(command.run()).rejects.toThrow('The Developer Terms of Service could not be accepted')
})
})

describe('template-options', () => {
test('no flag', async () => {
command.argv = ['--template', 'some-template']

const installOptions = {
installNpm: true,
templates: ['some-template'],
useDefaultValues: false
}

await command.run()
expect(command.installTemplates).toHaveBeenCalledWith(installOptions)
})

test('valid base64', async () => {
const templateOptions = {
text: 'base-text'
}
const base64 = Buffer.from(JSON.stringify(templateOptions)).toString('base64')
command.argv = ['--template', 'some-template', '--template-options', `${base64}`]

const installOptions = {
installNpm: true,
templates: ['some-template'],
useDefaultValues: false,
templateOptions
}

await command.run()
expect(command.installTemplates).toHaveBeenCalledWith(installOptions)
})

test('valid base64 --no-login', async () => {
const templateOptions = {
text: 'base-text'
}
const base64 = Buffer.from(JSON.stringify(templateOptions)).toString('base64')
command.argv = ['--no-login', '--template', 'some-template', '--template-options', `${base64}`]

const installOptions = {
installConfig: false,
installNpm: true,
templates: ['some-template'],
useDefaultValues: false,
templateOptions
}

await command.run()
expect(command.installTemplates).toHaveBeenCalledWith(installOptions)
})

test('invalid base64', async () => {
command.argv = ['--template', 'some-template', '--template-options=%'] // % is an invalid base64 character

expect.assertions(1)
await expect(command.run()).rejects.toThrow('--template-options: % is not a base64 encoded JSON object.')
})

test('malformed json', async () => {
const options = '{' // ew== in base64
command.argv = ['--template', 'some-template', `--template-options=${Buffer.from(options).toString('base64')}`]

expect.assertions(1)
await expect(command.run()).rejects.toThrow('--template-options: ew== is not a base64 encoded JSON object.')
})
})
Loading