com.vaadin.flow.server.frontend.

Class FrontendUtils


  • public class FrontendUtils
    extends Object

    A class for static methods and definitions that might be used in different locations.

    Since:

    2.0

    • Method Detail

      • getOsName

        public static String getOsName()

        Get the Operating System name from the os.name system property.

        Returns:

        operating system name

      • isWindows

        public static boolean isWindows()

        Check if the current os is Windows.

        Returns:

        true if windows

      • getNodeExecutable

        public static String getNodeExecutable(String baseDir)

        Locate node executable.

        Parameters:

        baseDir - project root folder.

        Returns:

        the full path to the executable

      • getNpmExecutable

        public static List<String> getNpmExecutable(String baseDir)

        Locate npm executable.

        Parameters:

        baseDir - project root folder.

        Returns:

        the list of all commands in sequence that need to be executed to have npm running

      • getBowerExecutable

        public static List<String> getBowerExecutable(String baseDir)

        Locate bower executable.

        An empty list is returned if bower is not found

        Parameters:

        baseDir - project root folder.

        Returns:

        the list of all commands in sequence that need to be executed to have bower running, an empty list if bower is not found

      • streamToString

        public static String streamToString(InputStream inputStream)

        Read a stream and copy the content in a String.

        Parameters:

        inputStream - the input stream

        Returns:

        the string

      • createProcessBuilder

        public static ProcessBuilder createProcessBuilder(List<String> command)

        Creates a process builder for the given list of program and arguments. If the program is defined as an absolute path, then the directory that contains the program is also appended to PATH so that the it can locate related tools.

        Parameters:

        command - a list with the program and arguments

        Returns:

        a configured process builder

      • getStatsContent

        public static String getStatsContent(VaadinService service)
                                      throws IOException

        Gets the content of the stats.json file produced by webpack.

        Parameters:

        service - the vaadin service.

        Returns:

        the content of the file as a string, null if not found.

        Throws:

        IOException - on error reading stats file.

      • getStatsHash

        public static String getStatsHash(VaadinService service)
                                   throws IOException

        Get the latest has for the stats file in development mode. This is requested from the webpack-dev-server.

        In production mode and disabled dev server mode an empty string is returned.

        Parameters:

        service - the Vaadin service.

        Returns:

        hash string for the stats.json file, empty string if none found

        Throws:

        IOException - if an I/O error occurs while creating the input stream.

      • getStatsAssetsByChunkName

        public static String getStatsAssetsByChunkName(VaadinService service)
                                                throws IOException

        Load the asset chunks from stats.json. We will only read the file until we have reached the assetsByChunkName json and return that as a json object string.

        Parameters:

        service - the Vaadin service.

        Returns:

        json for assetsByChunkName object in stats.json

        Throws:

        IOException - if an I/O error occurs while creating the input stream.

      • validateNodeAndNpmVersion

        public static void validateNodeAndNpmVersion(String baseDir)

        Validate that the found node and npm versions are new enough. Throws an exception with a descriptive message if a version is too old.

        Parameters:

        baseDir - project root folder.

      • isWebpackConfigFile

        public static boolean isWebpackConfigFile(File file)
                                           throws IOException

        Checks whether the file is a webpack configuration file with the expected content (includes a configuration generated by Flow).

        Parameters:

        file - a file to check

        Returns:

        true iff the file exists and includes a generated configuration

        Throws:

        IOException - if an I/O error occurs while reading the file

      • readFallbackChunk

        public static FallbackChunk readFallbackChunk(elemental.json.JsonObject object)

        Read fallback chunk data from a json object.

        Parameters:

        object - json object to read fallback chunk data

        Returns:

        a fallback chunk data