Search in sources :

Example 1 with FrontendToolsSettings

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);
    }
}
Also used : FrontendToolsSettings(com.vaadin.flow.server.frontend.FrontendToolsSettings) ExecutionFailedException(com.vaadin.flow.server.ExecutionFailedException) ClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder) ReflectionsClassFinder(com.vaadin.flow.server.scanner.ReflectionsClassFinder) Lookup(com.vaadin.flow.di.Lookup) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) URI(java.net.URI) File(java.io.File) NodeTasks(com.vaadin.flow.server.frontend.NodeTasks) FrontendTools(com.vaadin.flow.server.frontend.FrontendTools)

Example 2 with FrontendToolsSettings

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;
}
Also used : FrontendToolsSettings(com.vaadin.flow.server.frontend.FrontendToolsSettings)

Example 3 with FrontendToolsSettings

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);
    }
}
Also used : FrontendToolsSettings(com.vaadin.flow.server.frontend.FrontendToolsSettings) ClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder) ReflectionsClassFinder(com.vaadin.flow.server.scanner.ReflectionsClassFinder) Lookup(com.vaadin.flow.di.Lookup) FeatureFlags(com.vaadin.experimental.FeatureFlags) FrontendTools(com.vaadin.flow.server.frontend.FrontendTools)

Example 4 with FrontendToolsSettings

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();
}
Also used : FrontendToolsSettings(com.vaadin.flow.server.frontend.FrontendToolsSettings) ArrayList(java.util.ArrayList) FrontendTools(com.vaadin.flow.server.frontend.FrontendTools)

Aggregations

FrontendToolsSettings (com.vaadin.flow.server.frontend.FrontendToolsSettings)4 FrontendTools (com.vaadin.flow.server.frontend.FrontendTools)3 Lookup (com.vaadin.flow.di.Lookup)2 ClassFinder (com.vaadin.flow.server.frontend.scanner.ClassFinder)2 ReflectionsClassFinder (com.vaadin.flow.server.scanner.ReflectionsClassFinder)2 FeatureFlags (com.vaadin.experimental.FeatureFlags)1 ExecutionFailedException (com.vaadin.flow.server.ExecutionFailedException)1 NodeTasks (com.vaadin.flow.server.frontend.NodeTasks)1 File (java.io.File)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1