-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path.projenrc.ts
292 lines (272 loc) · 7.66 KB
/
.projenrc.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { CdklabsConstructLibrary } from 'cdklabs-projen-project-types';
import {
NodePackageManager,
QuoteProps,
TrailingComma,
ArrowParens,
EndOfLine
} from 'projen/lib/javascript';
/**
* Dependencies
*/
const sdkVersion = '3.600.0';
const lambdaHandlerDeps = [
`@aws-sdk/client-iam@${sdkVersion}`,
`@aws-sdk/client-secrets-manager@${sdkVersion}`,
`@aws-sdk/client-ssm@${sdkVersion}`,
`@aws-sdk/client-opensearch@${sdkVersion}`,
`@aws-sdk/client-imagebuilder@${sdkVersion}`,
`@aws-sdk/client-cloudformation@${sdkVersion}`,
`@aws-sdk/client-s3@${sdkVersion}`,
'@types/[email protected]',
];
/**
* Project Definition
*/
const project = new CdklabsConstructLibrary({
author: 'Derrike Nunn && Luciano Taranto',
authorAddress: '[email protected]',
stability: 'experimental',
private: false,
keywords: ['aws', 'awscdk', 'aws-cdk', 'cdk'],
jsiiVersion: '~5.7',
cdkVersion: '2.177.0',
defaultReleaseBranch: 'main',
rosettaOptions: {
strict: false
},
devDeps: [
...lambdaHandlerDeps,
'aws-sdk-client-mock',
'aws-sdk-client-mock-jest',
'cdklabs-projen-project-types',
'cloudform-types',
'esbuild',
'husky',
'lint-staged',
'@aws-sdk/client-wafv2',
'@types/uuid',
],
name: '@cdklabs/cdk-proserve-lib',
packageName: '@cdklabs/cdk-proserve-lib',
description:
'AWS CDK library containing constructs, aspects, and patterns.',
projenrcTs: true,
gitignore: [
'.DS_Store',
'.python-version',
'.nvmrc',
'test.json',
'.vscode/',
'.yarn/'
],
packageManager: NodePackageManager.YARN_CLASSIC,
prettier: true,
prettierOptions: {
settings: {
tabWidth: 4,
useTabs: false,
semi: true,
singleQuote: true,
quoteProps: QuoteProps.ASNEEDED,
trailingComma: TrailingComma.NONE,
bracketSpacing: true,
arrowParens: ArrowParens.ALWAYS,
endOfLine: EndOfLine.LF
},
overrides: [
{
files: ['*.yml', '*.yaml'],
options: {
singleQuote: false,
tabWidth: 2
}
},
{
files: ['*.md'],
options: {
tabWidth: 1
}
}
]
},
versionrcOptions: {
preset: 'conventionalcommits'
}
});
/**
* Package.json Modifications
*/
project.addFields({
exports: {
'.': './index.js',
'./aspects': './aspects/index.js',
'./constructs': './constructs/index.js',
'./patterns': './patterns/index.js',
'./types': './types/index.js'
},
// Represents the structure in the package staging directory
files: [
'API.md',
'lib/index.js',
'lib/index.d.ts',
'lib/aspects/**/*',
'lib/common/**/*',
'lib/constructs/**/*',
'lib/patterns/**/*',
'lib/types/**/*',
'lib/tsconfig.tsbuildinfo',
'.jsii',
'.jsii.gz'
],
'lint-staged': {
'**/*': ['prettier --write --ignore-unknown']
},
// Represents the structure in the package staging directory
main: 'index.js',
packageManager: '[email protected]+sha1.4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447'
});
project.addScripts({
prepare: 'husky'
});
/**
* Tsconfig Modifications
*/
project.tsconfigDev?.addInclude('esbuild.ts');
/**
* Tasks
*/
// Clean Up Task
project.addTask('clean', {
description: 'Removes all ephemeral build and test files.',
steps: [
{
exec: 'rm -rf coverage/',
name: 'Remove coverage information.'
},
{
exec: 'rm -rf dist/',
name: 'Remove built packages.'
},
{
exec: 'rm -rf lib/',
name: 'Remove build files.'
},
{
exec: 'rm -rf test-reports/',
name: 'Remove testing information.'
},
{
exec: 'rm -rf .jsii tsconfig.json',
name: 'Remove intermediate files.'
}
]
});
// Generate Task
project.addTask('generate', {
description: 'Automatically update files with generator scripts.',
steps: [
{
exec: 'yarn ts-node ./utilities/generators'
},
{
spawn: 'eslint'
}
]
});
// Language Packaging Tasks
const packageLanguageTasks = ['js', 'java', 'python', 'dotnet', 'go'];
packageLanguageTasks.forEach((l) => {
const languageTask = project.tasks.tryFind(`package:${l}`);
languageTask?.updateStep(0, {
...languageTask.steps[0],
condition: `node -e "if (!process.env.CI || (process.env.GITHUB_JOB.toLowerCase() !== 'build' && process.env.GITHUB_JOB.toLowerCase() !== 'release')) process.exit(1)"`
});
languageTask?.exec(
`jsii-pacmak -v --target ${l} --pack-command "rm -rf * && name=\\$(npm pack \"$(pwd)\" | tail -1) && mkdir tmp && tar -xzvf \\$name -C tmp && mv tmp/package/lib/* tmp/package && rm -rf tmp/package/lib && cd tmp && tar -czvf ../\\$name package && cd .. && rm -rf tmp && echo \\$name"`,
{
condition: `node -e "if (process.env.CI && (process.env.GITHUB_JOB.toLowerCase() === 'build' || process.env.GITHUB_JOB.toLowerCase() === 'release')) process.exit(1)"`
}
);
});
// Lambda Build Task
const compileLambdas = project.addTask('compile:lambda', {
description: 'Builds the Lambda function code and bundles dependencies',
steps: [
{
exec: 'yarn ts-node esbuild.ts',
name: 'Run esbuild.'
}
]
});
/**
* Asset Bundling
*/
const srcDir = 'src';
const outputDir = 'lib';
const bundleExtensions = ['yml', 'yaml'];
const bundleTask = project.addTask('bundle', {
description: 'Distributes assets to the build directory.'
});
bundleExtensions.forEach((e) =>
bundleTask.exec(
`find ${srcDir} -name "*.${e}" -exec sh -c 'mkdir -p "${outputDir}/$(dirname \${1#${srcDir}/})" && cp "$1" "${outputDir}/\${1#${srcDir}/}"' _ {} \\;`,
{
name: `Distribute asset files (.${e}) to the build directory.`
}
)
);
project.postCompileTask.spawn(bundleTask);
project.postCompileTask.spawn(compileLambdas);
/**
* README
*/
const readmeTask = project.addTask('update:readme', {
description: 'Updates the README with library package information.',
steps: [
{
exec: 'yarn ts-node utilities/generators/lib/update-readme-library.ts',
name: 'Runs script to automatically update the README.'
}
]
});
project.postCompileTask.spawn(readmeTask);
/**
* Ignore Patterns
*/
// Linting
project.eslint?.allowDevDeps('**/handler/**/*.ts');
const autoGeneratedFiles = [
'.projen/*.json',
'.eslintrc.json',
'.prettierrc.json',
'API.md',
'package.json',
'tsconfig.dev.json',
'yarn.lock'
];
autoGeneratedFiles.forEach((f) => {
project.eslint?.addIgnorePattern(f);
project.prettier?.addIgnorePattern(f);
});
// Testing
project.jest?.addIgnorePattern('utilities');
project.jest?.addIgnorePattern('<rootDir>/test/(.+/)?fixtures/');
/**
* Projen Fixes
*/
project.tasks.tryFind('rosetta:extract')?.updateStep(0, {
exec: 'yarn jsii-rosetta extract 2> /dev/null 1>&2'
});
/**
* Set minimum package versions across dependency chain
*/
project.package.addPackageResolutions(
'cross-spawn@^7.0.5' // grype finding nov24
);
project.synth();