Skip to content

Commit 84e4980

Browse files
authored
feat: initial implementation of cdk-specific project types (#1)
* feat: initial implementation of cdk-specific project types * update projen * move all cdklabs related things into cdklabs.ts * syling changes * snapshots
1 parent b24b86b commit 84e4980

16 files changed

+20727
-22
lines changed

.projen/deps.json

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projenrc.js

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
const { cdk } = require("projen");
1+
const { cdk } = require('projen');
22
const project = new cdk.JsiiProject({
3-
author: "AWS",
4-
authorAddress: "[email protected]",
5-
defaultReleaseBranch: "main",
6-
name: "cdklabs-projen-project-types",
7-
repositoryUrl: "https://github.com/cdklabs/cdklabs-projen-project-types.git",
8-
9-
// deps: [], /* Runtime dependencies of this module. */
10-
// description: undefined, /* The description is just a string that helps people understand the purpose of the package. */
11-
// devDeps: [], /* Build dependencies for this module. */
12-
// packageName: undefined, /* The "name" in package.json. */
3+
author: 'AWS',
4+
authorAddress: '[email protected]',
5+
defaultReleaseBranch: 'main',
6+
name: 'cdklabs-projen-project-types',
7+
repositoryUrl: 'https://github.com/cdklabs/cdklabs-projen-project-types.git',
8+
deps: ['projen'],
9+
bundledDeps: ['yaml'],
10+
peerDeps: ['projen'],
1311
});
1412
project.synth();

API.md

+14,668
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cdk.ts

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import { awscdk, typescript } from 'projen';
2+
import { Stability } from 'projen/lib/cdk';
3+
import { Private } from './private';
4+
5+
export interface CdkConstructLibraryOptions extends awscdk.AwsCdkConstructLibraryOptions {
6+
/**
7+
* Whether or not this package is private. Setting this variable
8+
* to true means that your project is created with sane defaults
9+
* for private repositories.
10+
*
11+
* @default true
12+
*/
13+
readonly private?: boolean;
14+
}
15+
16+
/**
17+
* Create a Cdk Construct Library Project
18+
*
19+
* @pjid cdk-construct-lib
20+
*/
21+
export class CdkConstructLibrary extends awscdk.AwsCdkConstructLibrary {
22+
private static stabilityRequirements(options: CdkConstructLibraryOptions): string[] {
23+
const errors: string[] = [];
24+
if (!options.publishToPypi) {
25+
errors.push('Publishing Error: project not configured to publish to Python');
26+
}
27+
if (!options.publishToMaven) {
28+
errors.push('Publishing Error: project not configured to publish to Maven');
29+
}
30+
if (!options.publishToNuget) {
31+
errors.push('Publishing Error: project not configured to publish to Nuget');
32+
}
33+
if (!options.publishToGo) {
34+
errors.push('Publishing Error: project not configured to publish to Go');
35+
}
36+
return errors;
37+
}
38+
39+
public readonly private: boolean;
40+
41+
constructor(options: CdkConstructLibraryOptions) {
42+
if (options.stability === Stability.STABLE) {
43+
const errors = CdkConstructLibrary.stabilityRequirements(options);
44+
if (errors.length > 0) {
45+
throw new Error(`The project does not pass stability requirements due to the following errors:\n ${errors.join('\n ')}`);
46+
}
47+
}
48+
49+
super({
50+
stability: Stability.EXPERIMENTAL,
51+
...options,
52+
});
53+
54+
this.private = options.private ?? true;
55+
56+
if (this.private) {
57+
new Private(this);
58+
}
59+
}
60+
}
61+
62+
export interface CdkTypeScriptProjectOptions extends typescript.TypeScriptProjectOptions {
63+
/**
64+
* Whether or not this module is private. Setting this variable
65+
* to true means that your project is created with sane defaults
66+
* for private repositories.
67+
*
68+
* @default true
69+
*/
70+
readonly private?: boolean;
71+
}
72+
73+
/**
74+
* Create a Cdk TypeScript Project
75+
*
76+
* @pjid cdk-ts-proj
77+
*/
78+
export class CdkTypeScriptProject extends typescript.TypeScriptProject {
79+
public readonly private: boolean;
80+
81+
constructor(options: CdkTypeScriptProjectOptions) {
82+
super(options);
83+
this.private = options.private ?? true;
84+
if (this.private) {
85+
new Private(this);
86+
}
87+
}
88+
}

src/cdklabs.ts

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { UpdateSnapshot } from 'projen/lib/javascript';
2+
import {
3+
CdkConstructLibrary,
4+
CdkConstructLibraryOptions,
5+
CdkTypeScriptProject,
6+
CdkTypeScriptProjectOptions,
7+
} from './cdk';
8+
9+
// override these properties no matter what values are given client-side
10+
const cdklabsForcedProps = {
11+
author: 'Amazon Web Services',
12+
authorName: 'Amazon Web Services',
13+
authorAddress: '[email protected]',
14+
authorEmail: '[email protected]',
15+
authorOrganization: true,
16+
};
17+
18+
const cdklabsDefaultProps = {
19+
autoApproveUpgrades: true,
20+
autoApproveOptions: {
21+
allowedUsernames: ['cdklabs-automation'],
22+
secret: 'GITHUB_TOKEN',
23+
},
24+
minNodeVersion: '14.17.0',
25+
jestOptions: {
26+
updateSnapshot: UpdateSnapshot.NEVER,
27+
},
28+
defaultReleaseBranch: 'main',
29+
};
30+
31+
export interface CdklabsConstructLibraryOptions extends CdkConstructLibraryOptions {
32+
}
33+
34+
/**
35+
* Create a Cdklabs Construct Library Project
36+
*
37+
* @pjid cdklabs-construct-lib
38+
*/
39+
export class CdklabsConstructLibrary extends CdkConstructLibrary {
40+
constructor(options: CdklabsConstructLibraryOptions) {
41+
super({
42+
...cdklabsDefaultProps,
43+
...options,
44+
...cdklabsForcedProps,
45+
});
46+
}
47+
}
48+
49+
export interface CdklabsTypeScriptProjectOptions extends CdkTypeScriptProjectOptions {
50+
}
51+
52+
/**
53+
* Create a Cdklabs TypeScript Project
54+
*
55+
* @pjid cdklabs-ts-proj
56+
*/
57+
export class CdklabsTypeScriptProject extends CdkTypeScriptProject {
58+
constructor(options: CdklabsTypeScriptProjectOptions) {
59+
super({
60+
...cdklabsDefaultProps,
61+
...options,
62+
...cdklabsForcedProps,
63+
});
64+
}
65+
}

src/index.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
export class Hello {
2-
public sayHello() {
3-
return 'hello, world!';
4-
}
5-
}
1+
export * from './cdk';
2+
export * from './cdklabs';

src/private.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Component } from 'projen';
2+
import { TypeScriptProject } from 'projen/lib/typescript';
3+
4+
/**
5+
* The Private component is a one-stop shop for all things
6+
* related to configuring a private repository. Instead of
7+
* ensuring that the project options are configured in a
8+
* "private" way, this component ensures that the output
9+
* enforces all our rules for private repositories regardless
10+
* of input.
11+
*/
12+
export class Private extends Component {
13+
constructor(project: TypeScriptProject) {
14+
super(project);
15+
16+
// mark private: true in package.json
17+
project.addFields({ private: true });
18+
19+
// private repositories cannot have mergify configured.
20+
project.tryRemoveFile('.mergify.yml');
21+
22+
// no need for npmignore file
23+
project.tryRemoveFile('.npmignore');
24+
}
25+
}

0 commit comments

Comments
 (0)