-
Notifications
You must be signed in to change notification settings - Fork 642
feat(lambda): download serverless land patterns in IDE #6612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,21 +4,17 @@ | |
*/ | ||
import * as nodefs from 'fs' // eslint-disable-line no-restricted-imports | ||
import { ToolkitError } from '../../../shared/errors' | ||
import path from 'path' | ||
|
||
interface IaC { | ||
id: string | ||
name: string | ||
} | ||
interface Runtime { | ||
id: string | ||
name: string | ||
version: string | ||
interface Implementation { | ||
iac: string | ||
runtime: string | ||
assetName: string | ||
} | ||
interface PatternData { | ||
name: string | ||
description: string | ||
runtimes: Runtime[] | ||
iac: IaC[] | ||
implementation: Implementation[] | ||
} | ||
|
||
export interface ProjectMetadata { | ||
|
@@ -32,6 +28,14 @@ export interface ProjectMetadata { | |
export class MetadataManager { | ||
private static instance: MetadataManager | ||
private metadata: ProjectMetadata | undefined | ||
private static readonly metadataPath = path.join( | ||
path.resolve(__dirname, '../../../../../'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you're probably going to wait to integrate with our copyFiles scripts. This path probably exists in the extension debug mode but I don't think it exists in the actual build. Instead, you will need to copy this file to the resources file and pull from that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I have made the changes in the path with the copyFiles scripts in the next PR and it is working correctly too. |
||
'src', | ||
'awsService', | ||
'appBuilder', | ||
'serverlessLand', | ||
'metadata.json' | ||
) | ||
|
||
private constructor() {} | ||
|
||
|
@@ -42,6 +46,14 @@ export class MetadataManager { | |
return MetadataManager.instance | ||
} | ||
|
||
public static initialize(): MetadataManager { | ||
const instance = MetadataManager.getInstance() | ||
instance.loadMetadata(MetadataManager.metadataPath).catch((err) => { | ||
throw new ToolkitError(`Failed to load metadata: ${err}`) | ||
}) | ||
return instance | ||
} | ||
|
||
/** | ||
* Loads metadata from a JSON file | ||
* @param metadataPath Path to the metadata JSON file | ||
|
@@ -96,11 +108,12 @@ export class MetadataManager { | |
*/ | ||
public getRuntimes(pattern: string): { label: string }[] { | ||
const patternData = this.metadata?.patterns?.[pattern] | ||
if (!patternData || !patternData.runtimes) { | ||
if (!patternData || !patternData.implementation) { | ||
return [] | ||
} | ||
return patternData.runtimes.map((runtime) => ({ | ||
label: runtime.name, | ||
const uniqueRuntimes = new Set(patternData.implementation.map((item) => item.runtime)) | ||
return Array.from(uniqueRuntimes).map((runtime) => ({ | ||
label: runtime, | ||
})) | ||
} | ||
|
||
|
@@ -111,11 +124,22 @@ export class MetadataManager { | |
*/ | ||
public getIacOptions(pattern: string): { label: string }[] { | ||
const patternData = this.metadata?.patterns?.[pattern] | ||
if (!patternData || !patternData.iac) { | ||
if (!patternData || !patternData.implementation) { | ||
return [] | ||
} | ||
return patternData.iac.map((iac) => ({ | ||
label: iac.name, | ||
const uniqueIaCs = new Set(patternData.implementation.map((item) => item.iac)) | ||
return Array.from(uniqueIaCs).map((iac) => ({ | ||
label: iac, | ||
})) | ||
} | ||
public getAssetName(selectedPattern: string, selectedRuntime: string, selectedIaC: string): string { | ||
const patternData = this.metadata?.patterns?.[selectedPattern] | ||
if (!patternData || !patternData.implementation) { | ||
return '' | ||
} | ||
const matchingImplementation = patternData.implementation.find( | ||
(impl) => impl.runtime === selectedRuntime && impl.iac === selectedIaC | ||
) | ||
return matchingImplementation?.assetName ?? '' | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.