-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into ecs/compile
- Loading branch information
Showing
9 changed files
with
199 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import * as fs from 'fs-extra'; | ||
|
||
export interface ModuleDefinition { | ||
readonly namespace: string; | ||
readonly moduleName: string; | ||
readonly moduleFamily: string; | ||
readonly moduleBaseName: string; | ||
readonly packageName: string; | ||
|
||
readonly dotnetPackage: string; | ||
readonly javaGroupId: string; | ||
readonly javaPackage: string; | ||
readonly javaArtifactId: string; | ||
|
||
readonly pythonDistName: string; | ||
readonly pythonModuleName: string; | ||
} | ||
|
||
export function createModuleDefinitionFromCfnNamespace(namespace: string): ModuleDefinition { | ||
const [moduleFamily, moduleBaseName] = (namespace === 'AWS::Serverless' ? 'AWS::SAM' : namespace).split('::'); | ||
const moduleName = `${moduleFamily}-${moduleBaseName.replace(/V\d+$/, '')}`.toLocaleLowerCase(); | ||
|
||
const lowcaseModuleName = moduleBaseName.toLocaleLowerCase(); | ||
const packageName = `@aws-cdk/${moduleName}`; | ||
|
||
// dotnet names | ||
const dotnetPackage = `Amazon.CDK.${moduleFamily}.${moduleBaseName}`; | ||
|
||
// java names | ||
const javaGroupId = 'software.amazon.awscdk'; | ||
const javaPackage = moduleFamily === 'AWS' | ||
? `services.${lowcaseModuleName}` | ||
: `${moduleFamily.toLocaleLowerCase()}.${lowcaseModuleName}`; | ||
const javaArtifactId = moduleFamily === 'AWS' | ||
? lowcaseModuleName | ||
: `${moduleFamily.toLocaleLowerCase()}-${lowcaseModuleName}`; | ||
|
||
// python names | ||
const pythonDistName = `aws-cdk.${moduleName}`; | ||
const pythonModuleName = pythonDistName.replace(/-/g, '_'); | ||
|
||
return { | ||
namespace, | ||
moduleName, | ||
moduleFamily, | ||
moduleBaseName, | ||
packageName, | ||
dotnetPackage, | ||
javaGroupId, | ||
javaPackage, | ||
javaArtifactId, | ||
pythonDistName, | ||
pythonModuleName, | ||
}; | ||
} | ||
|
||
export async function createLibraryReadme(namespace: string, readmePath: string) { | ||
const module = createModuleDefinitionFromCfnNamespace(namespace); | ||
|
||
await fs.writeFile(readmePath, [ | ||
`# ${namespace} Construct Library`, | ||
'<!--BEGIN STABILITY BANNER-->', | ||
'', | ||
'---', | ||
'', | ||
'![cfn-resources: Stable](https://img.shields.io/badge/cfn--resources-stable-success.svg?style=for-the-badge)', | ||
'', | ||
'> All classes with the `Cfn` prefix in this module ([CFN Resources]) are always stable and safe to use.', | ||
'>', | ||
'> [CFN Resources]: https://docs.aws.amazon.com/cdk/latest/guide/constructs.html#constructs_lib', | ||
'', | ||
'---', | ||
'', | ||
'<!--END STABILITY BANNER-->', | ||
'', | ||
'This module is part of the [AWS Cloud Development Kit](https://github.com/aws/aws-cdk) project.', | ||
'', | ||
'```ts', | ||
`import ${module.moduleName.toLocaleLowerCase()} = require('${module.packageName}');`, | ||
'```', | ||
'', | ||
].join('\n'), 'utf8'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { createModuleDefinitionFromCfnNamespace } from '../lib'; | ||
|
||
describe('createModuleDefinitionFromCfnNamespace', () => { | ||
|
||
test('base case', () => { | ||
const module = createModuleDefinitionFromCfnNamespace('AWS::EC2'); | ||
|
||
expect(module).toEqual({ | ||
namespace: 'AWS::EC2', | ||
moduleName: 'aws-ec2', | ||
moduleFamily: 'AWS', | ||
moduleBaseName: 'EC2', | ||
packageName: '@aws-cdk/aws-ec2', | ||
dotnetPackage: 'Amazon.CDK.AWS.EC2', | ||
javaGroupId: 'software.amazon.awscdk', | ||
javaPackage: 'services.ec2', | ||
javaArtifactId: 'ec2', | ||
pythonDistName: 'aws-cdk.aws-ec2', | ||
pythonModuleName: 'aws_cdk.aws_ec2', | ||
}); | ||
}); | ||
|
||
test('Serverless is special-cased to SAM', () => { | ||
const module = createModuleDefinitionFromCfnNamespace('AWS::Serverless'); | ||
|
||
expect(module).toEqual({ | ||
namespace: 'AWS::Serverless', | ||
moduleName: 'aws-sam', | ||
moduleFamily: 'AWS', | ||
moduleBaseName: 'SAM', | ||
packageName: '@aws-cdk/aws-sam', | ||
dotnetPackage: 'Amazon.CDK.AWS.SAM', | ||
javaGroupId: 'software.amazon.awscdk', | ||
javaPackage: 'services.sam', | ||
javaArtifactId: 'sam', | ||
pythonDistName: 'aws-cdk.aws-sam', | ||
pythonModuleName: 'aws_cdk.aws_sam', | ||
}); | ||
}); | ||
|
||
test('Java artifacts use different package/artifact when module family is not AWS', () => { | ||
const module = createModuleDefinitionFromCfnNamespace('Alexa::ASK'); | ||
|
||
expect(module).toEqual({ | ||
namespace: 'Alexa::ASK', | ||
moduleName: 'alexa-ask', | ||
moduleFamily: 'Alexa', | ||
moduleBaseName: 'ASK', | ||
packageName: '@aws-cdk/alexa-ask', | ||
dotnetPackage: 'Amazon.CDK.Alexa.ASK', | ||
javaGroupId: 'software.amazon.awscdk', | ||
javaPackage: 'alexa.ask', | ||
javaArtifactId: 'alexa-ask', | ||
pythonDistName: 'aws-cdk.alexa-ask', | ||
pythonModuleName: 'aws_cdk.alexa_ask', | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.