-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #367: Framework automation detection
- Loading branch information
Showing
5 changed files
with
153 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
deployment/src/main/java/io/quarkiverse/quinoa/deployment/packagemanager/FrameworkType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package io.quarkiverse.quinoa.deployment.packagemanager; | ||
|
||
import java.util.Locale; | ||
import java.util.Set; | ||
|
||
/** | ||
* Configuration defaults for multiple JS frameworks that can be used to allow for easier adoption with less user configuration. | ||
*/ | ||
public enum FrameworkType { | ||
|
||
REACT("build", "start", 3000, Set.of("react-scripts", "react-app-rewired", "craco")), | ||
VITE("dist", "dev", 5173, Set.of("vite")), | ||
NEXT("out", "dev", 3000, Set.of("next")), | ||
ANGULAR("dist/%s", "start", 4200, Set.of("ng")), | ||
WEB_COMPONENTS("dist", "start", 8003, Set.of("web-dev-server")); | ||
|
||
/** | ||
* This the Web UI internal build system (webpack, …) output directory. After the build, Quinoa will take the files from | ||
* this directory, move them to 'target/quinoa-build' (or build/quinoa-build with Gradle) and serve them at runtime. | ||
*/ | ||
private final String buildDirectory; | ||
|
||
/** | ||
* The script to run in package.json in dev mode. | ||
*/ | ||
private final String devScript; | ||
|
||
/** | ||
* Default UI live-coding dev server port (proxy mode). | ||
*/ | ||
private final int devServerPort; | ||
|
||
/** | ||
* Match package.json scripts to detect this framework in use. | ||
*/ | ||
private final Set<String> packageScripts; | ||
|
||
FrameworkType(String buildDirectory, String devScript, int devServerPort, Set<String> packageScripts) { | ||
this.buildDirectory = buildDirectory; | ||
this.devScript = devScript; | ||
this.devServerPort = devServerPort; | ||
this.packageScripts = packageScripts; | ||
} | ||
|
||
/** | ||
* Try and detect the framework based on the script starting with a command like "vite" or "ng" | ||
* | ||
* @param script the script to check | ||
* @return either NULL if no match or the matching framework if found | ||
*/ | ||
public static FrameworkType evaluate(String script) { | ||
final String lowerScript = script.toLowerCase(Locale.ROOT); | ||
for (FrameworkType value : values()) { | ||
Set<String> commands = value.getPackageScripts(); | ||
for (String command : commands) { | ||
if (lowerScript.startsWith(command)) { | ||
return value; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public String getBuildDirectory() { | ||
return buildDirectory; | ||
} | ||
|
||
public String getDevScript() { | ||
return devScript; | ||
} | ||
|
||
public Set<String> getPackageScripts() { | ||
return packageScripts; | ||
} | ||
|
||
public int getDevServerPort() { | ||
return devServerPort; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters