Skip to content

Commit 3471429

Browse files
committed
add constants file
1 parent 00e99fe commit 3471429

File tree

5 files changed

+58
-32
lines changed

5 files changed

+58
-32
lines changed

packages/core/src/shared/sam/build.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ import {
3232
} from './utils'
3333
import { getConfigFileUri, validateSamBuildConfig } from './config'
3434
import { runInTerminal } from './processTerminal'
35+
import { BUILD_MEMENTO_ROOT_KEY } from './constants'
3536

36-
const buildMementoRootKey = 'samcli.build.params'
3737
export interface BuildParams {
3838
readonly template: TemplateItem
3939
readonly projectRoot: vscode.Uri
@@ -140,7 +140,7 @@ export class BuildWizard extends Wizard<BuildParams> {
140140
if (this.arg === undefined) {
141141
// "Build" command was invoked on the command palette.
142142
this.form.template.bindPrompter(() =>
143-
createTemplatePrompter(this.registry, buildMementoRootKey, samBuildUrl)
143+
createTemplatePrompter(this.registry, BUILD_MEMENTO_ROOT_KEY, samBuildUrl)
144144
)
145145
this.form.projectRoot.setDefault(({ template }) => getProjectRoot(template))
146146
this.form.paramsSource.bindPrompter(async ({ projectRoot }) => {
@@ -232,7 +232,7 @@ export async function runBuild(arg?: TreeNode): Promise<SamBuildResult> {
232232
const templatePath = params.template.uri.fsPath
233233
buildFlags.push('--template', `${templatePath}`)
234234

235-
await updateRecentResponse(buildMementoRootKey, 'global', 'templatePath', templatePath)
235+
await updateRecentResponse(BUILD_MEMENTO_ROOT_KEY, 'global', 'templatePath', templatePath)
236236

237237
try {
238238
await vscode.window.withProgress(
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* eslint-disable header/header */
2+
/* eslint-disable @typescript-eslint/naming-convention */
3+
/*!
4+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
export const BUILD_PROCESS_MEMENTO_ROOT_KEY = 'samcli.build.processes'
9+
export const GLOBAL_IDENTIFIER = 'global'
10+
export const BUILD_MEMENTO_ROOT_KEY = 'samcli.build.params'
11+
export const DEPLOY_MEMENTO_ROOT_KEY = 'samcli.deploy.params'
12+
export const SYNC_MEMENTO_ROOT_KEY = 'samcli.sync.params'

packages/core/src/shared/sam/deploy.ts

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
updateRecentResponse,
3636
} from './utils'
3737
import { runInTerminal } from './processTerminal'
38+
import { DEPLOY_MEMENTO_ROOT_KEY } from './constants'
3839

3940
export interface DeployParams {
4041
readonly paramsSource: ParamsSource
@@ -48,10 +49,8 @@ export interface DeployParams {
4849
[key: string]: any
4950
}
5051

51-
const deployMementoRootKey = 'samcli.deploy.params'
52-
5352
function getRecentDeployParams(identifier: string, key: string): string | undefined {
54-
return getRecentResponse(deployMementoRootKey, identifier, key)
53+
return getRecentResponse(DEPLOY_MEMENTO_ROOT_KEY, identifier, key)
5554
}
5655

5756
function createParamPromptProvider(name: string, defaultValue: string | undefined, templateFsPath: string = 'default') {
@@ -106,7 +105,11 @@ export class DeployWizard extends Wizard<DeployParams> {
106105
})
107106
this.form.stackName.bindPrompter(
108107
({ region }) =>
109-
createStackPrompter(new DefaultCloudFormationClient(region!), deployMementoRootKey, samDeployUrl),
108+
createStackPrompter(
109+
new DefaultCloudFormationClient(region!),
110+
DEPLOY_MEMENTO_ROOT_KEY,
111+
samDeployUrl
112+
),
110113
{
111114
showWhen: ({ paramsSource }) =>
112115
paramsSource === ParamsSource.Specify || paramsSource === ParamsSource.SpecifyAndSave,
@@ -118,15 +121,15 @@ export class DeployWizard extends Wizard<DeployParams> {
118121
})
119122
this.form.bucketName.bindPrompter(
120123
({ region }) =>
121-
createBucketNamePrompter(new DefaultS3Client(region!), deployMementoRootKey, samDeployUrl),
124+
createBucketNamePrompter(new DefaultS3Client(region!), DEPLOY_MEMENTO_ROOT_KEY, samDeployUrl),
122125
{
123126
showWhen: ({ bucketSource }) => bucketSource === BucketSource.UserProvided,
124127
}
125128
)
126129
} else if (this.arg && this.arg.regionCode) {
127130
// "Deploy" command was invoked on a regionNode.
128131
this.form.template.bindPrompter(() =>
129-
createTemplatePrompter(this.registry, deployMementoRootKey, samDeployUrl)
132+
createTemplatePrompter(this.registry, DEPLOY_MEMENTO_ROOT_KEY, samDeployUrl)
130133
)
131134
this.form.projectRoot.setDefault(({ template }) => getProjectRoot(template))
132135
this.form.paramsSource.bindPrompter(async ({ projectRoot }) => {
@@ -136,7 +139,11 @@ export class DeployWizard extends Wizard<DeployParams> {
136139
this.form.region.setDefault(() => this.arg.regionCode)
137140
this.form.stackName.bindPrompter(
138141
({ region }) =>
139-
createStackPrompter(new DefaultCloudFormationClient(region!), deployMementoRootKey, samDeployUrl),
142+
createStackPrompter(
143+
new DefaultCloudFormationClient(region!),
144+
DEPLOY_MEMENTO_ROOT_KEY,
145+
samDeployUrl
146+
),
140147
{
141148
showWhen: ({ paramsSource }) =>
142149
paramsSource === ParamsSource.Specify || paramsSource === ParamsSource.SpecifyAndSave,
@@ -148,7 +155,7 @@ export class DeployWizard extends Wizard<DeployParams> {
148155
})
149156
this.form.bucketName.bindPrompter(
150157
({ region }) =>
151-
createBucketNamePrompter(new DefaultS3Client(region!), deployMementoRootKey, samDeployUrl),
158+
createBucketNamePrompter(new DefaultS3Client(region!), DEPLOY_MEMENTO_ROOT_KEY, samDeployUrl),
152159
{
153160
showWhen: ({ bucketSource }) => bucketSource === BucketSource.UserProvided,
154161
}
@@ -171,7 +178,11 @@ export class DeployWizard extends Wizard<DeployParams> {
171178
})
172179
this.form.stackName.bindPrompter(
173180
({ region }) =>
174-
createStackPrompter(new DefaultCloudFormationClient(region!), deployMementoRootKey, samDeployUrl),
181+
createStackPrompter(
182+
new DefaultCloudFormationClient(region!),
183+
DEPLOY_MEMENTO_ROOT_KEY,
184+
samDeployUrl
185+
),
175186
{
176187
showWhen: ({ paramsSource }) =>
177188
paramsSource === ParamsSource.Specify || paramsSource === ParamsSource.SpecifyAndSave,
@@ -183,7 +194,7 @@ export class DeployWizard extends Wizard<DeployParams> {
183194
})
184195
this.form.bucketName.bindPrompter(
185196
({ region }) =>
186-
createBucketNamePrompter(new DefaultS3Client(region!), deployMementoRootKey, samDeployUrl),
197+
createBucketNamePrompter(new DefaultS3Client(region!), DEPLOY_MEMENTO_ROOT_KEY, samDeployUrl),
187198
{
188199
showWhen: ({ bucketSource }) => bucketSource === BucketSource.UserProvided,
189200
}
@@ -192,7 +203,7 @@ export class DeployWizard extends Wizard<DeployParams> {
192203
} else {
193204
// "Deploy" command was invoked on the command palette.
194205
this.form.template.bindPrompter(() =>
195-
createTemplatePrompter(this.registry, deployMementoRootKey, samDeployUrl)
206+
createTemplatePrompter(this.registry, DEPLOY_MEMENTO_ROOT_KEY, samDeployUrl)
196207
)
197208
this.form.projectRoot.setDefault(({ template }) => getProjectRoot(template))
198209
this.form.paramsSource.bindPrompter(async ({ projectRoot }) => {
@@ -205,7 +216,11 @@ export class DeployWizard extends Wizard<DeployParams> {
205216
})
206217
this.form.stackName.bindPrompter(
207218
({ region }) =>
208-
createStackPrompter(new DefaultCloudFormationClient(region!), deployMementoRootKey, samDeployUrl),
219+
createStackPrompter(
220+
new DefaultCloudFormationClient(region!),
221+
DEPLOY_MEMENTO_ROOT_KEY,
222+
samDeployUrl
223+
),
209224
{
210225
showWhen: ({ paramsSource }) =>
211226
paramsSource === ParamsSource.Specify || paramsSource === ParamsSource.SpecifyAndSave,
@@ -217,7 +232,7 @@ export class DeployWizard extends Wizard<DeployParams> {
217232
})
218233
this.form.bucketName.bindPrompter(
219234
({ region }) =>
220-
createBucketNamePrompter(new DefaultS3Client(region!), deployMementoRootKey, samDeployUrl),
235+
createBucketNamePrompter(new DefaultS3Client(region!), DEPLOY_MEMENTO_ROOT_KEY, samDeployUrl),
221236
{
222237
showWhen: ({ bucketSource }) => bucketSource === BucketSource.UserProvided,
223238
}
@@ -314,14 +329,14 @@ export async function runDeploy(arg: any, wizardParams?: DeployParams): Promise<
314329
const paramsToSet: string[] = []
315330
for (const name of parameterNames) {
316331
if (params[name]) {
317-
await updateRecentResponse(deployMementoRootKey, params.template.uri.fsPath, name, params[name])
332+
await updateRecentResponse(DEPLOY_MEMENTO_ROOT_KEY, params.template.uri.fsPath, name, params[name])
318333
paramsToSet.push(`ParameterKey=${name},ParameterValue=${params[name]}`)
319334
}
320335
}
321336
paramsToSet.length > 0 && deployFlags.push('--parameter-overrides', paramsToSet.join(' '))
322337
}
323338

324-
await updateRecentResponse(deployMementoRootKey, 'global', 'templatePath', params.template.uri.fsPath)
339+
await updateRecentResponse(DEPLOY_MEMENTO_ROOT_KEY, 'global', 'templatePath', params.template.uri.fsPath)
325340

326341
try {
327342
const { path: samCliPath } = await getSamCliPathAndVersion()

packages/core/src/shared/sam/sync.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import { ParamsSource, createSyncParamsSourcePrompter } from '../ui/sam/paramsSo
5252
import { createEcrPrompter } from '../ui/sam/ecrPrompter'
5353
import { BucketSource, createBucketNamePrompter, createBucketSourcePrompter } from '../ui/sam/bucketPrompter'
5454
import { runInTerminal } from './processTerminal'
55+
import { SYNC_MEMENTO_ROOT_KEY } from './constants'
5556

5657
export interface SyncParams {
5758
readonly paramsSource: ParamsSource
@@ -68,11 +69,9 @@ export interface SyncParams {
6869
readonly syncFlags?: string
6970
}
7071

71-
export const syncMementoRootKey = 'samcli.sync.params'
72-
7372
// TODO: hook this up so it prompts the user when more than 1 environment is present in `samconfig.toml`
7473
export function createEnvironmentPrompter(config: SamConfig, environments = config.listEnvironments()) {
75-
const recentEnvironmentName = getRecentResponse(syncMementoRootKey, config.location.fsPath, 'environmentName')
74+
const recentEnvironmentName = getRecentResponse(SYNC_MEMENTO_ROOT_KEY, config.location.fsPath, 'environmentName')
7675
const items = environments.map((env) => ({
7776
label: env.name,
7877
data: env,
@@ -156,7 +155,7 @@ export class SyncWizard extends Wizard<SyncParams> {
156155
) {
157156
super({ initState: state, exitPrompterProvider: shouldPromptExit ? createExitPrompter : undefined })
158157
this.registry = registry
159-
this.form.template.bindPrompter(() => createTemplatePrompter(this.registry, syncMementoRootKey, samSyncUrl))
158+
this.form.template.bindPrompter(() => createTemplatePrompter(this.registry, SYNC_MEMENTO_ROOT_KEY, samSyncUrl))
160159
this.form.projectRoot.setDefault(({ template }) => getProjectRoot(template))
161160

162161
this.form.paramsSource.bindPrompter(async ({ projectRoot }) => {
@@ -169,7 +168,7 @@ export class SyncWizard extends Wizard<SyncParams> {
169168
})
170169
this.form.stackName.bindPrompter(
171170
({ region }) =>
172-
createStackPrompter(new DefaultCloudFormationClient(region!), syncMementoRootKey, samSyncUrl),
171+
createStackPrompter(new DefaultCloudFormationClient(region!), SYNC_MEMENTO_ROOT_KEY, samSyncUrl),
173172
{
174173
showWhen: ({ paramsSource }) =>
175174
paramsSource === ParamsSource.Specify || paramsSource === ParamsSource.SpecifyAndSave,
@@ -181,14 +180,14 @@ export class SyncWizard extends Wizard<SyncParams> {
181180
})
182181

183182
this.form.bucketName.bindPrompter(
184-
({ region }) => createBucketNamePrompter(new DefaultS3Client(region!), syncMementoRootKey, samSyncUrl),
183+
({ region }) => createBucketNamePrompter(new DefaultS3Client(region!), SYNC_MEMENTO_ROOT_KEY, samSyncUrl),
185184
{
186185
showWhen: ({ bucketSource }) => bucketSource === BucketSource.UserProvided,
187186
}
188187
)
189188

190189
this.form.ecrRepoUri.bindPrompter(
191-
({ region }) => createEcrPrompter(new DefaultEcrClient(region!), syncMementoRootKey),
190+
({ region }) => createEcrPrompter(new DefaultEcrClient(region!), SYNC_MEMENTO_ROOT_KEY),
192191
{
193192
showWhen: ({ template, paramsSource }) =>
194193
!!template &&
@@ -516,7 +515,7 @@ export async function runSync(
516515
}
517516

518517
async function updateSyncRecentResponse(region: string, key: string, value: string | undefined) {
519-
return await updateRecentResponse(syncMementoRootKey, region, key, value)
518+
return await updateRecentResponse(SYNC_MEMENTO_ROOT_KEY, region, key, value)
520519
}
521520

522521
export async function confirmDevStack() {

packages/core/src/shared/sam/utils.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable header/header */
2+
/* eslint-disable @typescript-eslint/naming-convention */
13
/*!
24
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
35
* SPDX-License-Identifier: Apache-2.0
@@ -18,6 +20,7 @@ import { telemetry } from '../telemetry/telemetry'
1820
import globals from '../extensionGlobals'
1921
import { getLogger } from '../logger/logger'
2022
import { ChildProcessResult } from '../utilities/processUtils'
23+
import { BUILD_PROCESS_MEMENTO_ROOT_KEY, GLOBAL_IDENTIFIER } from './constants'
2124

2225
/**
2326
* @description determines the root directory of the project given Template Item
@@ -109,15 +112,12 @@ export async function updateRecentResponse(
109112
}
110113
}
111114

112-
const buildProcessMementoRootKey = 'samcli.build.processes'
113-
const globalIdentifier = 'global'
114-
115115
/**
116116
* Returns true if there's an ongoing build process for the provided template, false otherwise
117117
* @Param templatePath The path to the template.yaml file
118118
*/
119119
function isBuildInProgress(templatePath: string): boolean {
120-
return getRecentResponse(buildProcessMementoRootKey, globalIdentifier, templatePath) !== undefined
120+
return getRecentResponse(BUILD_PROCESS_MEMENTO_ROOT_KEY, GLOBAL_IDENTIFIER, templatePath) !== undefined
121121
}
122122

123123
/**
@@ -131,11 +131,11 @@ export function throwIfTemplateIsBeingBuilt(templatePath: string) {
131131
}
132132

133133
export async function registerTemplateBuild(templatePath: string) {
134-
await updateRecentResponse(buildProcessMementoRootKey, 'global', templatePath, 'true')
134+
await updateRecentResponse(BUILD_PROCESS_MEMENTO_ROOT_KEY, GLOBAL_IDENTIFIER, templatePath, 'true')
135135
}
136136

137137
export async function unregisterTemplateBuild(templatePath: string) {
138-
await updateRecentResponse(buildProcessMementoRootKey, 'global', templatePath, undefined)
138+
await updateRecentResponse(BUILD_PROCESS_MEMENTO_ROOT_KEY, GLOBAL_IDENTIFIER, templatePath, undefined)
139139
}
140140

141141
export function getSamCliErrorMessage(stderr: string): string {

0 commit comments

Comments
 (0)