Class FrontendConverter

java.lang.Object
com.vaadin.flow.polymer2lit.FrontendConverter
All Implemented Interfaces:
AutoCloseable

public class FrontendConverter extends Object implements AutoCloseable
A converter that converts Polymer-based *.js source files to Lit. Effectively, this is a wrapper around the convert.ts script.
  • Constructor Summary

    Constructors
    Constructor
    Description
    FrontendConverter(com.vaadin.flow.server.frontend.FrontendTools frontendTools)
    Creates a converter that runs the bundled convert.js script with the Node.js executable provided by the given tools.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    boolean
    convertFile(Path filePath, boolean useLit1, boolean disableOptionalChaining)
    Converts a single Polymer-based *.js file to Lit in place.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • FrontendConverter

      public FrontendConverter(com.vaadin.flow.server.frontend.FrontendTools frontendTools) throws IOException
      Creates a converter that runs the bundled convert.js script with the Node.js executable provided by the given tools.

      The script is unpacked into a temporary directory that is removed again by close(), so the converter has to be closed after use.

      Parameters:
      frontendTools - the tools used to locate the Node.js executable
      Throws:
      IOException - if the temporary directory or the script copy cannot be created
  • Method Details

    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Throws:
      IOException
    • convertFile

      public boolean convertFile(Path filePath, boolean useLit1, boolean disableOptionalChaining) throws IOException, InterruptedException, com.vaadin.flow.internal.FrontendUtils.CommandExecutionException
      Converts a single Polymer-based *.js file to Lit in place.

      Files that do not contain PolymerElement are left untouched.

      Parameters:
      filePath - the file to convert
      useLit1 - true to generate Lit 1 compatible output, false to target the current Lit version
      disableOptionalChaining - true to avoid the optional chaining operator in the generated output, for tooling that cannot parse it
      Returns:
      true if the file was converted, false if it is not a Polymer file
      Throws:
      IOException - if the file cannot be read or written
      InterruptedException - if waiting for the converter process is interrupted
      com.vaadin.flow.internal.FrontendUtils.CommandExecutionException - if the converter process fails