Skip to content

Commit

Permalink
Merge branch 'master' into ecs/compile
Browse files Browse the repository at this point in the history
  • Loading branch information
kaizencc authored Oct 12, 2021
2 parents 71bf5ee + 0dcd9ec commit 4e4f37c
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 80 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/assertions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"package": "software.amazon.awscdk.assertions",
"maven": {
"groupId": "software.amazon.awscdk",
"artifactId": "cdk-assertions"
"artifactId": "assertions"
}
},
"dotnet": {
Expand Down
83 changes: 21 additions & 62 deletions packages/@aws-cdk/cfnspec/build-tools/create-missing-libraries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,9 @@ async function main() {

// iterate over all cloudformation namespaces
for (const namespace of cfnspec.namespaces()) {
const [moduleFamily, moduleBaseName] = (namespace === 'AWS::Serverless' ? 'AWS::SAM' : namespace).split('::');

const moduleName = `${moduleFamily}-${moduleBaseName.replace(/V\d+$/, '')}`.toLocaleLowerCase();
const packagePath = path.join(root, moduleName);

const lowcaseModuleName = moduleBaseName.toLocaleLowerCase();
const packageName = `@aws-cdk/${moduleName}`;
const module = cfnspec.createModuleDefinitionFromCfnNamespace(namespace);
const lowcaseModuleName = module.moduleName.toLocaleLowerCase();
const packagePath = path.join(root, module.moduleName);

// we already have a module for this namesapce, move on.
if (await fs.pathExists(packagePath)) {
Expand All @@ -42,12 +38,12 @@ async function main() {
if (scopes.indexOf(namespace) !== -1) {
// V2-style module is already modeled in the root package, nothing to be done!
continue;
} else if (await fs.pathExists(path.join(root, `${moduleFamily}-${moduleBaseName}`.toLocaleLowerCase()))) {
} else if (await fs.pathExists(path.join(root, `${module.moduleFamily}-${module.moduleBaseName}`.toLocaleLowerCase()))) {
// V2-style package already has it's own package (legacy behavior), nothing to be done!
continue;
} else {
// V2-style package needs to be added to it's "V1" package... Get down to business!
console.error(`Adding ${namespace} to ${packageName}`);
console.error(`Adding ${namespace} to ${module.packageName}`);
scopes.push(namespace);
packageJson['cdk-build'].cloudformation = scopes;
await fs.writeJson(packageJsonPath, packageJson, { encoding: 'utf-8', spaces: 2 });
Expand All @@ -62,22 +58,6 @@ async function main() {
}
}

// 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, '_');

async function write(relativePath: string, contents: string[] | string | object) {
const fullPath = path.join(packagePath, relativePath);
const dir = path.dirname(fullPath);
Expand All @@ -97,10 +77,10 @@ async function main() {
await fs.writeFile(fullPath, data + '\n');
}

console.log(`generating module for ${packageName}...`);
console.log(`generating module for ${module.packageName}...`);

await write('package.json', {
name: packageName,
name: module.packageName,
version,
description: `The CDK Construct Library for ${namespace}`,
main: 'lib/index.js',
Expand All @@ -110,33 +90,33 @@ async function main() {
projectReferences: true,
targets: {
dotnet: {
namespace: dotnetPackage,
packageId: dotnetPackage,
namespace: module.dotnetPackage,
packageId: module.dotnetPackage,
signAssembly: true,
assemblyOriginatorKeyFile: '../../key.snk',
iconUrl: 'https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png',
},
java: {
package: `${javaGroupId}.${javaPackage}`,
package: `${module.javaGroupId}.${module.javaPackage}`,
maven: {
groupId: javaGroupId,
artifactId: javaArtifactId,
groupId: module.javaGroupId,
artifactId: module.javaArtifactId,
},
},
python: {
classifiers: [
'Framework :: AWS CDK',
'Framework :: AWS CDK :: 1',
],
distName: pythonDistName,
module: pythonModuleName,
distName: module.pythonDistName,
module: module.pythonModuleName,
},
},
},
repository: {
type: 'git',
url: 'https://github.com/aws/aws-cdk.git',
directory: `packages/${packageName}`,
directory: `packages/${module.packageName}`,
},
homepage: 'https://github.com/aws/aws-cdk',
scripts: {
Expand Down Expand Up @@ -169,7 +149,7 @@ async function main() {
'cdk',
'constructs',
namespace,
moduleName,
module.moduleName,
],
author: {
name: 'Amazon Web Services',
Expand Down Expand Up @@ -271,28 +251,7 @@ async function main() {
'});',
]);

await write('README.md', [
`# ${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 ${lowcaseModuleName} = require('${packageName}');`,
'```',
]);
await cfnspec.createLibraryReadme(namespace, path.join(packagePath, 'README.md'));

await write('.eslintrc.js', [
"const baseConfig = require('@aws-cdk/cdk-build-tools/config/eslintrc');",
Expand All @@ -310,10 +269,10 @@ async function main() {
await fs.copy(path.join(templateDir, file), path.join(packagePath, file));
}

await addDependencyToMegaPackage(path.join('@aws-cdk', 'cloudformation-include'), packageName, version, ['dependencies', 'peerDependencies']);
await addDependencyToMegaPackage('aws-cdk-lib', packageName, version, ['devDependencies']);
await addDependencyToMegaPackage('monocdk', packageName, version, ['devDependencies']);
await addDependencyToMegaPackage('decdk', packageName, version, ['dependencies']);
await addDependencyToMegaPackage(path.join('@aws-cdk', 'cloudformation-include'), module.packageName, version, ['dependencies', 'peerDependencies']);
await addDependencyToMegaPackage('aws-cdk-lib', module.packageName, version, ['devDependencies']);
await addDependencyToMegaPackage('monocdk', module.packageName, version, ['devDependencies']);
await addDependencyToMegaPackage('decdk', module.packageName, version, ['dependencies']);
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/cfnspec/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CfnLintFileSchema } from './_private_schema/cfn-lint';
import * as schema from './schema';
export { schema };
export * from './canned-metrics';
export * from './library-creation';

/**
* The complete AWS CloudFormation Resource specification, having any CDK patches and enhancements included in it.
Expand Down
83 changes: 83 additions & 0 deletions packages/@aws-cdk/cfnspec/lib/library-creation.ts
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');
}
2 changes: 1 addition & 1 deletion packages/@aws-cdk/cfnspec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
"@types/jest": "^26.0.24",
"@types/md5": "^2.3.1",
"fast-json-patch": "^2.2.1",
"fs-extra": "^9.1.0",
"jest": "^26.6.3",
"json-diff": "^0.5.4",
"sort-json": "^2.0.0"
},
"dependencies": {
"fs-extra": "^9.1.0",
"md5": "^2.3.0"
},
"repository": {
Expand Down
59 changes: 59 additions & 0 deletions packages/@aws-cdk/cfnspec/test/libary-creation.test.ts
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',
});
});

});
37 changes: 22 additions & 15 deletions tools/@aws-cdk/pkglint/lib/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import {
monoRepoRoot,
} from './util';

const AWS_SERVICE_NAMES = require('./aws-service-official-names.json'); // eslint-disable-line @typescript-eslint/no-require-imports

const PKGLINT_VERSION = require('../package.json').version; // eslint-disable-line @typescript-eslint/no-require-imports
const AWS_SERVICE_NAMES = require('./aws-service-official-names.json'); // eslint-disable-line @typescript-eslint/no-require-imports

/**
* Verify that the package name matches the directory name
Expand Down Expand Up @@ -831,25 +830,33 @@ function cdkModuleName(name: string) {
const isCdkPkg = name === '@aws-cdk/core';
const isLegacyCdkPkg = name === '@aws-cdk/cdk';

name = name.replace(/^aws-cdk-/, '');
name = name.replace(/^@aws-cdk\//, '');
let suffix = name;
suffix = suffix.replace(/^aws-cdk-/, '');
suffix = suffix.replace(/^@aws-cdk\//, '');

const dotnetSuffix = name.split('-')
const dotnetSuffix = suffix.split('-')
.map(s => s === 'aws' ? 'AWS' : caseUtils.pascal(s))
.join('.');

const pythonName = name.replace(/^@/g, '').replace(/\//g, '.').split('.').map(caseUtils.kebab).join('.');
const pythonName = suffix.replace(/^@/g, '').replace(/\//g, '.').split('.').map(caseUtils.kebab).join('.');

// list of packages with special-cased Maven ArtifactId.
const mavenIdMap: Record<string, string> = {
'@aws-cdk/core': 'core',
'@aws-cdk/cdk': 'cdk',
'@aws-cdk/assertions': 'assertions',
'@aws-cdk/assertions-alpha': 'assertions-alpha',
};
/* eslint-disable @typescript-eslint/indent */
const mavenArtifactId =
name in mavenIdMap ? mavenIdMap[name] :
(suffix.startsWith('aws-') || suffix.startsWith('alexa-')) ? suffix.replace(/aws-/, '') :
suffix.startsWith('cdk-') ? suffix : `cdk-${suffix}`;
/* eslint-enable @typescript-eslint/indent */

return {
javaPackage: `software.amazon.awscdk${isLegacyCdkPkg ? '' : `.${name.replace(/aws-/, 'services-').replace(/-/g, '.')}`}`,
mavenArtifactId:
isLegacyCdkPkg
? 'cdk'
: (isCdkPkg
? 'core'
: (name.startsWith('aws-') || name.startsWith('alexa-')
? name.replace(/aws-/, '')
: (name.startsWith('cdk-') ? name : `cdk-${name}`))),
javaPackage: `software.amazon.awscdk${isLegacyCdkPkg ? '' : `.${suffix.replace(/aws-/, 'services-').replace(/-/g, '.')}`}`,
mavenArtifactId,
dotnetNamespace: `Amazon.CDK${isCdkPkg ? '' : `.${dotnetSuffix}`}`,
python: {
distName: `aws-cdk.${pythonName}`,
Expand Down
Loading

0 comments on commit 4e4f37c

Please sign in to comment.