use of com.vaadin.flow.server.frontend.FrontendToolsSettings in project flow by vaadin.
the class BuildFrontendUtil method prepareFrontend.
/**
* Prepares the Frontend
*
* @param adapter
* - the PluginAdapterBase.
* @throws IOException
* - Could not forceMkdir(adapter.generatedFolder());
* @throws ExecutionFailedException
* - While NodeTasks.execute()
* @throws URISyntaxException
* - Could not build an URI from nodeDownloadRoot().
*/
public static void prepareFrontend(PluginAdapterBase adapter) throws IOException, ExecutionFailedException, URISyntaxException {
final URI nodeDownloadRootURI = adapter.nodeDownloadRoot();
FrontendToolsSettings settings = getFrontendToolsSettings(adapter);
FrontendTools tools = new FrontendTools(settings);
tools.validateNodeAndNpmVersion();
try {
FileUtils.forceMkdir(adapter.generatedFolder());
} catch (IOException e) {
throw new IOException("Failed to create folder '" + adapter.generatedFolder() + "'. Verify that you may write to path.", e);
}
File flowResourcesFolder = new File(adapter.npmFolder(), Paths.get(adapter.buildFolder(), DEFAULT_FLOW_RESOURCES_FOLDER).toString());
ClassFinder classFinder = adapter.getClassFinder();
Lookup lookup = adapter.createLookup(classFinder);
NodeTasks.Builder builder = new NodeTasks.Builder(lookup, adapter.npmFolder(), adapter.generatedFolder(), adapter.frontendDirectory(), adapter.buildFolder()).useV14Bootstrap(adapter.isUseDeprecatedV14Bootstrapping()).withFlowResourcesFolder(flowResourcesFolder).createMissingPackageJson(true).enableImportsUpdate(false).enablePackagesUpdate(false).runNpmInstall(false).withNodeVersion(adapter.nodeVersion()).withNodeDownloadRoot(nodeDownloadRootURI).setNodeAutoUpdate(adapter.nodeAutoUpdate()).withHomeNodeExecRequired(adapter.requireHomeNodeExec()).setJavaResourceFolder(adapter.javaResourceFolder()).withProductionMode(adapter.productionMode());
// Copy jar artifact contents in TaskCopyFrontendFiles
builder.copyResources(adapter.getJarFiles());
try {
builder.build().execute();
} catch (ExecutionFailedException exception) {
throw exception;
} catch (Throwable throwable) {
// NOSONAR Intentionally throwable
throw new ExecutionFailedException("Error occured during goal execution: " + throwable.getMessage() + "\n\nPlease run Maven with the -e switch (or Gradle with the --stacktrace switch), to learn the full stack trace.", throwable);
}
}
use of com.vaadin.flow.server.frontend.FrontendToolsSettings in project flow by vaadin.
the class BuildFrontendUtil method getFrontendToolsSettings.
private static FrontendToolsSettings getFrontendToolsSettings(PluginAdapterBase adapter) throws URISyntaxException {
FrontendToolsSettings settings = new FrontendToolsSettings(adapter.npmFolder().getAbsolutePath(), () -> FrontendUtils.getVaadinHomeDirectory().getAbsolutePath());
settings.setNodeDownloadRoot(adapter.nodeDownloadRoot());
settings.setNodeVersion(adapter.nodeVersion());
settings.setAutoUpdate(adapter.nodeAutoUpdate());
settings.setUseGlobalPnpm(adapter.useGlobalPnpm());
settings.setForceAlternativeNode(adapter.requireHomeNodeExec());
return settings;
}
use of com.vaadin.flow.server.frontend.FrontendToolsSettings in project flow by vaadin.
the class BuildFrontendUtil method runFrontendBuild.
/**
* Execute the frontend build with the wanted build system.
*
* @param adapter
* - the PluginAdapterBase.
* @throws TimeoutException
* - while running build system
* @throws URISyntaxException
* - while parsing nodeDownloadRoot()) to URI
*/
public static void runFrontendBuild(PluginAdapterBase adapter) throws TimeoutException, URISyntaxException {
ClassFinder classFinder = adapter.getClassFinder();
Lookup lookup = adapter.createLookup(classFinder);
final FeatureFlags featureFlags = new FeatureFlags(lookup);
featureFlags.setPropertiesLocation(adapter.javaResourceFolder());
FrontendToolsSettings settings = getFrontendToolsSettings(adapter);
FrontendTools tools = new FrontendTools(settings);
if (featureFlags.isEnabled(FeatureFlags.VITE)) {
BuildFrontendUtil.runVite(adapter, tools);
} else {
BuildFrontendUtil.runWebpack(adapter, tools);
}
}
use of com.vaadin.flow.server.frontend.FrontendToolsSettings in project flow by vaadin.
the class BrowserLauncher method runNodeCommands.
private static int runNodeCommands(String script) throws InterruptedException, IOException {
FrontendToolsSettings settings = new FrontendToolsSettings("", () -> FrontendUtils.getVaadinHomeDirectory().getAbsolutePath());
FrontendTools tools = new FrontendTools(settings);
String node = tools.getNodeExecutable();
List<String> command = new ArrayList<>();
command.add(node);
command.add("-e");
command.add(script);
ProcessBuilder builder = FrontendUtils.createProcessBuilder(command);
return builder.start().waitFor();
}
Aggregations