Skip to content

Commit

Permalink
Fix path resolution for angular.json (#813)
Browse files Browse the repository at this point in the history
  • Loading branch information
xjarvik authored Dec 10, 2024
1 parent 9adf5fa commit 306c39e
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public ConfiguredQuinoaBuildItem prepareQuinoaDirectory(

initializeTargetDirectory(outputTarget);

final QuinoaConfig resolvedConfig = overrideConfig(launchMode, userConfig, packageJson);
final QuinoaConfig resolvedConfig = overrideConfig(launchMode, userConfig, packageJson, projectDirs.uiDir);

return new ConfiguredQuinoaBuildItem(projectDirs.projectRootDir, projectDirs.uiDir, packageJson, resolvedConfig);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkiverse.quinoa.deployment.framework;

import java.nio.file.Path;
import java.util.Optional;

import jakarta.json.JsonObject;
Expand All @@ -13,5 +14,5 @@ public interface FrameworkConfigOverrideFactory {
String getDefaultDevScriptName();

QuinoaConfig override(QuinoaConfig delegate, Optional<JsonObject> packageJson, Optional<String> detectedDevScript,
boolean isCustomized);
}
boolean isCustomized, Path uiDir);
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,25 @@ public FrameworkConfigOverrideFactory factory() {
return factory;
}

public static QuinoaConfig overrideConfig(LaunchModeBuildItem launchMode, QuinoaConfig config, Path packageJsonFile) {
public static QuinoaConfig overrideConfig(LaunchModeBuildItem launchMode, QuinoaConfig config, Path packageJsonFile,
Path uiDir) {
if (!config.framework().detection()) {
return UNKNOWN_FRAMEWORK.override(config, Optional.empty(), Optional.empty(), true);
return UNKNOWN_FRAMEWORK.override(config, Optional.empty(), Optional.empty(), true, uiDir);
}

final JsonObject packageJson = readPackageJson(packageJsonFile);
final Optional<DetectedFramework> detectedFramework = detectFramework(packageJson);

if (detectedFramework.isEmpty()) {
LOG.trace("Quinoa could not auto-detect the frameworkType from package.json file.");
return UNKNOWN_FRAMEWORK.override(config, Optional.of(packageJson), Optional.empty(), true);
return UNKNOWN_FRAMEWORK.override(config, Optional.of(packageJson), Optional.empty(), true, uiDir);
}

final FrameworkType frameworkType = detectedFramework.get().type;
LOG.infof("Quinoa detected '%s' frameworkType from package.json file.", frameworkType);

return frameworkType.factory.override(config, Optional.of(packageJson), Optional.of(detectedFramework.get().devScript),
detectedFramework.get().isCustomized);
detectedFramework.get().isCustomized, uiDir);
}

private static JsonObject readPackageJson(Path packageJsonFile) {
Expand Down Expand Up @@ -197,4 +198,4 @@ public String toString() {
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import io.quarkiverse.quinoa.deployment.config.QuinoaConfig;
import io.quarkiverse.quinoa.deployment.config.delegate.PackageManagerCommandConfigDelegate;
import io.quarkiverse.quinoa.deployment.config.delegate.QuinoaConfigDelegate;
import io.quarkus.logging.Log;

public class AngularFramework extends GenericFramework {

Expand All @@ -24,13 +23,14 @@ public AngularFramework() {

@Override
public QuinoaConfig override(QuinoaConfig originalConfig, Optional<JsonObject> packageJson,
Optional<String> detectedDevScript, boolean isCustomized) {
Optional<String> detectedDevScript, boolean isCustomized, Path uiDir) {
final String devScript = detectedDevScript.orElse(getDefaultDevScriptName());
return new QuinoaConfigDelegate(super.override(originalConfig, packageJson, detectedDevScript, isCustomized)) {
return new QuinoaConfigDelegate(super.override(originalConfig, packageJson, detectedDevScript, isCustomized,
uiDir)) {
@Override
public Optional<String> buildDir() {
return Optional.of(originalConfig.buildDir().orElseGet(() -> {
final JsonObject angularJson = readAngularJson(originalConfig);
final JsonObject angularJson = readAngularJson(uiDir);
final JsonObject projectList = angularJson.getJsonObject("projects");
final JsonObject builder = projectList.values().stream()
.map(JsonValue::asJsonObject)
Expand All @@ -50,10 +50,8 @@ public Optional<String> buildDir() {
}));
}

private static JsonObject readAngularJson(QuinoaConfig configuration) {
Log.debug("=== Configuration ===" + configuration);
try (JsonReader reader = Json
.createReader(Files.newInputStream(Path.of(configuration.uiDir() + "/" + ANGULAR_JSON_FILE)))) {
private static JsonObject readAngularJson(Path uiDir) {
try (JsonReader reader = Json.createReader(Files.newInputStream(uiDir.resolve(ANGULAR_JSON_FILE)))) {
return reader.readObject();
} catch (IOException | JsonException e) {
throw new RuntimeException("Quinoa failed to read the angular.json file. %s", e);
Expand All @@ -80,4 +78,4 @@ public Optional<String> test() {
}
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static io.quarkiverse.quinoa.deployment.config.PackageManagerCommandConfig.DEFAULT_DEV_SCRIPT_NAME;
import static io.quarkiverse.quinoa.deployment.config.QuinoaConfig.DEFAULT_BUILD_DIR;

import java.nio.file.Path;
import java.util.Optional;

import jakarta.json.JsonObject;
Expand Down Expand Up @@ -53,7 +54,7 @@ public String getDefaultDevScriptName() {

@Override
public QuinoaConfig override(QuinoaConfig originalConfig, Optional<JsonObject> packageJson,
Optional<String> detectedDevScript, boolean isCustomized) {
Optional<String> detectedDevScript, boolean isCustomized, Path uiDir) {
final String devScript = detectedDevScript.orElse(defaultScriptName);
return new QuinoaConfigDelegate(originalConfig) {
@Override
Expand Down Expand Up @@ -84,4 +85,4 @@ public Optional<String> dev() {
}
};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkiverse.quinoa.deployment.framework.override;

import java.nio.file.Path;
import java.util.Optional;

import jakarta.json.JsonObject;
Expand All @@ -22,8 +23,7 @@ public NextFramework() {

@Override
public QuinoaConfig override(QuinoaConfig delegate, Optional<JsonObject> packageJson,
Optional<String> detectedDevScript,
boolean isCustomized) {
Optional<String> detectedDevScript, boolean isCustomized, Path uiDir) {
LOG.warn("Next.js version 13 and above are not fully supported yet. Please make sure to use version 12 or below.");

if (delegate.packageManagerCommand().build().orElse("???").equals("run build") && packageJson.isPresent()) {
Expand All @@ -43,7 +43,7 @@ public QuinoaConfig override(QuinoaConfig delegate, Optional<JsonObject> package
}
}

return new QuinoaConfigDelegate(super.override(delegate, packageJson, detectedDevScript, isCustomized)) {
return new QuinoaConfigDelegate(super.override(delegate, packageJson, detectedDevScript, isCustomized, uiDir)) {

@Override
public DevServerConfig devServer() {
Expand All @@ -58,4 +58,4 @@ public Optional<String> indexPage() {
}
};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkiverse.quinoa.deployment.framework.override;

import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
Expand All @@ -19,8 +20,8 @@ public ReactFramework() {

@Override
public QuinoaConfig override(QuinoaConfig delegate, Optional<JsonObject> packageJson, Optional<String> detectedDevScript,
boolean isCustomized) {
return new QuinoaConfigDelegate(super.override(delegate, packageJson, detectedDevScript, isCustomized)) {
boolean isCustomized, Path uiDir) {
return new QuinoaConfigDelegate(super.override(delegate, packageJson, detectedDevScript, isCustomized, uiDir)) {

@Override
public PackageManagerCommandConfig packageManagerCommand() {
Expand All @@ -36,4 +37,4 @@ public Map<String, String> devEnv() {
}
};
}
}
}

0 comments on commit 306c39e

Please sign in to comment.