Skip to content

Commit

Permalink
fix(infrastructure): fix java compilation issue without api, and skip…
Browse files Browse the repository at this point in the history
… unused constructs in java/py (#629)

The Java website construct didn't compile when an api wasn't present due to some extra brackets
being commented out. Additionally the website construct would always be rendered for typescript even
if no website was configured. Likewise for Java and Python, the api and website constructs were
always rendered. This PR also adds tests for the infrastructure projects.
  • Loading branch information
cogwirrel authored Nov 1, 2023
1 parent 586aa0b commit cc1ddca
Show file tree
Hide file tree
Showing 12 changed files with 10,587 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ import software.constructs.Construct;
* Construct to deploy a Static Website
*/
public class WebsiteConstruct extends Construct {
public WebsiteConstruct(Construct scope, String id, UserIdentity userIdentity) {
this(scope, id, userIdentity{{^hasApi}}/* {{/hasApi}}, null{{^hasApi}} */{{/hasApi}});
}
public WebsiteConstruct(Construct scope, String id, UserIdentity userIdentity{{^hasApi}}/* {{/hasApi}}, ApiConstruct apiConstruct{{^hasApi}} */{{/hasApi}}) {
super(scope, id);
Expand All @@ -31,7 +28,8 @@ public class WebsiteConstruct extends Construct {
"identityPoolId", userIdentity.getIdentityPool().getIdentityPoolId(),
"userPoolId", userIdentity.getUserPool().getUserPoolId(),
"userPoolWebClientId", userIdentity.getUserPoolClient().getUserPoolClientId(){{#hasApi}},{{/hasApi}}
{{^hasApi}}// {{/hasApi}}"apiUrl", apiConstruct.api.getApi().urlForPath())))
{{^hasApi}}// {{/hasApi}}"apiUrl", apiConstruct.api.getApi().urlForPath()
)))
.build())
.distributionProps(DistributionProps.builder()
.geoRestriction(GeoRestriction.allowlist(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,16 @@ export class InfrastructureJavaProject extends AwsCdkJavaApp {
) {
fs.readdirSync(dir, { withFileTypes: true })
.filter((f) => {
let shouldIncludeFile = true;
if (!mustacheConfig.hasApi) {
return !f.name.endsWith("api.ts.mustache");
} else if (!mustacheConfig.hasWebsite) {
return !f.name.endsWith("website.ts.mustache");
} else {
return true;
shouldIncludeFile &&= !f.name.endsWith("ApiConstruct.java.mustache");
}
if (!mustacheConfig.hasWebsite) {
shouldIncludeFile &&= !f.name.endsWith(
"WebsiteConstruct.java.mustache"
);
}
return shouldIncludeFile;
})
.forEach((f) => {
if (f.isDirectory()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,14 @@ export class InfrastructurePyProject extends AwsCdkPythonApp {
) {
fs.readdirSync(dir, { withFileTypes: true })
.filter((f) => {
let shouldIncludeFile = true;
if (!mustacheConfig.hasApi) {
return !f.name.endsWith("api.ts.mustache");
} else if (!mustacheConfig.hasWebsite) {
return !f.name.endsWith("website.ts.mustache");
} else {
return true;
shouldIncludeFile &&= !f.name.endsWith("api.py.mustache");
}
if (!mustacheConfig.hasWebsite) {
shouldIncludeFile &&= !f.name.endsWith("website.py.mustache");
}
return shouldIncludeFile;
})
.forEach((f) => {
if (f.isDirectory()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,14 @@ export class InfrastructureTsProject extends AwsCdkTypeScriptApp {
) {
fs.readdirSync(dir, { withFileTypes: true })
.filter((f) => {
let shouldIncludeFile = true;
if (!mustacheConfig.hasApi) {
return !f.name.endsWith("api.ts.mustache");
} else if (!mustacheConfig.hasWebsite) {
return !f.name.endsWith("website.ts.mustache");
} else {
return true;
shouldIncludeFile &&= !f.name.endsWith("api.ts.mustache");
}
if (!mustacheConfig.hasWebsite) {
shouldIncludeFile &&= !f.name.endsWith("website.ts.mustache");
}
return shouldIncludeFile;
})
.forEach((f) =>
f.isDirectory()
Expand Down
1 change: 0 additions & 1 deletion packages/infrastructure/test/.gitkeep

This file was deleted.

Loading

0 comments on commit cc1ddca

Please sign in to comment.