Skip to content

Commit 26508b8

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

File tree

3 files changed

+454
-11
lines changed

3 files changed

+454
-11
lines changed

API.md

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

src/cdklabs.ts

+80-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { UpdateSnapshot } from 'projen/lib/javascript';
2+
import { deepMerge } from 'projen/lib/util';
3+
24
import {
35
CdkConstructLibrary,
46
CdkConstructLibraryOptions,
@@ -28,7 +30,51 @@ const cdklabsDefaultProps = {
2830
defaultReleaseBranch: 'main',
2931
};
3032

33+
function createCdklabsPublishingDefaults(npmPackageName: string) {
34+
return {
35+
publishToPypi: {
36+
distName: npmPackageName,
37+
module: changeDelimiter(npmPackageName, '_'),
38+
},
39+
publishToMaven: {
40+
javaPackage: `io.github.cdklabs.${changeDelimiter(npmPackageName, '.')}`,
41+
mavenGroupId: 'io.github.cdklabs',
42+
mavenArtifactId: npmPackageName,
43+
mavenEndpoint: 'https://s01.oss.sonatype.org',
44+
},
45+
publishToNuget: {
46+
dotNetNamespace: `Cdklabs${upperCaseName(npmPackageName)}`,
47+
packageId: `Cdklabs${upperCaseName(npmPackageName)}`,
48+
},
49+
publishToGo: {
50+
moduleName: `${npmPackageName}-go`,
51+
},
52+
};
53+
54+
function upperCaseName(str: string) {
55+
let words = str.split('-');
56+
words = words.map((w) => w[0].toUpperCase() + w.substring(1));
57+
return words.join('');
58+
}
59+
60+
function changeDelimiter(str: string, delim: string) {
61+
return str.split('-').join(delim);
62+
}
63+
};
64+
3165
export interface CdklabsConstructLibraryOptions extends CdkConstructLibraryOptions {
66+
/**
67+
* Set default publishing properties. Setting this property guarantees
68+
* that your project will have reasonable publishing names. You can choose
69+
* to modify them however you wish with the traditional `publishToPypi`,
70+
* `publishToMaven`, `publishToNuget`, and `publishToGo` properties, and
71+
* your configuration will be respected.
72+
*
73+
* This should be set to false only if you do not plan on releasing the package.
74+
*
75+
* @default true
76+
*/
77+
readonly cdklabsPublishingDefaults?: boolean;
3278
}
3379

3480
/**
@@ -38,15 +84,33 @@ export interface CdklabsConstructLibraryOptions extends CdkConstructLibraryOptio
3884
*/
3985
export class CdklabsConstructLibrary extends CdkConstructLibrary {
4086
constructor(options: CdklabsConstructLibraryOptions) {
41-
super({
42-
...cdklabsDefaultProps,
43-
...options,
44-
...cdklabsForcedProps,
45-
});
87+
const cdklabsPublishingDefaultProps = (options.cdklabsPublishingDefaults ?? true) ?
88+
createCdklabsPublishingDefaults(options.name) : {};
89+
90+
const mergedOptions = deepMerge([
91+
cdklabsDefaultProps,
92+
cdklabsPublishingDefaultProps,
93+
options,
94+
cdklabsForcedProps,
95+
]) as CdkConstructLibraryOptions;
96+
97+
super(mergedOptions);
4698
}
4799
}
48100

49101
export interface CdklabsTypeScriptProjectOptions extends CdkTypeScriptProjectOptions {
102+
/**
103+
* Set default publishing properties. Setting this property guarantees
104+
* that your project will have reasonable publishing names. You can choose
105+
* to modify them however you wish with the traditional `publishToPypi`,
106+
* `publishToMaven`, `publishToNuget`, and `publishToGo` properties, and
107+
* your configuration will be respected.
108+
*
109+
* This should be set to false only if you do not plan on releasing the package.
110+
*
111+
* @default true
112+
*/
113+
readonly cdklabsPublishingDefaults?: boolean;
50114
}
51115

52116
/**
@@ -56,10 +120,16 @@ export interface CdklabsTypeScriptProjectOptions extends CdkTypeScriptProjectOpt
56120
*/
57121
export class CdklabsTypeScriptProject extends CdkTypeScriptProject {
58122
constructor(options: CdklabsTypeScriptProjectOptions) {
59-
super({
60-
...cdklabsDefaultProps,
61-
...options,
62-
...cdklabsForcedProps,
63-
});
123+
const cdklabsPublishingDefaultProps = (options.cdklabsPublishingDefaults ?? true) ?
124+
createCdklabsPublishingDefaults(options.name) : {};
125+
126+
const mergedOptions = deepMerge([
127+
cdklabsDefaultProps,
128+
cdklabsPublishingDefaultProps,
129+
options,
130+
cdklabsForcedProps,
131+
]) as CdkConstructLibraryOptions;
132+
133+
super(mergedOptions);
64134
}
65135
}

0 commit comments

Comments
 (0)