Skip to content

Commit

Permalink
Share Angular resources in the build tools
Browse files Browse the repository at this point in the history
  • Loading branch information
jonafanho committed Oct 29, 2024
1 parent ca60f04 commit d274fbf
Show file tree
Hide file tree
Showing 9 changed files with 737 additions and 1,150 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ bin/
*.DS_Store

generated/
**/website/.gitignore
**/website/src/assets/
log4j2.properties
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ tasks.register("generateSchemaClasses") {
Generator.generate(project, "schema/map", "core/generated/map", false, "core.map")
Generator.generate(project, "schema/oba", "core/generated/oba", false, "core.oba")
Generator.generate(project, "schema/operation", "core/generated/operation", false, "core.data", "core.operation")
WebserverSetup.setup(project.rootDir)
WebserverSetup.setup(project.rootDir, "", "core")
}

tasks.withType(AbstractArchiveTask).configureEach {
Expand Down
10 changes: 9 additions & 1 deletion buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,13 @@ jar {
tasks.withType(AbstractArchiveTask).configureEach {
preserveFileTimestamps = false
reproducibleFileOrder = true
excludes = ["website"]
excludes = [
"website/.*",
"website/dist",
"website/node_modules",
"website/src/app",
"website/src/assets",
"website/src/index.html",
"website/src/main.ts",
]
}
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/org/mtr/core/Generator.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.stream.Stream;

@ParametersAreNonnullByDefault
public class Generator {
public final class Generator {

private static final Logger LOGGER = LogManager.getLogger("Generator");

Expand Down
11 changes: 7 additions & 4 deletions buildSrc/src/main/java/org/mtr/core/WebserverSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
import java.util.List;
import java.util.stream.Stream;

public class WebserverSetup {
public final class WebserverSetup {

private static final Logger LOGGER = LogManager.getLogger("WebserverSetup");

public static void setup(File projectPath) {
public static void setup(File projectPath, String module, String namespace) {
final Path websitePath = projectPath.toPath().resolve("buildSrc/src/main/resources/website/dist/website/browser");
final StringBuilder stringBuilder = new StringBuilder("package org.mtr.core.generated;@javax.annotation.Nullable public final class WebserverResources{public static String get(String resource){switch(resource.startsWith(\"/\")?resource.substring(1):resource){");
final StringBuilder stringBuilder = new StringBuilder(String.format("package org.mtr.%s.generated;", namespace));
stringBuilder.append("@javax.annotation.Nullable public final class WebserverResources{public static String get(String resource){switch(resource.startsWith(\"/\")?resource.substring(1):resource){");
try (final Stream<Path> stream = Files.list(websitePath)) {
stream.forEach(websiteFilePath -> {
try {
Expand All @@ -39,7 +40,9 @@ public static void setup(File projectPath) {
LOGGER.error("", e);
}
stringBuilder.append("default:return null;}}}");
write(projectPath.toPath().resolve("src/main/java/org/mtr/core/generated/WebserverResources.java"), stringBuilder.toString());
write(projectPath.toPath().resolve(String.format("%ssrc/main/java/org/mtr/%s/generated/WebserverResources.java", module, namespace)), stringBuilder.toString());

write(projectPath.toPath().resolve("buildSrc/src/main/resources/website/.gitignore"), download("https://raw.githubusercontent.com/angular/angular/refs/heads/main/.gitignore"));
}

private static String download(String url) {
Expand Down
42 changes: 0 additions & 42 deletions buildSrc/src/main/resources/website/.gitignore

This file was deleted.

Loading

0 comments on commit d274fbf

Please sign in to comment.