Skip to content

Commit 1010f9c

Browse files
author
Vandita Patidar
committed
Fixing bug bash changes
1 parent d5698e9 commit 1010f9c

File tree

8 files changed

+44
-81
lines changed

8 files changed

+44
-81
lines changed

packages/core/package.nls.json

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

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,10 @@ async function openReadmeFile(config: CreateServerlessLandWizardForm): Promise<v
118118
getLogger().warn('README.md file not found in the project directory')
119119
return
120120
}
121+
await new Promise((resolve) => setTimeout(resolve, 1000))
121122

122123
await vscode.commands.executeCommand('workbench.action.focusFirstEditorGroup')
123-
await vscode.window.showTextDocument(readmeUri)
124+
await vscode.commands.executeCommand('markdown.showPreview', readmeUri)
124125
} catch (err) {
125126
getLogger().error(`Error in openReadmeFile: ${err}`)
126127
throw new ToolkitError('Error processing README file')

packages/core/src/awsService/appBuilder/serverlessLand/metadata.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"s3-lambda-resizing-sam": {
44
"name": "Resizing image",
55
"description": "Lambda, S3 • Python, Javascript, Java, .NET • SAM",
6-
"gitUrl": "https://github.com/aws-samples/serverless-patterns/tree/main/s3-lambda-resizing-python",
76
"implementation": [
87
{
98
"iac": "sam",

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import * as nodefs from 'fs' // eslint-disable-line no-restricted-imports
66
import { ToolkitError } from '../../../shared/errors'
77
import path from 'path'
8+
import { ExtensionContext } from 'vscode'
89

910
interface Implementation {
1011
iac: string
@@ -32,14 +33,6 @@ export interface ProjectMetadata {
3233
export class MetadataManager {
3334
private static instance: MetadataManager
3435
private metadata: ProjectMetadata | undefined
35-
private static readonly metadataPath = path.join(
36-
path.resolve(__dirname, '../../../../../'),
37-
'src',
38-
'awsService',
39-
'appBuilder',
40-
'serverlessLand',
41-
'metadata.json'
42-
)
4336

4437
private constructor() {}
4538

@@ -50,14 +43,19 @@ export class MetadataManager {
5043
return MetadataManager.instance
5144
}
5245

53-
public static initialize(): MetadataManager {
46+
public static initialize(ctx: ExtensionContext): MetadataManager {
5447
const instance = MetadataManager.getInstance()
55-
instance.loadMetadata(MetadataManager.metadataPath).catch((err) => {
48+
const metadataPath = instance.getMetadataPath(ctx)
49+
instance.loadMetadata(metadataPath).catch((err) => {
5650
throw new ToolkitError(`Failed to load metadata: ${err}`)
5751
})
5852
return instance
5953
}
6054

55+
public getMetadataPath(ctx: ExtensionContext): string {
56+
return ctx.asAbsolutePath(path.join('dist', 'src', 'serverlessLand', 'metadata.json'))
57+
}
58+
6159
/**
6260
* Loads metadata from a JSON file
6361
* @param metadataPath Path to the metadata JSON file

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

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -34,40 +34,4 @@ export class WebviewService {
3434
</html>
3535
`
3636
}
37-
38-
public static getGitWebviewContent(url: string): string {
39-
const htmlContent = `
40-
<html>
41-
<head>
42-
<meta http-equiv="refresh" content="0; url=${url}">
43-
<style>
44-
body {
45-
display: flex;
46-
justify-content: center;
47-
align-items: center;
48-
height: 100vh;
49-
margin: 0;
50-
font-family: var(--vscode-font-family);
51-
}
52-
p {
53-
text-align: center;
54-
padding: 20px;
55-
}
56-
a {
57-
color: var(--vscode-textLink-foreground);
58-
text-decoration: none;
59-
}
60-
a:hover {
61-
text-decoration: underline;
62-
color: var(--vscode-textLink-activeForeground);
63-
}
64-
</style>
65-
</head>
66-
<body>
67-
<p>To preview GitHub page, <a href="${url}">click here</a>.</p>
68-
</body>
69-
</html>
70-
`
71-
return htmlContent
72-
}
7337
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function promptPattern(metadataManager: MetadataManager) {
3232
throw new ToolkitError('No patterns found in metadata')
3333
}
3434

35-
const quickPick = createQuickPick<string>(
35+
return createQuickPick<string>(
3636
patterns.map((p) => ({
3737
label: p.label,
3838
detail: p.description,
@@ -56,8 +56,6 @@ function promptPattern(metadataManager: MetadataManager) {
5656
matchOnDetail: true,
5757
}
5858
)
59-
60-
return quickPick
6159
}
6260

6361
function promptRuntime(metadataManager: MetadataManager, pattern: string | undefined) {
@@ -142,7 +140,7 @@ export class CreateServerlessLandWizard extends Wizard<CreateServerlessLandWizar
142140
super({
143141
exitPrompterProvider: createExitPrompter,
144142
})
145-
this.metadataManager = MetadataManager.initialize()
143+
this.metadataManager = MetadataManager.initialize(context.ctx)
146144
this.form.pattern.bindPrompter(() => promptPattern(this.metadataManager))
147145
this.form.runtime.bindPrompter((state) => promptRuntime(this.metadataManager, state.pattern))
148146
this.form.iac.bindPrompter((state) => promptIac(this.metadataManager, state.pattern))

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

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ export function createQuickPick<T>(
144144
const mergedOptions = { ...defaultQuickpickOptions, ...options }
145145
assign(mergedOptions, picker)
146146
picker.buttons = mergedOptions.buttons ?? []
147+
let serverlessPanel: vscode.WebviewPanel | undefined
147148

148149
picker.onDidTriggerItemButton(async (event) => {
149150
const metadataManager = MetadataManager.getInstance()
@@ -153,31 +154,28 @@ export function createQuickPick<T>(
153154
const patternUrl = metadataManager.getUrl(selectedPattern.label)
154155
if (patternUrl) {
155156
if (event.button.tooltip === 'Open in GitHub') {
156-
const panel = vscode.window.createWebviewPanel(
157-
'githubPreview',
158-
`GitHub Repository ${selectedPattern.label}`,
159-
vscode.ViewColumn.One,
160-
{
161-
enableScripts: true,
162-
retainContextWhenHidden: true,
163-
enableCommandUris: true,
164-
enableFindWidget: true,
165-
}
166-
)
167-
panel.webview.html = WebviewService.getGitWebviewContent(patternUrl.githubUrl)
157+
await vscode.env.openExternal(vscode.Uri.parse(patternUrl.githubUrl))
168158
} else if (event.button.tooltip === 'Open in Serverless Land') {
169-
const panel = vscode.window.createWebviewPanel(
170-
'serverlessLandPreview',
171-
'Serverless Land Preview',
172-
vscode.ViewColumn.One,
173-
{
174-
enableScripts: true,
175-
retainContextWhenHidden: true,
176-
enableCommandUris: true,
177-
enableFindWidget: true,
178-
}
179-
)
180-
panel.webview.html = WebviewService.getWebviewContent(patternUrl.previewUrl)
159+
if (!serverlessPanel) {
160+
serverlessPanel = vscode.window.createWebviewPanel(
161+
'serverlessLandPreview',
162+
`${selectedPattern.label}`,
163+
vscode.ViewColumn.One,
164+
{
165+
enableScripts: true,
166+
retainContextWhenHidden: true,
167+
enableCommandUris: false,
168+
enableFindWidget: true,
169+
}
170+
)
171+
serverlessPanel.onDidDispose(() => {
172+
serverlessPanel = undefined
173+
})
174+
} else {
175+
serverlessPanel.title = `${selectedPattern.label}`
176+
}
177+
serverlessPanel.webview.html = WebviewService.getWebviewContent(patternUrl.previewUrl)
178+
serverlessPanel.reveal()
181179
}
182180
}
183181
}

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",

0 commit comments

Comments
 (0)