Skip to content

Commit

Permalink
Various improvements in user xp
Browse files Browse the repository at this point in the history
  • Loading branch information
ia3andy committed Dec 7, 2023
1 parent 878dcff commit 3698ecf
Show file tree
Hide file tree
Showing 35 changed files with 521 additions and 155 deletions.
42 changes: 42 additions & 0 deletions common-deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkiverse.web-bundler</groupId>
<artifactId>quarkus-web-bundler-parent</artifactId>
<version>999-SNAPSHOT</version>
</parent>
<artifactId>quarkus-web-bundler-common-deployment</artifactId>
<name>Quarkus Web Bundler - Common - Deployment</name>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-http-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${quarkus.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.quarkiverse.web.bundler.deployment.items.BundleWebAsset;
import io.quarkiverse.web.bundler.deployment.items.BundleWebAsset.BundleType;
import io.quarkiverse.web.bundler.deployment.items.EntryPointBuildItem;
import io.quarkiverse.web.bundler.deployment.items.HtmlTemplatesBuildItem;
import io.quarkiverse.web.bundler.deployment.items.QuteTagsBuildItem;
import io.quarkiverse.web.bundler.deployment.items.StaticAssetsBuildItem;
import io.quarkiverse.web.bundler.deployment.items.WebAsset;
Expand Down Expand Up @@ -53,6 +54,7 @@ void collect(ApplicationArchivesBuildItem applicationArchives,
BuildProducer<StaticAssetsBuildItem> staticAssets,
BuildProducer<QuteTagsBuildItem> quteTagsAssets,
BuildProducer<BundleConfigAssetsBuildItem> bundleConfigAssets,
BuildProducer<HtmlTemplatesBuildItem> htmlTemplatesAssets,
BuildProducer<HotDeploymentWatchedFileBuildItem> watchedFiles,
WebBundlerConfig config,
LiveReloadBuildItem liveReload)
Expand All @@ -67,7 +69,7 @@ void collect(ApplicationArchivesBuildItem applicationArchives,
// Project WebAssets shouldn't be changed even if the file is changed as content is not stored
// WebAsset from dependencies means we should do a new scan
LOGGER.debug("Web bundler scan not needed for live reload");
produceWebAssets(bundles, staticAssets, quteTagsAssets, bundleConfigAssets, devContext, true);
produceWebAssets(bundles, staticAssets, quteTagsAssets, bundleConfigAssets, htmlTemplatesAssets, devContext, true);
return;
}
LOGGER.debug("Web bundler scan started");
Expand All @@ -76,6 +78,7 @@ void collect(ApplicationArchivesBuildItem applicationArchives,
.filter(Dependency::isRuntimeExtensionArtifact).collect(Collectors.toList());
Map<String, EntryPointConfig> entryPointsConfig = new HashMap<>(config.bundle());
final List<Scanner> staticAssetsScanners = new ArrayList<>();
final List<Scanner> htmlTemplateAssetsScanner = new ArrayList<>();
final List<Scanner> quteTagsAssetsScanners = new ArrayList<>();
final List<Scanner> bundleConfigAssetsScanners = new ArrayList<>();

Expand All @@ -94,6 +97,9 @@ void collect(ApplicationArchivesBuildItem applicationArchives,
config.presets().app().entryPointKey().orElse(MAIN_ENTRYPOINT_KEY)));
}

htmlTemplateAssetsScanner.add(new Scanner(config.webRoot(),
"glob:*.html", config.charset()));

staticAssetsScanners.add(new Scanner(config.fromWebRoot(config.staticDir()),
"glob:**", config.charset()));

Expand Down Expand Up @@ -122,9 +128,11 @@ void collect(ApplicationArchivesBuildItem applicationArchives,

final WebAssetsLookupDevContext context = new WebAssetsLookupDevContext(
bundleAssets,
resourcesScanner.scan(staticAssetsScanners), resourcesScanner.scan(quteTagsAssetsScanners),
resourcesScanner.scan(bundleConfigAssetsScanners));
produceWebAssets(bundles, staticAssets, quteTagsAssets, bundleConfigAssets, context, false);
resourcesScanner.scan(staticAssetsScanners),
resourcesScanner.scan(quteTagsAssetsScanners),
resourcesScanner.scan(bundleConfigAssetsScanners),
resourcesScanner.scan(htmlTemplateAssetsScanner));
produceWebAssets(bundles, staticAssets, quteTagsAssets, bundleConfigAssets, htmlTemplatesAssets, context, false);
liveReload.setContextObject(WebAssetsLookupDevContext.class, context);
}

Expand All @@ -139,9 +147,13 @@ private static boolean hasNewWebResources(WebBundlerConfig config, LiveReloadBui
.allMatch(webAssets::contains);
}

