Skip to content

Commit 403a8de

Browse files
Vandita2020nkomonen-amazon
authored andcommitted
feat(lambda): link for serverlessland, fixes aws#6687
## Problem This PR adds the functionality to open pattern in serverless-land website. It addresses an issue with the `metadata.json` file path for the extension by specifying the path after the build step in the `copyFile.ts` file. ## Solution Changes: 1. Removed the webview functionality and instead open the browser to preview the patterns. 2. Removed the Github button. 3. Added a link at the bottom of pattern quick pick to explore the [serverless land website](https://serverlessland.com/patterns?services=lambda). 4. Ensured the proper path for the metadata file is accessible and it gets executed properly after the build. 5. Added another entry point at the AWS Explorer high-level, accessible when clicking the three-dot menu.
1 parent 919f141 commit 403a8de

File tree

7 files changed

+70
-30
lines changed

7 files changed

+70
-30
lines changed

packages/core/package.nls.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,5 +462,5 @@
462462
"AWS.toolkit.lambda.walkthrough.step1.description": "Locally test and debug your code.",
463463
"AWS.toolkit.lambda.walkthrough.step2.title": "Deploy to the cloud",
464464
"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)",
465-
"AWS.toolkit.lambda.serverlessLand.quickpickTitle": "Create Lambda Application from template"
465+
"AWS.toolkit.lambda.serverlessLand.quickpickTitle": "Create application with Serverless template"
466466
}

