diff --git a/packages/core/src/awsService/appBuilder/explorer/openTemplate.ts b/packages/core/src/awsService/appBuilder/explorer/openTemplate.ts index a01b4becaed..c29bdeffce4 100644 --- a/packages/core/src/awsService/appBuilder/explorer/openTemplate.ts +++ b/packages/core/src/awsService/appBuilder/explorer/openTemplate.ts @@ -5,7 +5,7 @@ import { samSyncUrl } from '../../../shared/constants' import { CloudFormationTemplateRegistry } from '../../../shared/fs/templateRegistry' -import { SYNC_MEMENTO_ROOT_KEY } from '../../../shared/sam/constants' +import { syncMementoRootKey } from '../../../shared/sam/constants' import { createExitPrompter } from '../../../shared/ui/common/exitPrompter' import { createTemplatePrompter, TemplateItem } from '../../../shared/ui/sam/templatePrompter' import { Wizard } from '../../../shared/wizards/wizard' @@ -17,6 +17,6 @@ export interface OpenTemplateParams { export class OpenTemplateWizard extends Wizard { public constructor(state: Partial, registry: CloudFormationTemplateRegistry) { super({ initState: state, exitPrompterProvider: createExitPrompter }) - this.form.template.bindPrompter(() => createTemplatePrompter(registry, SYNC_MEMENTO_ROOT_KEY, samSyncUrl)) + this.form.template.bindPrompter(() => createTemplatePrompter(registry, syncMementoRootKey, samSyncUrl)) } } diff --git a/packages/core/src/shared/sam/build.ts b/packages/core/src/shared/sam/build.ts index c4761c33141..750f6250d4d 100644 --- a/packages/core/src/shared/sam/build.ts +++ b/packages/core/src/shared/sam/build.ts @@ -32,7 +32,7 @@ import { } from './utils' import { getConfigFileUri, validateSamBuildConfig } from './config' import { runInTerminal } from './processTerminal' -import { BUILD_MEMENTO_ROOT_KEY } from './constants' +import { buildMementoRootKey } from './constants' export interface BuildParams { readonly template: TemplateItem @@ -140,7 +140,7 @@ export class BuildWizard extends Wizard { if (this.arg === undefined) { // "Build" command was invoked on the command palette. this.form.template.bindPrompter(() => - createTemplatePrompter(this.registry, BUILD_MEMENTO_ROOT_KEY, samBuildUrl) + createTemplatePrompter(this.registry, buildMementoRootKey, samBuildUrl) ) this.form.projectRoot.setDefault(({ template }) => getProjectRoot(template)) this.form.paramsSource.bindPrompter(async ({ projectRoot }) => { @@ -232,7 +232,7 @@ export async function runBuild(arg?: TreeNode): Promise { const templatePath = params.template.uri.fsPath buildFlags.push('--template', `${templatePath}`) - await updateRecentResponse(BUILD_MEMENTO_ROOT_KEY, 'global', 'templatePath', templatePath) + await updateRecentResponse(buildMementoRootKey, 'global', 'templatePath', templatePath) try { await vscode.window.withProgress( diff --git a/packages/core/src/shared/sam/constants.ts b/packages/core/src/shared/sam/constants.ts index e216a1e78d1..ac0d66f75ba 100644 --- a/packages/core/src/shared/sam/constants.ts +++ b/packages/core/src/shared/sam/constants.ts @@ -1,12 +1,10 @@ -/* eslint-disable header/header */ -/* eslint-disable @typescript-eslint/naming-convention */ /*! * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -export const BUILD_PROCESS_MEMENTO_ROOT_KEY = 'samcli.build.processes' -export const GLOBAL_IDENTIFIER = 'global' -export const BUILD_MEMENTO_ROOT_KEY = 'samcli.build.params' -export const DEPLOY_MEMENTO_ROOT_KEY = 'samcli.deploy.params' -export const SYNC_MEMENTO_ROOT_KEY = 'samcli.sync.params' +export const buildProcessMementoRootKey = 'samcli.build.processes' +export const globalIdentifier = 'global' +export const buildMementoRootKey = 'samcli.build.params' +export const deployMementoRootKey = 'samcli.deploy.params' +export const syncMementoRootKey = 'samcli.sync.params' diff --git a/packages/core/src/shared/sam/deploy.ts b/packages/core/src/shared/sam/deploy.ts index ab0d6710869..0733cd9837b 100644 --- a/packages/core/src/shared/sam/deploy.ts +++ b/packages/core/src/shared/sam/deploy.ts @@ -35,7 +35,7 @@ import { updateRecentResponse, } from './utils' import { runInTerminal } from './processTerminal' -import { DEPLOY_MEMENTO_ROOT_KEY } from './constants' +import { deployMementoRootKey } from './constants' export interface DeployParams { readonly paramsSource: ParamsSource @@ -50,7 +50,7 @@ export interface DeployParams { } function getRecentDeployParams(identifier: string, key: string): string | undefined { - return getRecentResponse(DEPLOY_MEMENTO_ROOT_KEY, identifier, key) + return getRecentResponse(deployMementoRootKey, identifier, key) } function createParamPromptProvider(name: string, defaultValue: string | undefined, templateFsPath: string = 'default') { @@ -105,11 +105,7 @@ export class DeployWizard extends Wizard { }) this.form.stackName.bindPrompter( ({ region }) => - createStackPrompter( - new DefaultCloudFormationClient(region!), - DEPLOY_MEMENTO_ROOT_KEY, - samDeployUrl - ), + createStackPrompter(new DefaultCloudFormationClient(region!), deployMementoRootKey, samDeployUrl), { showWhen: ({ paramsSource }) => paramsSource === ParamsSource.Specify || paramsSource === ParamsSource.SpecifyAndSave, @@ -121,7 +117,7 @@ export class DeployWizard extends Wizard { }) this.form.bucketName.bindPrompter( ({ region }) => - createBucketNamePrompter(new DefaultS3Client(region!), DEPLOY_MEMENTO_ROOT_KEY, samDeployUrl), + createBucketNamePrompter(new DefaultS3Client(region!), deployMementoRootKey, samDeployUrl), { showWhen: ({ bucketSource }) => bucketSource === BucketSource.UserProvided, } @@ -129,7 +125,7 @@ export class DeployWizard extends Wizard { } else if (this.arg && this.arg.regionCode) { // "Deploy" command was invoked on a regionNode. this.form.template.bindPrompter(() => - createTemplatePrompter(this.registry, DEPLOY_MEMENTO_ROOT_KEY, samDeployUrl) + createTemplatePrompter(this.registry, deployMementoRootKey, samDeployUrl) ) this.form.projectRoot.setDefault(({ template }) => getProjectRoot(template)) this.form.paramsSource.bindPrompter(async ({ projectRoot }) => { @@ -139,11 +135,7 @@ export class DeployWizard extends Wizard { this.form.region.setDefault(() => this.arg.regionCode) this.form.stackName.bindPrompter( ({ region }) => - createStackPrompter( - new DefaultCloudFormationClient(region!), - DEPLOY_MEMENTO_ROOT_KEY, - samDeployUrl - ), + createStackPrompter(new DefaultCloudFormationClient(region!), deployMementoRootKey, samDeployUrl), { showWhen: ({ paramsSource }) => paramsSource === ParamsSource.Specify || paramsSource === ParamsSource.SpecifyAndSave, @@ -155,7 +147,7 @@ export class DeployWizard extends Wizard { }) this.form.bucketName.bindPrompter( ({ region }) => - createBucketNamePrompter(new DefaultS3Client(region!), DEPLOY_MEMENTO_ROOT_KEY, samDeployUrl), + createBucketNamePrompter(new DefaultS3Client(region!), deployMementoRootKey, samDeployUrl), { showWhen: ({ bucketSource }) => bucketSource === BucketSource.UserProvided, } @@ -178,11 +170,7 @@ export class DeployWizard extends Wizard { }) this.form.stackName.bindPrompter( ({ region }) => - createStackPrompter( - new DefaultCloudFormationClient(region!), - DEPLOY_MEMENTO_ROOT_KEY, - samDeployUrl - ), + createStackPrompter(new DefaultCloudFormationClient(region!), deployMementoRootKey, samDeployUrl), { showWhen: ({ paramsSource }) => paramsSource === ParamsSource.Specify || paramsSource === ParamsSource.SpecifyAndSave, @@ -194,7 +182,7 @@ export class DeployWizard extends Wizard { }) this.form.bucketName.bindPrompter( ({ region }) => - createBucketNamePrompter(new DefaultS3Client(region!), DEPLOY_MEMENTO_ROOT_KEY, samDeployUrl), + createBucketNamePrompter(new DefaultS3Client(region!), deployMementoRootKey, samDeployUrl), { showWhen: ({ bucketSource }) => bucketSource === BucketSource.UserProvided, } @@ -203,7 +191,7 @@ export class DeployWizard extends Wizard { } else { // "Deploy" command was invoked on the command palette. this.form.template.bindPrompter(() => - createTemplatePrompter(this.registry, DEPLOY_MEMENTO_ROOT_KEY, samDeployUrl) + createTemplatePrompter(this.registry, deployMementoRootKey, samDeployUrl) ) this.form.projectRoot.setDefault(({ template }) => getProjectRoot(template)) this.form.paramsSource.bindPrompter(async ({ projectRoot }) => { @@ -216,11 +204,7 @@ export class DeployWizard extends Wizard { }) this.form.stackName.bindPrompter( ({ region }) => - createStackPrompter( - new DefaultCloudFormationClient(region!), - DEPLOY_MEMENTO_ROOT_KEY, - samDeployUrl - ), + createStackPrompter(new DefaultCloudFormationClient(region!), deployMementoRootKey, samDeployUrl), { showWhen: ({ paramsSource }) => paramsSource === ParamsSource.Specify || paramsSource === ParamsSource.SpecifyAndSave, @@ -232,7 +216,7 @@ export class DeployWizard extends Wizard { }) this.form.bucketName.bindPrompter( ({ region }) => - createBucketNamePrompter(new DefaultS3Client(region!), DEPLOY_MEMENTO_ROOT_KEY, samDeployUrl), + createBucketNamePrompter(new DefaultS3Client(region!), deployMementoRootKey, samDeployUrl), { showWhen: ({ bucketSource }) => bucketSource === BucketSource.UserProvided, } @@ -329,14 +313,14 @@ export async function runDeploy(arg: any, wizardParams?: DeployParams): Promise< const paramsToSet: string[] = [] for (const name of parameterNames) { if (params[name]) { - await updateRecentResponse(DEPLOY_MEMENTO_ROOT_KEY, params.template.uri.fsPath, name, params[name]) + await updateRecentResponse(deployMementoRootKey, params.template.uri.fsPath, name, params[name]) paramsToSet.push(`ParameterKey=${name},ParameterValue=${params[name]}`) } } paramsToSet.length > 0 && deployFlags.push('--parameter-overrides', paramsToSet.join(' ')) } - await updateRecentResponse(DEPLOY_MEMENTO_ROOT_KEY, 'global', 'templatePath', params.template.uri.fsPath) + await updateRecentResponse(deployMementoRootKey, 'global', 'templatePath', params.template.uri.fsPath) try { const { path: samCliPath } = await getSamCliPathAndVersion() diff --git a/packages/core/src/shared/sam/sync.ts b/packages/core/src/shared/sam/sync.ts index 647b47c4e73..4f31ea28a0f 100644 --- a/packages/core/src/shared/sam/sync.ts +++ b/packages/core/src/shared/sam/sync.ts @@ -52,7 +52,7 @@ import { ParamsSource, createSyncParamsSourcePrompter } from '../ui/sam/paramsSo import { createEcrPrompter } from '../ui/sam/ecrPrompter' import { BucketSource, createBucketNamePrompter, createBucketSourcePrompter } from '../ui/sam/bucketPrompter' import { runInTerminal } from './processTerminal' -import { SYNC_MEMENTO_ROOT_KEY } from './constants' +import { syncMementoRootKey } from './constants' export interface SyncParams { readonly paramsSource: ParamsSource @@ -71,7 +71,7 @@ export interface SyncParams { // TODO: hook this up so it prompts the user when more than 1 environment is present in `samconfig.toml` export function createEnvironmentPrompter(config: SamConfig, environments = config.listEnvironments()) { - const recentEnvironmentName = getRecentResponse(SYNC_MEMENTO_ROOT_KEY, config.location.fsPath, 'environmentName') + const recentEnvironmentName = getRecentResponse(syncMementoRootKey, config.location.fsPath, 'environmentName') const items = environments.map((env) => ({ label: env.name, data: env, @@ -155,7 +155,7 @@ export class SyncWizard extends Wizard { ) { super({ initState: state, exitPrompterProvider: shouldPromptExit ? createExitPrompter : undefined }) this.registry = registry - this.form.template.bindPrompter(() => createTemplatePrompter(this.registry, SYNC_MEMENTO_ROOT_KEY, samSyncUrl)) + this.form.template.bindPrompter(() => createTemplatePrompter(this.registry, syncMementoRootKey, samSyncUrl)) this.form.projectRoot.setDefault(({ template }) => getProjectRoot(template)) this.form.paramsSource.bindPrompter(async ({ projectRoot }) => { @@ -168,7 +168,7 @@ export class SyncWizard extends Wizard { }) this.form.stackName.bindPrompter( ({ region }) => - createStackPrompter(new DefaultCloudFormationClient(region!), SYNC_MEMENTO_ROOT_KEY, samSyncUrl), + createStackPrompter(new DefaultCloudFormationClient(region!), syncMementoRootKey, samSyncUrl), { showWhen: ({ paramsSource }) => paramsSource === ParamsSource.Specify || paramsSource === ParamsSource.SpecifyAndSave, @@ -180,14 +180,14 @@ export class SyncWizard extends Wizard { }) this.form.bucketName.bindPrompter( - ({ region }) => createBucketNamePrompter(new DefaultS3Client(region!), SYNC_MEMENTO_ROOT_KEY, samSyncUrl), + ({ region }) => createBucketNamePrompter(new DefaultS3Client(region!), syncMementoRootKey, samSyncUrl), { showWhen: ({ bucketSource }) => bucketSource === BucketSource.UserProvided, } ) this.form.ecrRepoUri.bindPrompter( - ({ region }) => createEcrPrompter(new DefaultEcrClient(region!), SYNC_MEMENTO_ROOT_KEY), + ({ region }) => createEcrPrompter(new DefaultEcrClient(region!), syncMementoRootKey), { showWhen: ({ template, paramsSource }) => !!template && @@ -515,7 +515,7 @@ export async function runSync( } async function updateSyncRecentResponse(region: string, key: string, value: string | undefined) { - return await updateRecentResponse(SYNC_MEMENTO_ROOT_KEY, region, key, value) + return await updateRecentResponse(syncMementoRootKey, region, key, value) } export async function confirmDevStack() { diff --git a/packages/core/src/shared/sam/utils.ts b/packages/core/src/shared/sam/utils.ts index 4db61a69128..dfb3c909c6f 100644 --- a/packages/core/src/shared/sam/utils.ts +++ b/packages/core/src/shared/sam/utils.ts @@ -1,5 +1,3 @@ -/* eslint-disable header/header */ -/* eslint-disable @typescript-eslint/naming-convention */ /*! * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 @@ -20,7 +18,7 @@ import { telemetry } from '../telemetry/telemetry' import globals from '../extensionGlobals' import { getLogger } from '../logger/logger' import { ChildProcessResult } from '../utilities/processUtils' -import { BUILD_PROCESS_MEMENTO_ROOT_KEY, GLOBAL_IDENTIFIER } from './constants' +import { buildProcessMementoRootKey, globalIdentifier } from './constants' /** * @description determines the root directory of the project given Template Item @@ -117,7 +115,7 @@ export async function updateRecentResponse( * @Param templatePath The path to the template.yaml file */ function isBuildInProgress(templatePath: string): boolean { - return getRecentResponse(BUILD_PROCESS_MEMENTO_ROOT_KEY, GLOBAL_IDENTIFIER, templatePath) !== undefined + return getRecentResponse(buildProcessMementoRootKey, globalIdentifier, templatePath) !== undefined } /** @@ -131,11 +129,11 @@ export function throwIfTemplateIsBeingBuilt(templatePath: string) { } export async function registerTemplateBuild(templatePath: string) { - await updateRecentResponse(BUILD_PROCESS_MEMENTO_ROOT_KEY, GLOBAL_IDENTIFIER, templatePath, 'true') + await updateRecentResponse(buildProcessMementoRootKey, globalIdentifier, templatePath, 'true') } export async function unregisterTemplateBuild(templatePath: string) { - await updateRecentResponse(BUILD_PROCESS_MEMENTO_ROOT_KEY, GLOBAL_IDENTIFIER, templatePath, undefined) + await updateRecentResponse(buildProcessMementoRootKey, globalIdentifier, templatePath, undefined) } export function getSamCliErrorMessage(stderr: string): string {