void produceWebAssets(BuildProducer<EntryPointBuildItem> bundles, BuildProducer<StaticAssetsBuildItem> staticAssets,
BuildProducer<QuteTagsBuildItem> quteTagsAssets, BuildProducer<BundleConfigAssetsBuildItem> bundleConfigAssets,
WebAssetsLookupDevContext context, boolean checkIfExists) {
void produceWebAssets(BuildProducer<EntryPointBuildItem> bundles,
BuildProducer<StaticAssetsBuildItem> staticAssets,
BuildProducer<QuteTagsBuildItem> quteTagsAssets,
BuildProducer<BundleConfigAssetsBuildItem> bundleConfigAssets,
BuildProducer<HtmlTemplatesBuildItem> htmlTemplatesAssets,
WebAssetsLookupDevContext context,
boolean checkIfExists) {
for (Map.Entry<String, List<BundleWebAsset>> e : context.bundleAssets().entrySet()) {
bundles.produce(new EntryPointBuildItem(e.getKey(), checkIfExists ? checkWebAssets(e.getValue()) : e.getValue()));
}
Expand All @@ -154,6 +166,9 @@ void produceWebAssets(BuildProducer<EntryPointBuildItem> bundles, BuildProducer<
quteTagsAssets.produce(new QuteTagsBuildItem(
checkIfExists ? checkWebAssets(context.quteWebAssets()) : context.quteWebAssets()));

htmlTemplatesAssets.produce(new HtmlTemplatesBuildItem(
checkIfExists ? checkWebAssets(context.htmlTemplateWebAssets()) : context.htmlTemplateWebAssets()));

}

private static <T extends WebAsset> List<T> checkWebAssets(List<T> webAssets) {
Expand All @@ -163,13 +178,14 @@ private static <T extends WebAsset> List<T> checkWebAssets(List<T> webAssets) {
}

record WebAssetsLookupDevContext(Map<String, List<BundleWebAsset>> bundleAssets, List<WebAsset> staticWebAssets,
List<WebAsset> quteWebAssets, List<WebAsset> bundleConfigWebAssets) {
List<WebAsset> quteWebAssets, List<WebAsset> bundleConfigWebAssets, List<WebAsset> htmlTemplateWebAssets) {

public List<WebAsset> allWebAssets() {
final ArrayList<WebAsset> all = new ArrayList<>();
all.addAll(staticWebAssets);
all.addAll(quteWebAssets);
all.addAll(bundleConfigWebAssets);
all.addAll(htmlTemplateWebAssets);
bundleAssets.values().forEach(all::addAll);
return all;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
package io.quarkiverse.web.bundler.deployment;

import static io.quarkiverse.web.bundler.deployment.util.PathUtils.addTrailingSlash;
import static io.quarkiverse.web.bundler.deployment.util.PathUtils.join;
import static io.quarkiverse.web.bundler.deployment.util.PathUtils.prefixWithSlash;
import static io.quarkiverse.web.bundler.deployment.util.PathUtils.removeLeadingSlash;
import static java.util.function.Predicate.not;

import java.nio.charset.Charset;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;

import io.quarkus.maven.dependency.Dependency;
import io.quarkus.runtime.annotations.ConfigDocDefault;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
Expand All @@ -36,11 +29,10 @@ public interface WebBundlerConfig {
* The directory in the resources which serves as root for the web assets
*/
@WithDefault("web")
@NotBlank
String webRoot();

default String fromWebRoot(String dir) {
return addTrailingSlash(webRoot()) + removeLeadingSlash(dir);
return join(webRoot(), dir);
}

/**
Expand All @@ -55,7 +47,6 @@ default String fromWebRoot(String dir) {
*/
@WithName("static")
@WithDefault("static")
@Pattern(regexp = "")
String staticDir();

/**
Expand Down Expand Up @@ -168,11 +159,10 @@ interface PresetConfig {
interface WebDependenciesConfig {

/**
* The type used to collect web dependencies:
* web-jar or mvnpm
* Path to the node_modules directory (relative to the project root).
*/
@WithDefault("mvnpm")
WebDependencyType type();
@ConfigDocDefault("node_modules will be in the build/target directory")
Optional<String> nodeModules();

/**
* If enabled web dependencies will also be served, this is usually not needed as they are already bundled.
Expand Down Expand Up @@ -303,19 +293,4 @@ default String effectiveKey(String mapKey) {

}

enum WebDependencyType {
WEBJARS("org.webjars.npm"::equals),
MVNPM(s -> s.startsWith("org.mvnpm"));

private final Predicate<String> groupMatcher;

WebDependencyType(Predicate<String> groupMatcher) {
this.groupMatcher = groupMatcher;
}

public boolean matches(Dependency dep) {
return this.groupMatcher.test(dep.getGroupId());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.quarkiverse.web.bundler.deployment.items;

import java.util.List;

public final class HtmlTemplatesBuildItem extends WebAssetsBuildItem {

public HtmlTemplatesBuildItem(List<WebAsset> webAssets) {
super(webAssets);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ default byte[] readContentFromFile() {
return readTemplateContent(filePath().orElseThrow());
}

default byte[] contentOrReadFromFile() {
return hasContent() ? content() : readContentFromFile();
}

default boolean hasContent() {
return this.content() != null;
}
Expand Down
18 changes: 10 additions & 8 deletions deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@
<artifactId>quarkus-web-bundler</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-http-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-qute-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.web-bundler</groupId>
<artifactId>quarkus-web-bundler-sass-compiler</artifactId>
Expand All @@ -36,16 +28,26 @@
<artifactId>yuicompressor</artifactId>
<version>${yuicompressor.version}</version>
</dependency>
<!--
<dependency>
<groupId>com.sksamuel.scrimage</groupId>
<artifactId>scrimage-core</artifactId>
<version>${scrimage-core.version}</version>
</dependency>-->
<dependency>
<groupId>io.quarkus.qute</groupId>
<artifactId>qute-core</artifactId>
</dependency>
<dependency>
<groupId>io.mvnpm</groupId>
<artifactId>esbuild-java</artifactId>
<version>${esbuild-java.version}</version>
</dependency>
<dependency>
<groupId>io.quarkiverse.web-bundler</groupId>
<artifactId>quarkus-web-bundler-common-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
Expand Down

This file was deleted.

Loading

0 comments on commit 3698ecf

Please sign in to comment.