packages/core/src/awsService/appBuilder/serverlessLand/main.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,8 @@ async function openReadmeFile(config: CreateServerlessLandWizardForm): Promise<v
115115
getLogger().warn('README.md file not found in the project directory')
116116
return
117117
}
118-
119118
await vscode.commands.executeCommand('workbench.action.focusFirstEditorGroup')
120-
await vscode.window.showTextDocument(readmeUri)
119+
await vscode.commands.executeCommand('markdown.showPreview', readmeUri)
121120
} catch (err) {
122121
getLogger().error(`Error in openReadmeFile: ${err}`)
123122
throw new ToolkitError('Error processing README file')

packages/core/src/awsService/appBuilder/serverlessLand/metadataManager.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
import * as nodefs from 'fs' // eslint-disable-line no-restricted-imports
66
import { ToolkitError } from '../../../shared/errors'
7-
import path from 'path'
7+
import globals from '../../../shared/extensionGlobals'
88

99
interface Implementation {
1010
iac: string
@@ -28,14 +28,6 @@ export interface ProjectMetadata {
2828
export class MetadataManager {
2929
private static instance: MetadataManager
3030
private metadata: ProjectMetadata | undefined
31-
private static readonly metadataPath = path.join(
32-
path.resolve(__dirname, '../../../../../'),
33-
'src',
34-
'awsService',
35-
'appBuilder',
36-
'serverlessLand',
37-
'metadata.json'
38-
)
3931

4032
private constructor() {}
4133

@@ -48,12 +40,17 @@ export class MetadataManager {
4840

4941
public static initialize(): MetadataManager {
5042
const instance = MetadataManager.getInstance()
51-
instance.loadMetadata(MetadataManager.metadataPath).catch((err) => {
43+
const metadataPath = instance.getMetadataPath()
44+
instance.loadMetadata(metadataPath).catch((err) => {
5245
throw new ToolkitError(`Failed to load metadata: ${err}`)
5346
})
5447
return instance
5548
}
5649

50+
public getMetadataPath(): string {
51+
return globals.context.asAbsolutePath('dist/src/serverlessLand/metadata.json')
52+
}
53+
5754
/**
5855
* Loads metadata from a JSON file
5956
* @param metadataPath Path to the metadata JSON file
@@ -117,6 +114,16 @@ export class MetadataManager {
117114
}))
118115
}
119116

117+
public getUrl(pattern: string): string {
118+
const patternData = this.metadata?.patterns?.[pattern]
119+
if (!patternData || !patternData.implementation) {
120+
return ''
121+
}
122+
const asset = patternData.implementation[0].assetName
123+
124+
return `https://serverlessland.com/patterns/${asset}`
125+
}
126+
120127
/**
121128
* Gets available Infrastructure as Code options for a specific pattern
122129
* @param pattern The pattern name to get IaC options for

packages/core/src/awsService/appBuilder/serverlessLand/wizard.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface CreateServerlessLandWizardForm {
2222
pattern: string
2323
runtime: string
2424
iac: string
25+
assetName: string
2526
}
2627

2728
function promptPattern(metadataManager: MetadataManager) {
@@ -37,11 +38,7 @@ function promptPattern(metadataManager: MetadataManager) {
3738
data: p.label,
3839
buttons: [
3940
{
40-
iconPath: new vscode.ThemeIcon('github'),
41-
tooltip: 'Open in GitHub',
42-
},
43-
{
44-
iconPath: new vscode.ThemeIcon('open-preview'),
41+
iconPath: new vscode.ThemeIcon('link-external'),
4542
tooltip: 'Open in Serverless Land',
4643
},
4744
],
@@ -74,7 +71,7 @@ function promptRuntime(metadataManager: MetadataManager, pattern: string | undef
7471
{
7572
title: localize('AWS.serverlessLand.initWizard.runtime.prompt', 'Select Runtime'),
7673
placeholder: 'Choose a runtime for your project',
77-
buttons: [vscode.QuickInputButtons.Back],
74+
buttons: createCommonButtons(),
7875
}
7976
)
8077
}
@@ -97,24 +94,25 @@ function promptIac(metadataManager: MetadataManager, pattern: string | undefined
9794
{
9895
title: localize('AWS.serverlessLand.initWizard.iac.prompt', 'Select IaC'),
9996
placeholder: 'Choose an IaC option for your project',
100-
buttons: [vscode.QuickInputButtons.Back],
97+
buttons: createCommonButtons(),
10198
}
10299
)
103100
}
104101

105102
function promptLocation() {
106103
return createFolderPrompt(vscode.workspace.workspaceFolders ?? [], {
107104
title: localize('AWS.serverlessLand.initWizard.location.prompt', 'Select Project Location'),
108-
buttons: [vscode.QuickInputButtons.Back],
109-
browseFolderDetail: 'Select a folder for your project',
105+
buttons: createCommonButtons(),
106+
browseFolderDetail: 'Select a parent folder for your project',
110107
})
111108
}
112109

113-
function promptName() {
110+
function promptName(location: vscode.Uri | undefined) {
111+
const folderName = location ? path.basename(location.fsPath) : ''
114112
return createInputBox({
115113
title: localize('AWS.serverlessLand.initWizard.name.prompt', 'Enter Project Name'),
116-
placeholder: 'Enter a name for your new application',
117-
buttons: [vscode.QuickInputButtons.Back],
114+
placeholder: ` ${folderName}/: Enter a name for your new application`,
115+
buttons: createCommonButtons(),
118116
validateInput: (value: string): string | undefined => {
119117
if (!value) {
120118
return 'Application name cannot be empty'
@@ -143,6 +141,6 @@ export class CreateServerlessLandWizard extends Wizard<CreateServerlessLandWizar
143141
this.form.runtime.bindPrompter((state) => promptRuntime(this.metadataManager, state.pattern))
144142
this.form.iac.bindPrompter((state) => promptIac(this.metadataManager, state.pattern))
145143
this.form.location.bindPrompter(() => promptLocation())
146-
this.form.name.bindPrompter(() => promptName())
144+
this.form.name.bindPrompter((state) => promptName(state.location))
147145
}
148146
}

packages/core/src/shared/ui/pickerPrompter.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { Prompter, PromptResult, Transform } from './prompter'
1212
import { assign, isAsyncIterable } from '../utilities/collectionUtils'
1313
import { recentlyUsed } from '../localizedText'
1414
import { getLogger } from '../logger/logger'
15+
import { openUrl } from '../utilities/vsCodeUtils'
16+
import { MetadataManager } from '../../awsService/appBuilder/serverlessLand/metadataManager'
1517

1618
const localize = nls.loadMessageBundle()
1719

@@ -143,6 +145,22 @@ export function createQuickPick<T>(
143145
assign(mergedOptions, picker)
144146
picker.buttons = mergedOptions.buttons ?? []
145147

148+
picker.onDidTriggerItemButton(async (event) => {
149+
const metadataManager = MetadataManager.getInstance()
150+
if (event.button.tooltip !== 'Open in Serverless Land') {
151+
return
152+
}
153+
const selectedPattern = event.item
154+
if (!selectedPattern) {
155+
return
156+
}
157+
const patternUrl = metadataManager.getUrl(selectedPattern.label)
158+
if (!patternUrl) {
159+
return
160+
}
161+
await openUrl(vscode.Uri.parse(patternUrl))
162+
})
163+
146164
const prompter =
147165
mergedOptions.filterBoxInputSettings !== undefined
148166
? new FilterBoxQuickPickPrompter<T>(picker, mergedOptions)

packages/toolkit/package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,24 +1327,29 @@
13271327
"group": "1_account@3"
13281328
},
13291329
{
1330-
"command": "aws.lambda.createNewSamApp",
1330+
"command": "aws.toolkit.lambda.createServerlessLandProject",
13311331
"when": "view == aws.explorer",
13321332
"group": "3_lambda@1"
13331333
},
13341334
{
1335-
"command": "aws.launchConfigForm",
1335+
"command": "aws.lambda.createNewSamApp",
13361336
"when": "view == aws.explorer",
13371337
"group": "3_lambda@2"
13381338
},
1339+
{
1340+
"command": "aws.launchConfigForm",
1341+
"when": "view == aws.explorer",
1342+
"group": "3_lambda@3"
1343+
},
13391344
{
13401345
"command": "aws.deploySamApplication",
13411346
"when": "config.aws.samcli.legacyDeploy && view == aws.explorer",
1342-
"group": "3_lambda@3"
1347+
"group": "3_lambda@4"
13431348
},
13441349
{
13451350
"command": "aws.samcli.sync",
13461351
"when": "!config.aws.samcli.legacyDeploy && view == aws.explorer",
1347-
"group": "3_lambda@3"
1352+
"group": "3_lambda@4"
13481353
},
13491354
{
13501355
"submenu": "aws.toolkit.submenu.feedback",

packages/toolkit/scripts/build/copyFiles.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ const tasks: CopyTask[] = [
6969
destination: path.join('src', 'stepFunctions', 'asl', 'aslServer.js'),
7070
},
7171

72+
// Serverless Land
73+
{
74+
target: path.join(
75+
'../../node_modules/aws-core-vscode',
76+
'src',
77+
'awsService',
78+
'appBuilder',
79+
'serverlessLand',
80+
'metadata.json'
81+
),
82+
destination: path.join('src', 'serverlessLand', 'metadata.json'),
83+
},
84+
7285
// Vue
7386
{
7487
target: path.join('../core', 'resources', 'js', 'vscode.js'),

0 commit comments

Comments
 (0)