1
1
import { UpdateSnapshot } from 'projen/lib/javascript' ;
2
+ import { deepMerge } from 'projen/lib/util' ;
3
+
2
4
import {
3
5
CdkConstructLibrary ,
4
6
CdkConstructLibraryOptions ,
@@ -28,7 +30,51 @@ const cdklabsDefaultProps = {
28
30
defaultReleaseBranch : 'main' ,
29
31
} ;
30
32
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
+
31
65
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 ;
32
78
}
33
79
34
80
/**
@@ -38,15 +84,33 @@ export interface CdklabsConstructLibraryOptions extends CdkConstructLibraryOptio
38
84
*/
39
85
export class CdklabsConstructLibrary extends CdkConstructLibrary {
40
86
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 ) ;
46
98
}
47
99
}
48
100
49
101
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 ;
50
114
}
51
115
52
116
/**
@@ -56,10 +120,16 @@ export interface CdklabsTypeScriptProjectOptions extends CdkTypeScriptProjectOpt
56
120
*/
57
121
export class CdklabsTypeScriptProject extends CdkTypeScriptProject {
58
122
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 ) ;
64
134
}
65
135
}
0 commit comments