Skip to content

Commit

Permalink
Building Quick Pick structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Vandita Patidar committed Feb 17, 2025
1 parent e63ca97 commit bb4eeef
Show file tree
Hide file tree
Showing 7 changed files with 552 additions and 20 deletions.
67 changes: 49 additions & 18 deletions aws-toolkit-vscode.code-workspace
Original file line number Diff line number Diff line change
@@ -1,19 +1,50 @@
{
"folders": [
{
"path": "."
},
{
"path": "packages/toolkit"
},
{
"path": "packages/core"
},
{
"path": "packages/amazonq"
}
],
"settings": {
"typescript.tsdk": "node_modules/typescript/lib"
}
}
"folders": [
{
"path": ".",
},
{
"path": "packages/toolkit",
},
{
"path": "packages/core",
},
{
"path": "packages/amazonq",
},
],
"settings": {
"typescript.tsdk": "node_modules/typescript/lib",
},
"launch": {
"configurations": [
{
"type": "aws-sam",
"request": "direct-invoke",
"name": "core:src/awsService/appBuilder/serverlessLand.getProjectUri (nodejs14.x)",
"invokeTarget": {
"target": "code",
"projectRoot": "/Users/vanditap/src/github.com/aws-toolkit-vscode/packages/core",
"lambdaHandler": "src/awsService/appBuilder/serverlessLand.getProjectUri",
},
"lambda": {
"runtime": "nodejs14.x",
"payload": {},
"environmentVariables": {},
},
},
{
"name": "Test Lint",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/scripts/lint/testLint.ts",
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
"preLaunchTask": "build",
"presentation": {
"group": "7_TestLint",
"order": 1,
},
},
],
},
}
3 changes: 2 additions & 1 deletion packages/core/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -414,5 +414,6 @@
"AWS.toolkit.lambda.walkthrough.step1.title": "Iterate locally",
"AWS.toolkit.lambda.walkthrough.step1.description": "Locally test and debug your code.",
"AWS.toolkit.lambda.walkthrough.step2.title": "Deploy to the cloud",
"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)"
"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)",
"AWS.toolkit.lambda.serverlessLand.quickpickTitle": "Create Lambda application from template"
}
5 changes: 4 additions & 1 deletion packages/core/src/awsService/appBuilder/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { ResourceNode } from './explorer/nodes/resourceNode'
import { getSyncWizard, runSync } from '../../shared/sam/sync'
import { getDeployWizard, runDeploy } from '../../shared/sam/deploy'
import { DeployTypeWizard } from './wizards/deployTypeWizard'

import { createNewServerlessLandProject } from './serverlessLand'
export const templateToOpenAppComposer = 'aws.toolkit.appComposer.templateToOpenOnStart'

