Skip to content

Commit

Permalink
Fixing bug bash changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Vandita Patidar committed Feb 26, 2025
1 parent d5698e9 commit 1010f9c
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 81 deletions.
2 changes: 1 addition & 1 deletion packages/core/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -437,5 +437,5 @@
"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.serverlessLand.quickpickTitle": "Create Lambda Application from template"
"AWS.toolkit.lambda.serverlessLand.quickpickTitle": "Create application with Serverless template"
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ async function openReadmeFile(config: CreateServerlessLandWizardForm): Promise<v
getLogger().warn('README.md file not found in the project directory')
return
}
await new Promise((resolve) => setTimeout(resolve, 1000))

await vscode.commands.executeCommand('workbench.action.focusFirstEditorGroup')
await vscode.window.showTextDocument(readmeUri)
await vscode.commands.executeCommand('markdown.showPreview', readmeUri)
} catch (err) {
getLogger().error(`Error in openReadmeFile: ${err}`)
throw new ToolkitError('Error processing README file')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"s3-lambda-resizing-sam": {
"name": "Resizing image",
"description": "Lambda, S3 • Python, Javascript, Java, .NET • SAM",
"gitUrl": "https://github.com/aws-samples/serverless-patterns/tree/main/s3-lambda-resizing-python",
"implementation": [
{
"iac": "sam",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import * as nodefs from 'fs' // eslint-disable-line no-restricted-imports
import { ToolkitError } from '../../../shared/errors'
import path from 'path'
import { ExtensionContext } from 'vscode'

interface Implementation {
iac: string
Expand Down Expand Up @@ -32,14 +33,6 @@ export interface ProjectMetadata {
export class MetadataManager {
private static instance: MetadataManager
private metadata: ProjectMetadata | undefined
private static readonly metadataPath = path.join(
path.resolve(__dirname, '../../../../../'),
'src',
'awsService',
'appBuilder',
'serverlessLand',
'metadata.json'
)

private constructor() {}

Expand All @@ -50,14 +43,19 @@ export class MetadataManager {
return MetadataManager.instance
}

public static initialize(): MetadataManager {
public static initialize(ctx: ExtensionContext): MetadataManager {
const instance = MetadataManager.getInstance()
instance.loadMetadata(MetadataManager.metadataPath).catch((err) => {
const metadataPath = instance.getMetadataPath(ctx)
instance.loadMetadata(metadataPath).catch((err) => {
throw new ToolkitError(`Failed to load metadata: ${err}`)
})
return instance
}

public getMetadataPath(ctx: ExtensionContext): string {
return ctx.asAbsolutePath(path.join('dist', 'src', 'serverlessLand', 'metadata.json'))
}

/**
* Loads metadata from a JSON file
* @param metadataPath Path to the metadata JSON file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,40 +34,4 @@ export class WebviewService {
</html>
`
}

public static getGitWebviewContent(url: string): string {
const htmlContent = `
<html>
<head>
<meta http-equiv="refresh" content="0; url=${url}">
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
font-family: var(--vscode-font-family);
}
p {
text-align: center;
padding: 20px;
}
a {
color: var(--vscode-textLink-foreground);
text-decoration: none;
}
a:hover {
text-decoration: underline;
color: var(--vscode-textLink-activeForeground);
}
</style>
</head>
<body>
<p>To preview GitHub page, <a href="${url}">click here</a>.</p>
</body>
</html>
`
return htmlContent
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function promptPattern(metadataManager: MetadataManager) {
throw new ToolkitError('No patterns found in metadata')
}

const quickPick = createQuickPick<string>(
return createQuickPick<string>(
patterns.map((p) => ({
label: p.label,
detail: p.description,
Expand All @@ -56,8 +56,6 @@ function promptPattern(metadataManager: MetadataManager) {
matchOnDetail: true,
}
)

return quickPick
}

function promptRuntime(metadataManager: MetadataManager, pattern: string | undefined) {
Expand Down Expand Up @@ -142,7 +140,7 @@ export class CreateServerlessLandWizard extends Wizard<CreateServerlessLandWizar
super({
exitPrompterProvider: createExitPrompter,
})
this.metadataManager = MetadataManager.initialize()
this.metadataManager = MetadataManager.initialize(context.ctx)
this.form.pattern.bindPrompter(() => promptPattern(this.metadataManager))
this.form.runtime.bindPrompter((state) => promptRuntime(this.metadataManager, state.pattern))
this.form.iac.bindPrompter((state) => promptIac(this.metadataManager, state.pattern))
Expand Down
46 changes: 22 additions & 24 deletions packages/core/src/shared/ui/pickerPrompter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export function createQuickPick<T>(
const mergedOptions = { ...defaultQuickpickOptions, ...options }
assign(mergedOptions, picker)
picker.buttons = mergedOptions.buttons ?? []
let serverlessPanel: vscode.WebviewPanel | undefined

picker.onDidTriggerItemButton(async (event) => {
const metadataManager = MetadataManager.getInstance()
Expand All @@ -153,31 +154,28 @@ export function createQuickPick<T>(
const patternUrl = metadataManager.getUrl(selectedPattern.label)
if (patternUrl) {
if (event.button.tooltip === 'Open in GitHub') {
const panel = vscode.window.createWebviewPanel(
'githubPreview',
`GitHub Repository ${selectedPattern.label}`,
vscode.ViewColumn.One,
{
enableScripts: true,
retainContextWhenHidden: true,
enableCommandUris: true,
enableFindWidget: true,
}
)
panel.webview.html = WebviewService.getGitWebviewContent(patternUrl.githubUrl)
await vscode.env.openExternal(vscode.Uri.parse(patternUrl.githubUrl))
} else if (event.button.tooltip === 'Open in Serverless Land') {
const panel = vscode.window.createWebviewPanel(
'serverlessLandPreview',
'Serverless Land Preview',
vscode.ViewColumn.One,
{
enableScripts: true,
retainContextWhenHidden: true,
enableCommandUris: true,
enableFindWidget: true,
}
)
panel.webview.html = WebviewService.getWebviewContent(patternUrl.previewUrl)
if (!serverlessPanel) {
serverlessPanel = vscode.window.createWebviewPanel(
'serverlessLandPreview',
`${selectedPattern.label}`,
vscode.ViewColumn.One,
{
enableScripts: true,
retainContextWhenHidden: true,
enableCommandUris: false,
enableFindWidget: true,
}
)
serverlessPanel.onDidDispose(() => {
serverlessPanel = undefined
})
} else {
serverlessPanel.title = `${selectedPattern.label}`
}
serverlessPanel.webview.html = WebviewService.getWebviewContent(patternUrl.previewUrl)
serverlessPanel.reveal()
}
}
}
Expand Down
13 changes: 9 additions & 4 deletions packages/toolkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1327,24 +1327,29 @@
"group": "1_account@3"
},
{
"command": "aws.lambda.createNewSamApp",
"command": "aws.toolkit.lambda.createServerlessLandProject",
"when": "view == aws.explorer",
"group": "3_lambda@1"
},
{
"command": "aws.launchConfigForm",
"command": "aws.lambda.createNewSamApp",
"when": "view == aws.explorer",
"group": "3_lambda@2"
},
{
"command": "aws.launchConfigForm",
"when": "view == aws.explorer",
"group": "3_lambda@3"
},
{
"command": "aws.deploySamApplication",
"when": "config.aws.samcli.legacyDeploy && view == aws.explorer",
"group": "3_lambda@3"
"group": "3_lambda@4"
},
{
"command": "aws.samcli.sync",
"when": "!config.aws.samcli.legacyDeploy && view == aws.explorer",
"group": "3_lambda@3"
"group": "3_lambda@4"
},
{
"submenu": "aws.toolkit.submenu.feedback",
Expand Down

0 comments on commit 1010f9c

Please sign in to comment.