Skip to content

Commit bb4eeef

Browse files
author
Vandita Patidar
committed
Building Quick Pick structure
1 parent e63ca97 commit bb4eeef

File tree

7 files changed

+552
-20
lines changed

7 files changed

+552
-20
lines changed

aws-toolkit-vscode.code-workspace

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,50 @@
11
{
2-
"folders": [
3-
{
4-
"path": "."
5-
},
6-
{
7-
"path": "packages/toolkit"
8-
},
9-
{
10-
"path": "packages/core"
11-
},
12-
{
13-
"path": "packages/amazonq"
14-
}
15-
],
16-
"settings": {
17-
"typescript.tsdk": "node_modules/typescript/lib"
18-
}
19-
}
2+
"folders": [
3+
{
4+
"path": ".",
5+
},
6+
{
7+
"path": "packages/toolkit",
8+
},
9+
{
10+
"path": "packages/core",
11+
},
12+
{
13+
"path": "packages/amazonq",
14+
},
15+
],
16+
"settings": {
17+
"typescript.tsdk": "node_modules/typescript/lib",
18+
},
19+
"launch": {
20+
"configurations": [
21+
{
22+
"type": "aws-sam",
23+
"request": "direct-invoke",
24+
"name": "core:src/awsService/appBuilder/serverlessLand.getProjectUri (nodejs14.x)",
25+
"invokeTarget": {
26+
"target": "code",
27+
"projectRoot": "/Users/vanditap/src/github.com/aws-toolkit-vscode/packages/core",
28+
"lambdaHandler": "src/awsService/appBuilder/serverlessLand.getProjectUri",
29+
},
30+
"lambda": {
31+
"runtime": "nodejs14.x",
32+
"payload": {},
33+
"environmentVariables": {},
34+
},
35+
},
36+
{
37+
"name": "Test Lint",
38+
"type": "node",
39+
"request": "launch",
40+
"program": "${workspaceFolder}/scripts/lint/testLint.ts",
41+
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
42+
"preLaunchTask": "build",
43+
"presentation": {
44+
"group": "7_TestLint",
45+
"order": 1,
46+
},
47+
},
48+
],
49+
},
50+
}

packages/core/package.nls.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,5 +414,6 @@
414414
"AWS.toolkit.lambda.walkthrough.step1.title": "Iterate locally",
415415
"AWS.toolkit.lambda.walkthrough.step1.description": "Locally test and debug your code.",
416416
"AWS.toolkit.lambda.walkthrough.step2.title": "Deploy to the cloud",
417-
"AWS.toolkit.lambda.walkthrough.step2.description": "Test your application in the cloud from within VS Code. \n\nNote: The AWS CLI and the SAM CLI require AWS Credentials to interact with the cloud. For information on setting up your credentials, see [Authentication and access credentials](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html). \n\n[Configure credentials](command:aws.toolkit.lambda.walkthrough.credential)"
417+
"AWS.toolkit.lambda.walkthrough.step2.description": "Test your application in the cloud from within VS Code. \n\nNote: The AWS CLI and the SAM CLI require AWS Credentials to interact with the cloud. For information on setting up your credentials, see [Authentication and access credentials](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html). \n\n[Configure credentials](command:aws.toolkit.lambda.walkthrough.credential)",
418+
"AWS.toolkit.lambda.serverlessLand.quickpickTitle": "Create Lambda application from template"
418419
}

packages/core/src/awsService/appBuilder/activation.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { ResourceNode } from './explorer/nodes/resourceNode'
2323
import { getSyncWizard, runSync } from '../../shared/sam/sync'
2424
import { getDeployWizard, runDeploy } from '../../shared/sam/deploy'
2525
import { DeployTypeWizard } from './wizards/deployTypeWizard'
26-
26+
import { createNewServerlessLandProject } from './serverlessLand'
2727
export const templateToOpenAppComposer = 'aws.toolkit.appComposer.templateToOpenOnStart'
2828