/**
Expand Down Expand Up @@ -200,6 +200,9 @@ async function registerAppBuilderCommands(context: ExtContext): Promise<void> {
await runSync('infra', arg, undefined, choices.syncParam)
}
}
}),
Commands.register({ id: 'aws.toolkit.lambda.serverlessLand', autoconnect: false }, async () => {
await createNewServerlessLandProject(context)
})
)
}
60 changes: 60 additions & 0 deletions packages/core/src/awsService/appBuilder/models/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"patterns": {
"s3-lambda-resizing-sam": {
"name": "Resizing image",
"description": "Lambda, S3 • Python, Javascript, Java, .NET • SAM",
"runtimes": [
{
"id": "python",
"name": "Python"
},
{
"id": "javascript",
"name": "Javascript"
},
{
"id": "dotnet",
"name": "Dotnet"
},
{
"id": "java",
"name": "Java"
}
],
"iac": [
{
"id": "sam",
"name": "SAM"
}
]
},
"apigw-rest-api-lambda-sam": {
"name": "Rest API",
"description": "Lambda, API Gateway • Python, Javascript, Java, .NET • SAM",
"runtimes": [
{
"id": "python",
"name": "Python"
},
{
"id": "javascript",
"name": "Javascript"
},
{
"id": "dotnet",
"name": "Dotnet"
},
{
"id": "java",
"name": "Java"
}
],
"iac": [
{
"id": "sam",
"name": "AWS SAM"
}
]
}
}
}
131 changes: 131 additions & 0 deletions packages/core/src/awsService/appBuilder/serverlessLand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*!
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

import * as nls from 'vscode-nls'
const localize = nls.loadMessageBundle()
import * as path from 'path'
// import * as vscode from 'vscode'
import { getTelemetryResult, RegionProvider } from '../../shared'

Check failure on line 10 in packages/core/src/awsService/appBuilder/serverlessLand.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

do not import from folders or index.ts files since it can cause circular dependencies. import from the file directly
import { getLogger } from '../../shared/logger'

Check failure on line 11 in packages/core/src/awsService/appBuilder/serverlessLand.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

do not import from folders or index.ts files since it can cause circular dependencies. import from the file directly
import globals from '../../shared/extensionGlobals'
import { checklogs } from '../../shared/localizedText'
// import { fileExists } from '../../shared/filesystemUtilities'
// import { CreateServerlessLandWizardForm } from '../appBuilder/wizards/serverlessLandWizard'
import { Result, telemetry } from '../../shared/telemetry/telemetry'
import { CreateServerlessLandWizard } from '../appBuilder/wizards/serverlessLandWizard'
import { ExtContext } from '../../shared/extensions'
import { addFolderToWorkspace } from '../../shared/utilities/workspaceUtils'

export const readmeFile: string = 'README.md'

// export async function getProjectUri(
// config: Pick<CreateServerlessLandWizardForm, 'location' | 'name'>,
// files: string
// ): Promise<vscode.Uri | undefined> {
// if (files.length === 0) {
// throw Error('expected "files" parameter to have at least one item')
// }
// let file: string
// let cfnTemplatePath: string
// for (const f of files) {
// file = f
// cfnTemplatePath = path.resolve(config.location.fsPath, config.name, file)
// if (await fileExists(cfnTemplatePath)) {
// return vscode.Uri.file(cfnTemplatePath)
// }
// }
// void vscode.window.showWarningMessage(
// localize(
// 'AWS.samcli.initWizard.source.error.notFound',
// 'Project created successfully, but {0} file not found: {1}',
// file!,
// cfnTemplatePath!
// )
// )
// }

/**
* Creates a new Serverless Land project using the provided extension context
* @param extContext Extension context containing AWS credentials and region information
* @returns Promise that resolves when the project creation is complete
*
* This function:
* 1. Validates AWS credentials and regions
* 2. Launches the Serverless Land project creation wizard
* 3. Creates the project structure
* 4. Adds the project folder to the workspace
* 5. Opens the README.md file if available
* 6. Handles errors and emits telemetry
*/
export async function createNewServerlessLandProject(extContext: ExtContext): Promise<void> {
const awsContext = extContext.awsContext
const regionProvider: RegionProvider = extContext.regionProvider
let createResult: Result = 'Succeeded'
let reason: string | undefined

try {
const credentials = await awsContext.getCredentials()
const schemaRegions = regionProvider
.getRegions()
.filter((r) => regionProvider.isServiceInRegion('schemas', r.id))
const defaultRegion = awsContext.getCredentialDefaultRegion()

// Launch the project creation wizard
const config = await new CreateServerlessLandWizard({
credentials,
schemaRegions,
defaultRegion,
}).run()
if (!config) {
createResult = 'Cancelled'
reason = 'userCancelled'
return
}

// Add the project folder to the workspace
await addFolderToWorkspace(
{
uri: config.location,
name: path.basename(config.location.fsPath),
},
true
)

// Verify project creation and locate project files
// const projectUri = await getProjectUri(config, readmeFile)
// if (!projectUri) {
// reason = 'fileNotFound'

// return
// }

// Open README.md file
// const readmeUri = vscode.Uri.file(path.join(path.dirname(projectUri.fsPath), readmeFile))
// if (await fileExists(readmeUri.fsPath)) {
// const document = await vscode.workspace.openTextDocument(readmeUri)
// await vscode.window.showTextDocument(document)
// } else {
// getLogger().warn(
// localize('AWS.serverlessLand.readme.notFound', 'README.md file not found in the project directory')
// )
// }
} catch (err) {
createResult = getTelemetryResult(err)
reason = getTelemetryResult(err)

globals.outputChannel.show(true)
getLogger().error(
localize('AWS.samcli.initWizard.general.error', 'Error creating new SAM Application. {0}', checklogs())
)

getLogger().error('Error creating new SAM Application: %O', err as Error)
} finally {
// add telemetry
telemetry.sam_init.emit({
result: createResult,
reason: reason,
})
}
}
Loading

0 comments on commit bb4eeef

Please sign in to comment.