-
Notifications
You must be signed in to change notification settings - Fork 2
/
.projenrc.ts
221 lines (199 loc) · 7.31 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
import { MonorepoTsProject } from "@aws/pdk/monorepo";
import { DocumentationFormat, Language, Library, ModelLanguage, TypeSafeApiProject } from "@aws/pdk/type-safe-api";
import { CloudscapeReactTsWebsiteProject } from "@aws/pdk/cloudscape-react-ts-website";
import { InfrastructureTsProject } from "@aws/pdk/infrastructure";
import { NodePackageManager } from "projen/lib/javascript";
import { PythonProject } from "projen/lib/python";
import * as path from "path";
import { DependencyType } from "projen";
import { configureTsProject } from "./projenrc/utils/typescript";
import { configureProject } from "./projenrc/utils/common";
import { configurePyProject } from "./projenrc/utils/python";
const monorepo = new MonorepoTsProject({
devDeps: ["@aws/pdk"],
name: "@aws/document-extraction-platform",
packageManager: NodePackageManager.PNPM,
projenrcTs: true,
});
configureTsProject(monorepo);
monorepo.package.addPackageResolutions(
"fast-xml-parser@^4.4.1",
"nth-check@^2.0.1",
"semver@^7.5.2",
"axios@^1.7.4",
"postcss@^8.4.31",
"braces@^3.0.3",
"ws@^8.17.1",
"webpack-dev-middleware@^5.3.4",
"body-parser@^1.20.3",
"dompurify@^3.1.3",
"express@^4.19.2",
"follow-redirects@^1.15.6",
"ejs@^3.1.10",
"webpack@^5.94.0",
"send@^0.19.0",
"serve-static@^1.16.0",
"micromatch@^4.0.8",
);
monorepo.package.file.addOverride("pnpm.overrides.path-to-regexp@^1", "^1.9.0");
const api = new TypeSafeApiProject({
parent: monorepo,
outdir: "packages/api",
name: "@aws/document-extraction-platform-api",
infrastructure: {
language: Language.TYPESCRIPT,
},
model: {
language: ModelLanguage.OPENAPI,
options: {
openapi: {
title: "AWSDocsAPI",
},
},
},
documentation: {
formats: [DocumentationFormat.HTML_REDOC],
},
handlers: {
languages: [Language.PYTHON],
},
library: {
libraries: [Library.TYPESCRIPT_REACT_QUERY_HOOKS],
},
});
api.handlers.python!.addDependency("boto3@^1");
api.handlers.python!.addDependency("botocore@^1");
configurePyProject(api.handlers.python!);
const pythonLibrary = new PythonProject({
parent: monorepo,
poetry: true,
sample: false,
outdir: "packages/lib",
name: "aws-document-extraction-platform-lib",
moduleName: "aws_document_extraction_platform_lib",
authorEmail: "[email protected]",
authorName: "aws",
version: "0.0.0",
deps: [
"python@^3.11",
"boto3@^1",
"botocore@^1",
"amazon-textract-response-parser@^1",
"pypdf2@^1",
"thefuzz@^0.19",
],
devDeps: [
"moto@^4",
`boto3-stubs@{version="^1", extras=["s3"]}`,
"types-python-dateutil@^2",
],
});
configurePyProject(pythonLibrary);
monorepo.addPythonPoetryDependency(pythonLibrary, api.runtime.python!);
monorepo.addPythonPoetryDependency(api.handlers.python!, pythonLibrary);
// Create a lambda distributable for the state machine handlers included in the python library
pythonLibrary.packageTask.exec("mkdir -p dist/lambda && rm -rf dist/lambda/*");
pythonLibrary.packageTask.exec(
`cp -r ${pythonLibrary.moduleName} dist/lambda/${pythonLibrary.moduleName}`
);
pythonLibrary.packageTask.exec(
"poetry export --without-hashes --format=requirements.txt > dist/lambda/requirements.txt"
);
pythonLibrary.packageTask.exec(
`pip install -r dist/lambda/requirements.txt --target dist/lambda --upgrade --platform manylinux2014_x86_64 --only-binary :all:`
);
const webapp = new CloudscapeReactTsWebsiteProject({
parent: monorepo,
outdir: "packages/webapp",
name: "@aws/document-extraction-platform-webapp",
typeSafeApi: api,
deps: [
"@aws-amplify/[email protected]",
"aws-northstar",
"aws4fetch",
"react-pdf@^9",
"react-ace@^10",
"ace-builds@^1",
"@material-ui/icons@^4",
"lodash",
"humanize-duration",
"react-zoom-pan-pinch@^2",
"react-router-dom@^5",
],
devDeps: [
"@types/lodash",
"@types/humanize-duration",
"react-app-rewired@^2",
"@types/react-router-dom",
"@types/react-pdf@^7",
],
});
configureTsProject(webapp);
// TODO: Consider upgrading to northstar v2 / cloudscape
webapp.deps.removeDependency("@aws-northstar/ui");
webapp.deps.removeDependency("@cloudscape-design/components");
webapp.deps.removeDependency("@cloudscape-design/board-components");
monorepo.package.addPackageResolutions("react-router-dom@^5");
// TODO: Consider upgrade to react 18
[webapp, api.library.typescriptReactQueryHooks!].forEach(project => {
project.deps.removeDependency("react", DependencyType.BUILD);
project.deps.removeDependency("react", DependencyType.PEER);
project.deps.removeDependency("@types/react");
project.deps.removeDependency("react-dom");
project.deps.removeDependency("@types/react-dom");
project.addDeps("react@^17");
project.addDeps("react-dom@^17");
project.addDevDeps("@types/react@^17");
project.addDevDeps("@types/react-dom@^17");
});
// Use react-app-rewired tasks instead of default create react app tasks.
// Note that we disable the inbuilt create react app eslint plugin in favour of running our own eslint after the tests
webapp.tasks.tryFind("dev")?.reset();
webapp.tasks
.tryFind("dev")
?.exec("DISABLE_ESLINT_PLUGIN=true react-app-rewired start");
webapp.tasks.tryFind("compile")?.reset();
webapp.tasks
.tryFind("compile")
?.exec("DISABLE_ESLINT_PLUGIN=true react-app-rewired build --verbose");
webapp.tasks.tryFind("test")?.reset();
webapp.tasks
.tryFind("test")
?.exec(
"DISABLE_ESLINT_PLUGIN=true react-app-rewired test --watchAll=false"
);
webapp.tasks.tryFind("test")?.spawn(webapp.tasks.tryFind("eslint")!);
webapp.tasks.tryFind("test:watch")?.reset();
webapp.tasks
.tryFind("test:watch")
?.exec("DISABLE_ESLINT_PLUGIN=true react-app-rewired test");
const copyApiDocs = webapp.addTask("copy:api-docs");
copyApiDocs.exec("rm -rf public/api-docs");
copyApiDocs.exec("mkdir -p public/api-docs");
copyApiDocs.exec(`cp -r ${path.relative(webapp.outdir, api.documentation.htmlRedoc!.outdir)}/index.html public/api-docs/index.html`);
monorepo.addImplicitDependency(webapp, api.documentation.htmlRedoc!);
webapp.preCompileTask.reset();
webapp.preCompileTask.spawn(copyApiDocs);
webapp.preCompileTask.exec(`cp ${path.relative(webapp.outdir, path.join(require.resolve('pdfjs-dist'), "..", "pdf.worker.min.mjs"))} public/pdf.worker.min.mjs`);
webapp.gitignore.addPatterns("public/pdf.worker.min.mjs");
const infra = new InfrastructureTsProject({
parent: monorepo,
outdir: "packages/infra",
name: "@aws/document-extraction-platform-infra",
deps: [
api.infrastructure.typescript!.package.packageName,
api.runtime.typescript!.package.packageName,
"cdk-nag",
],
});
configureTsProject(infra);
monorepo.addImplicitDependency(infra, api.handlers.python!);
monorepo.addImplicitDependency(infra, webapp);
monorepo.addTask("bootstrap", { receiveArgs: true }).exec(`nx run ${infra.name}:bootstrap`, { receiveArgs: true });
monorepo.addTask("deploy", { receiveArgs: true }).exec(`nx run ${infra.name}:deploy --require-approval never --all`, { receiveArgs: true });
monorepo.addTask("destroy", { receiveArgs: true }).exec(`nx run ${infra.name}:destroy --require-approval never --all`, { receiveArgs: true });
monorepo.addTask("dev", { receiveArgs: true }).exec(`nx run ${webapp.name}:dev`, { receiveArgs: true });
monorepo.subprojects.forEach(p => configureProject(p));
configureProject(monorepo);
monorepo.synth();