Skip to content
Open
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
33 changes: 19 additions & 14 deletions src/BaseCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class BaseCommand extends Command {
}

async getAppExtConfigs (flags, options = {}) {
const all = (await this.getFullConfig(options)).all
const all = (await this.getFullConfig(options, flags)).all

// default case: no flags, return all
let ret = all
Expand Down Expand Up @@ -96,41 +96,41 @@ class BaseCommand extends Command {
return ret
}

async getRuntimeManifestConfigFile (implName) {
async getRuntimeManifestConfigFile (implName, flags) {
let configKey
if (implName === APPLICATION_CONFIG_KEY) {
configKey = APPLICATION_CONFIG_KEY
} else {
configKey = `${EXTENSIONS_CONFIG_KEY}.${implName}`
}
let configData = await this.getConfigFileForKey(`${configKey}.runtimeManifest`)
let configData = await this.getConfigFileForKey(`${configKey}.runtimeManifest`, flags)
if (!configData.file) {
// first action manifest is not defined
configData = await this.getConfigFileForKey(`${configKey}`)
configData = await this.getConfigFileForKey(`${configKey}`, flags)
configData.key = configData.key + '.runtimeManifest'
}
return configData
}

async getEventsConfigFile (implName) {
async getEventsConfigFile (implName, flags) {
let configKey
if (implName === APPLICATION_CONFIG_KEY) {
configKey = APPLICATION_CONFIG_KEY
} else {
configKey = `${EXTENSIONS_CONFIG_KEY}.${implName}`
}
let configData = await this.getConfigFileForKey(`${configKey}.events`)
let configData = await this.getConfigFileForKey(`${configKey}.events`, flags)
if (!configData.file) {
// first events manifest is not defined
configData = await this.getConfigFileForKey(`${configKey}`)
configData = await this.getConfigFileForKey(`${configKey}`, flags)
configData.key = configData.key + '.events'
}
return configData
}

async getConfigFileForKey (fullKey) {
async getConfigFileForKey (fullKey, flags = {}) {
// NOTE: the index returns undefined if the key is loaded from a legacy configuration file
const fullConfig = await this.getFullConfig()
const fullConfig = await this.getFullConfig({}, flags)
// full key like 'extensions.dx/excshell/1.runtimeManifest'
// returns { key: relKey, file: configFile}
const configData = fullConfig.includeIndex[fullKey]
Expand All @@ -142,12 +142,12 @@ class BaseCommand extends Command {
return configData || {}
}

async getFullConfig (options = {}) {
// validate appConfig defaults to false for now
const validateAppConfig = options.validateAppConfig === true
async getFullConfig (options = {}, flags = {}) {
// validate appConfig defaults to true unless flag is explicitly set to off
const validateAppConfig = flags['config-validation'] !== false
aioLogger.debug(`validateAppConfig=${validateAppConfig}`)

if (!this.appConfig) {
// this will explicitly set validateAppConfig=false if not set
this.appConfig = await appConfig.load({ ...options, validateAppConfig })
}
return this.appConfig
Expand Down Expand Up @@ -191,7 +191,12 @@ class BaseCommand extends Command {

BaseCommand.flags = {
verbose: Flags.boolean({ char: 'v', description: 'Verbose output' }),
version: Flags.boolean({ description: 'Show version' })
version: Flags.boolean({ description: 'Show version' }),
'config-validation': Flags.boolean({
description: '[default: true] Validate the app configuration file(s) before continuing.',
default: true,
allowNo: true
})
}

BaseCommand.args = {}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/app/add/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AddActionCommand extends TemplatesCommand {
const config = entries[0][1]

const actionFolder = path.relative(config.root, config.actions.src)
const configData = await this.getRuntimeManifestConfigFile(configName)
const configData = await this.getRuntimeManifestConfigFile(configName, flags)

const projectOrgId = aioConfigLoader.get('project.org.id')
if (!projectOrgId) {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/app/add/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class AddEventCommand extends TemplatesCommand {
const configName = entries[0][0]
const config = entries[0][1]
const actionFolder = path.relative(config.root, config.actions.src)
const runtimeManifestData = await this.getRuntimeManifestConfigFile(configName)
const eventsData = await this.getEventsConfigFile(configName)
const runtimeManifestData = await this.getRuntimeManifestConfigFile(configName, flags)
const eventsData = await this.getEventsConfigFile(configName, flags)
const templateOptions = {
'skip-prompt': false,
'action-folder': actionFolder,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/app/add/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class AddExtensionCommand extends TemplatesCommand {
this.error('--extension= must also be provided when using --yes')
}

const fullConfig = await this.getFullConfig({ allowNoImpl: true })
const fullConfig = await this.getFullConfig({ allowNoImpl: true }, flags)
const alreadyImplemented = fullConfig.implements

if (flags.extension) {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/app/add/web-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AddWebAssetsCommand extends TemplatesCommand {
const { flags } = await this.parse(AddWebAssetsCommand)
aioLogger.debug(`add web-assets with flags: ${JSON.stringify(flags)}`)

const projectName = (await this.getFullConfig()).packagejson.name
const projectName = (await this.getFullConfig({}, flags)).packagejson.name
// guaranteed to have at least one, otherwise would throw in config load or in matching the ext name
const entries = Object.entries(await this.getAppExtConfigs(flags))
if (entries.length > 1) {
Expand Down
7 changes: 6 additions & 1 deletion src/commands/app/config/get/log-forwarding.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const { setRuntimeApiHostAndAuthHandler } = require('../../../../lib/auth-helper

class LogForwardingCommand extends BaseCommand {
async run () {
let aioConfig = (await this.getFullConfig()).aio
const { flags } = await this.parse(LogForwardingCommand)
let aioConfig = (await this.getFullConfig({}, flags)).aio
aioConfig = setRuntimeApiHostAndAuthHandler(aioConfig)
const lf = await LogForwarding.init(aioConfig)

Expand Down Expand Up @@ -50,4 +51,8 @@ class LogForwardingCommand extends BaseCommand {
LogForwardingCommand.description = 'Get log forwarding destination configuration'
LogForwardingCommand.aliases = ['app:config:get:log-forwarding', 'app:config:get:lf']

LogForwardingCommand.flags = {
...BaseCommand.flags
}

module.exports = LogForwardingCommand
10 changes: 7 additions & 3 deletions src/commands/app/config/get/log-forwarding/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ const { setRuntimeApiHostAndAuthHandler } = require('../../../../../lib/auth-hel

class ErrorsCommand extends BaseCommand {
async run () {
const { flags } = await this.parse(ErrorsCommand)
const spinner = ora()
const lf = await this.getLogForwarding()
const lf = await this.getLogForwarding(flags)
spinner.start('Checking for errors...')
const res = await lf.getErrors()
const destinationMessage = res.configured_forwarder !== undefined
Expand All @@ -30,8 +31,8 @@ class ErrorsCommand extends BaseCommand {
}
}

async getLogForwarding () {
let aioConfig = (await this.getFullConfig()).aio
async getLogForwarding (flags) {
let aioConfig = (await this.getFullConfig({}, flags)).aio
aioConfig = setRuntimeApiHostAndAuthHandler(aioConfig)

const runtimeConfig = aioConfig.runtime
Expand All @@ -46,5 +47,8 @@ class ErrorsCommand extends BaseCommand {

ErrorsCommand.description = 'Get log forwarding errors'
ErrorsCommand.aliases = ['app:config:get:log-forwarding:errors', 'app:config:get:lf:errors']
ErrorsCommand.flags = {
...BaseCommand.flags
}

module.exports = ErrorsCommand
6 changes: 5 additions & 1 deletion src/commands/app/config/set/log-forwarding.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const { setRuntimeApiHostAndAuthHandler } = require('../../../../lib/auth-helper

class LogForwardingCommand extends BaseCommand {
async run () {
let aioConfig = (await this.getFullConfig()).aio
const { flags } = await this.parse(LogForwardingCommand)
let aioConfig = (await this.getFullConfig({}, flags)).aio
aioConfig = setRuntimeApiHostAndAuthHandler(aioConfig)
const lf = await LogForwarding.init(aioConfig)

Expand Down Expand Up @@ -50,5 +51,8 @@ class LogForwardingCommand extends BaseCommand {

LogForwardingCommand.description = 'Set log forwarding destination configuration'
LogForwardingCommand.aliases = ['app:config:set:log-forwarding', 'app:config:set:lf']
LogForwardingCommand.flags = {
...BaseCommand.flags
}

module.exports = LogForwardingCommand
22 changes: 11 additions & 11 deletions src/commands/app/delete/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class DeleteActionCommand extends BaseCommand {
this.error('<action-name> must also be provided when using --yes')
}

const fullConfig = await this.getFullConfig()
const { actions, actionsByImpl } = await this.getAllActions(fullConfig)
const fullConfig = await this.getFullConfig({}, flags)
const { actions, actionsByImpl } = await this.getAllActions(fullConfig, flags)
if (actions.length <= 0) {
this.error('There are no actions in this project!')
}
Expand Down Expand Up @@ -108,7 +108,7 @@ class DeleteActionCommand extends BaseCommand {
)))
}

async getAllActions (config) {
async getAllActions (config, flags = {}) {
const actions = []
const actionsByImpl = {}
const allConfigEntries = Object.entries(config.all)
Expand All @@ -121,7 +121,7 @@ class DeleteActionCommand extends BaseCommand {
for (const [actionName, action] of actionEntries) {
const fullActionName = `${pkgName}/${actionName}`
const startKey = implName === 'application' ? 'application' : `extensions.${implName}`
const configData = await this.getConfigFileForKey(`${startKey}.runtimeManifest.packages.${pkgName}.actions.${actionName}`)
const configData = await this.getConfigFileForKey(`${startKey}.runtimeManifest.packages.${pkgName}.actions.${actionName}`, flags)
const actionObj = {
// assumes path is not relative
path: action.function,
Expand Down Expand Up @@ -157,13 +157,13 @@ DeleteActionCommand.flags = {
}

DeleteActionCommand.args =
{
'action-name': Args.string({
description: 'Action `pkg/name` to delete, you can specify multiple actions via a comma separated list',
default: '',
required: false
})
}
{
'action-name': Args.string({
description: 'Action `pkg/name` to delete, you can specify multiple actions via a comma separated list',
default: '',
required: false
})
}

DeleteActionCommand.aliases = ['app:delete:actions']

Expand Down
10 changes: 5 additions & 5 deletions src/commands/app/delete/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class DeleteExtensionCommand extends BaseCommand {
this.error('--extension= must also be provided when using --yes')
}

const fullConfig = await this.getFullConfig({ allowNoImpl: true })
const fullConfig = await this.getFullConfig({ allowNoImpl: true }, flags)
const configs = await this.selectOrGetConfigsToDelete(flags, fullConfig)

const resConfirm = await this.prompt([
Expand All @@ -44,7 +44,7 @@ class DeleteExtensionCommand extends BaseCommand {
this.error('aborting..')
}

await this.deleteImplementations(configs)
await this.deleteImplementations(configs, flags)

this.log(chalk.bold(chalk.green(
`✔ Successfully deleted implementation(s) '${Object.keys(configs)}'` + EOL +
Expand All @@ -71,7 +71,7 @@ class DeleteExtensionCommand extends BaseCommand {
return await this.getAppExtConfigs(flags)
}

async deleteImplementations (configs) {
async deleteImplementations (configs, flags) {
for (const [id, c] of Object.entries(configs)) {
// delete actions
if (c.app.hasBackend) {
Expand All @@ -89,12 +89,12 @@ class DeleteExtensionCommand extends BaseCommand {
// delete config
// try to find another config file => case of init extension in another folder
const configKey = id === 'application' ? 'application' : `extensions.${id}`
const configDataOp = await this.getConfigFileForKey(configKey + '.operations')
const configDataOp = await this.getConfigFileForKey(configKey + '.operations', flags)
if (configDataOp.file) {
fs.removeSync(configDataOp.file)
}
// delete config in parent config file
const configData = await this.getConfigFileForKey(configKey)
const configData = await this.getConfigFileForKey(configKey, flags)
deleteUserConfig(configData)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/app/delete/web-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DeleteWebAssetsCommand extends BaseCommand {

aioLogger.debug(`deleting web assets from the project, using flags: ${JSON.stringify(flags)}`)

const fullConfig = await this.getFullConfig()
const fullConfig = await this.getFullConfig({}, flags)
const webAssetsByImpl = this.getAllWebAssets(fullConfig)
if (!webAssetsByImpl) {
this.error('web-assets not found')
Expand Down
2 changes: 1 addition & 1 deletion src/commands/app/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Deploy extends BuildCommand {
const spinner = ora()

try {
const { aio: aioConfig, packagejson: packageJson } = await this.getFullConfig()
const { aio: aioConfig, packagejson: packageJson } = await this.getFullConfig({}, flags)
const cliDetails = await getAccessToken({ useCachedToken: !flags.publish })
const appInfo = {
name: packageJson.name,
Expand Down
10 changes: 5 additions & 5 deletions src/commands/app/get-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class GetUrlCommand extends BaseCommand {
options.cdn = flags.cdn

const urls = {}
const fullConfig = await this.getFullConfig()
const fullConfig = await this.getFullConfig({}, flags)
if (options.action) {
let action
// search for action
Expand Down Expand Up @@ -107,9 +107,9 @@ GetUrlCommand.flags = {
}

GetUrlCommand.args =
{
action: Args.string({
})
}
{
action: Args.string({
})
}

module.exports = GetUrlCommand
2 changes: 1 addition & 1 deletion src/commands/app/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Info extends BaseCommand {
async run () {
// cli input
const { flags } = await this.parse(Info)
const appConfig = deepCopy(await this.getFullConfig({ allowNoImpl: true }))
const appConfig = deepCopy(await this.getFullConfig({ allowNoImpl: true }, flags))

// includes .env secret delete all aio config for now
delete appConfig.aio
Expand Down
2 changes: 1 addition & 1 deletion src/commands/app/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Logs extends BaseCommand {

async run () {
const { flags } = await this.parse(Logs)
const fullConfig = await this.getFullConfig()
const fullConfig = await this.getFullConfig({}, flags)

// has any backend
const hasAnyBackend = Object.values(fullConfig.all).reduce((hasBackend, config) => hasBackend && config.app.hasBackend, true)
Expand Down
12 changes: 6 additions & 6 deletions src/commands/app/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,11 @@ Pack.flags = {
}

Pack.args =
{
path: Args.string({
description: 'Path to the app directory to package',
default: '.'
})
}
{
path: Args.string({
description: 'Path to the app directory to package',
default: '.'
})
}

module.exports = Pack
3 changes: 2 additions & 1 deletion src/commands/app/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Test extends BaseCommand {
unit = true
}

const buildConfigs = await this.getAppExtConfigs({ extension })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a comment on your code but previous code: not sure how the previous code worked since it shouldn't. The unit tests didn't catch this https://github.com/adobe/aio-cli-plugin-app/blob/master/test/commands/app/test.test.js

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wild! What was the issue?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be a red herring.
At first glance aio app test should not have worked, basically - the first param should be flags (object) - you pass in all the flags, but { extension } (object) is passed. But it's just the call is passing in only the extension flag itself.

const buildConfigs = await this.getAppExtConfigs(flags, { extension })
aioLogger.debug(`run buildConfigs:${JSON.stringify(buildConfigs, null, 2)}`)

const totalResults = []
Expand Down Expand Up @@ -202,6 +202,7 @@ class Test extends BaseCommand {
}

Test.flags = {
...BaseCommand.flags,
extension: Flags.string({
char: 'e',
description: 'the extension(s) to test',
Expand Down
2 changes: 1 addition & 1 deletion src/commands/app/undeploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Undeploy extends BaseCommand {

const spinner = ora()
try {
const { aio: aioConfig, packagejson: packageJson } = await this.getFullConfig()
const { aio: aioConfig, packagejson: packageJson } = await this.getFullConfig({}, flags)
const cliDetails = await getAccessToken({ useCachedToken: !flags.unpublish })
const appInfo = {
name: packageJson.name,
Expand Down
Loading