2929
/**
@@ -200,6 +200,9 @@ async function registerAppBuilderCommands(context: ExtContext): Promise<void> {
200200
await runSync('infra', arg, undefined, choices.syncParam)
201201
}
202202
}
203+
}),
204+
Commands.register({ id: 'aws.toolkit.lambda.serverlessLand', autoconnect: false }, async () => {
205+
await createNewServerlessLandProject(context)
203206
})
204207
)
205208
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"patterns": {
3+
"s3-lambda-resizing-sam": {
4+
"name": "Resizing image",
5+
"description": "Lambda, S3 • Python, Javascript, Java, .NET • SAM",
6+
"runtimes": [
7+
{
8+
"id": "python",
9+
"name": "Python"
10+
},
11+
{
12+
"id": "javascript",
13+
"name": "Javascript"
14+
},
15+
{
16+
"id": "dotnet",
17+
"name": "Dotnet"
18+
},
19+
{
20+
"id": "java",
21+
"name": "Java"
22+
}
23+
],
24+
"iac": [
25+
{
26+
"id": "sam",
27+
"name": "SAM"
28+
}
29+
]
30+
},
31+
"apigw-rest-api-lambda-sam": {
32+
"name": "Rest API",
33+
"description": "Lambda, API Gateway • Python, Javascript, Java, .NET • SAM",
34+
"runtimes": [
35+
{
36+
"id": "python",
37+
"name": "Python"
38+
},
39+
{
40+
"id": "javascript",
41+
"name": "Javascript"
42+
},
43+
{
44+
"id": "dotnet",
45+
"name": "Dotnet"
46+
},
47+
{
48+
"id": "java",
49+
"name": "Java"
50+
}
51+
],
52+
"iac": [
53+
{
54+
"id": "sam",
55+
"name": "AWS SAM"
56+
}
57+
]
58+
}
59+
}
60+
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import * as nls from 'vscode-nls'
7+
const localize = nls.loadMessageBundle()
8+
import * as path from 'path'
9+
// import * as vscode from 'vscode'
10+
import { getTelemetryResult, RegionProvider } from '../../shared'
11+
import { getLogger } from '../../shared/logger'
12+
import globals from '../../shared/extensionGlobals'
13+
import { checklogs } from '../../shared/localizedText'
14+
// import { fileExists } from '../../shared/filesystemUtilities'
15+
// import { CreateServerlessLandWizardForm } from '../appBuilder/wizards/serverlessLandWizard'
16+
import { Result, telemetry } from '../../shared/telemetry/telemetry'
17+
import { CreateServerlessLandWizard } from '../appBuilder/wizards/serverlessLandWizard'
18+
import { ExtContext } from '../../shared/extensions'
19+
import { addFolderToWorkspace } from '../../shared/utilities/workspaceUtils'
20+
21+
export const readmeFile: string = 'README.md'
22+
23+
// export async function getProjectUri(
24+
// config: Pick<CreateServerlessLandWizardForm, 'location' | 'name'>,
25+
// files: string
26+
// ): Promise<vscode.Uri | undefined> {
27+
// if (files.length === 0) {
28+
// throw Error('expected "files" parameter to have at least one item')
29+
// }
30+
// let file: string
31+
// let cfnTemplatePath: string
32+
// for (const f of files) {
33+
// file = f
34+
// cfnTemplatePath = path.resolve(config.location.fsPath, config.name, file)
35+
// if (await fileExists(cfnTemplatePath)) {
36+
// return vscode.Uri.file(cfnTemplatePath)
37+
// }
38+
// }
39+
// void vscode.window.showWarningMessage(
40+
// localize(
41+
// 'AWS.samcli.initWizard.source.error.notFound',
42+
// 'Project created successfully, but {0} file not found: {1}',
43+
// file!,
44+
// cfnTemplatePath!
45+
// )
46+
// )
47+
// }
48+
49+
/**
50+
* Creates a new Serverless Land project using the provided extension context
51+
* @param extContext Extension context containing AWS credentials and region information
52+
* @returns Promise that resolves when the project creation is complete
53+
*
54+
* This function:
55+
* 1. Validates AWS credentials and regions
56+
* 2. Launches the Serverless Land project creation wizard
57+
* 3. Creates the project structure
58+
* 4. Adds the project folder to the workspace
59+
* 5. Opens the README.md file if available
60+
* 6. Handles errors and emits telemetry
61+
*/
62+
export async function createNewServerlessLandProject(extContext: ExtContext): Promise<void> {
63+
const awsContext = extContext.awsContext
64+
const regionProvider: RegionProvider = extContext.regionProvider
65+
let createResult: Result = 'Succeeded'
66+
let reason: string | undefined
67+
68+
try {
69+
const credentials = await awsContext.getCredentials()
70+
const schemaRegions = regionProvider
71+
.getRegions()
72+
.filter((r) => regionProvider.isServiceInRegion('schemas', r.id))
73+
const defaultRegion = awsContext.getCredentialDefaultRegion()
74+
75+
// Launch the project creation wizard
76+
const config = await new CreateServerlessLandWizard({
77+
credentials,
78+
schemaRegions,
79+
defaultRegion,
80+
}).run()
81+
if (!config) {
82+
createResult = 'Cancelled'
83+
reason = 'userCancelled'
84+
return
85+
}
86+
87+
// Add the project folder to the workspace
88+
await addFolderToWorkspace(
89+
{
90+
uri: config.location,
91+
name: path.basename(config.location.fsPath),
92+
},
93+
true
94+
)
95+
96+
// Verify project creation and locate project files
97+
// const projectUri = await getProjectUri(config, readmeFile)
98+
// if (!projectUri) {
99+
// reason = 'fileNotFound'
100+
101+
// return
102+
// }
103+
104+
// Open README.md file
105+
// const readmeUri = vscode.Uri.file(path.join(path.dirname(projectUri.fsPath), readmeFile))
106+
// if (await fileExists(readmeUri.fsPath)) {
107+
// const document = await vscode.workspace.openTextDocument(readmeUri)
108+
// await vscode.window.showTextDocument(document)
109+
// } else {
110+
// getLogger().warn(
111+
// localize('AWS.serverlessLand.readme.notFound', 'README.md file not found in the project directory')
112+
// )
113+
// }
114+
} catch (err) {
115+
createResult = getTelemetryResult(err)
116+
reason = getTelemetryResult(err)
117+
118+
globals.outputChannel.show(true)
119+
getLogger().error(
120+
localize('AWS.samcli.initWizard.general.error', 'Error creating new SAM Application. {0}', checklogs())
121+
)
122+
123+
getLogger().error('Error creating new SAM Application: %O', err as Error)
124+
} finally {
125+
// add telemetry
126+
telemetry.sam_init.emit({
127+
result: createResult,
128+
reason: reason,
129+
})
130+
}
131+
}

0 commit comments

Comments
 (0)