public class FrontendUtils extends Object
For internal use only. May be renamed or removed in a future release.
Modifier and Type | Class and Description |
---|---|
static class |
FrontendUtils.CommandExecutionException
Thrown when the command execution fails.
|
static class |
FrontendUtils.UnknownVersionException
Thrown when detecting the version of a tool fails.
|
Modifier and Type | Field and Description |
---|---|
static String |
BOOTSTRAP_FILE_NAME
File name of the bootstrap file that is generated in frontend
GENERATED folder. |
static String |
BRIGHT_BLUE |
static String |
CHUNKS
A key in a Json object for chunks list.
|
static String |
CSS_IMPORTS
A key in a Json object for css imports data.
|
static String |
DEAULT_FLOW_RESOURCES_FOLDER
Deprecated.
This is deprecated due to a typo. Use
DEFAULT_FLOW_RESOURCES_FOLDER instead.
|
static String |
DEFAULT_CONNECT_APPLICATION_PROPERTIES
Default application properties file path in Vaadin project.
|
static String |
DEFAULT_CONNECT_JAVA_SOURCE_FOLDER
Default Java source folder for OpenAPI generator.
|
static String |
DEFAULT_CONNECT_OPENAPI_JSON_FILE
Default generated path for OpenAPI spec file.
|
static String |
DEFAULT_FLOW_RESOURCES_FOLDER
Default folder where front-end resources present in the classpath jars
are copied to.
|
static String |
DEFAULT_FRONTEND_DIR
Path of the folder containing application frontend source files, it needs
to be relative to the
DEFAULT_NODE_DIR
By default it is /frontend in the project folder. |
static String |
DEFAULT_GENERATED_DIR
Default folder name for flow generated stuff relative to the
InitParameters.BUILD_FOLDER . |
static String |
DEFAULT_NODE_DIR
Default folder for the node related content.
|
static String |
DEFAULT_PROJECT_FRONTEND_GENERATED_DIR
Default generated path for generated frontend files.
|
static String |
DISABLE_CHECK |
static String |
EXPORT_CHUNK
The entry-point key used for the exported bundle.
|
static String |
FALLBACK
A key in a Json object for fallback chunk.
|
static String |
FALLBACK_IMPORTS_NAME
Name of the file that contains all application imports, javascript, theme
and style annotations which are not discovered by the current scanning
strategy (but they are in the project classpath).
|
static String |
FLOW_NPM_PACKAGE_NAME
The NPM package name that will be used for the javascript files present
in jar resources that will to be copied to the npm folder so as they are
accessible to webpack.
|
static String |
FRONTEND
Default folder used for source and generated folders.
|
static String |
GENERATED
Default folder for client-side generated files inside the project root
frontend folder.
|
static String |
GREEN |
static String |
IMPORTS_D_TS_NAME
The TypeScript definitions for the
IMPORTS_NAME
file. |
static String |
IMPORTS_NAME
Name of the file that contains application imports, javascript, theme and
style annotations.
|
static String |
INDEX_HTML
File name of the index.html in client side.
|
static String |
INDEX_JS
File name of the index.js in client side.
|
static String |
INDEX_TS
File name of the index.ts in client side.
|
static String |
JS_MODULES
A key in a Json object for js modules data.
|
static String |
NODE_MODULES
Location for the installed node packages.
|
static String |
PARAM_FRONTEND_DIR
A parameter for overriding the
DEFAULT_FRONTEND_DIR
folder. |
static String |
PARAM_GENERATED_DIR
A parameter for overriding the
DEFAULT_GENERATED_DIR folder. |
static String |
PARAM_IGNORE_VERSION_CHECKS
Set to
true to ignore node/npm tool version checks. |
static String |
PARAM_TOKEN_FILE
A parameter informing about the location of the
TOKEN_FILE . |
static String |
PROJECT_BASEDIR |
static String |
RED |
static String |
SERVICE_WORKER_SRC
The name of the service worker source file for InjectManifest method of
workbox-webpack-plugin.
|
static String |
SERVICE_WORKER_SRC_JS
The JavaScript version of the service worker file, for checking if a user
has a JavaScript version of a custom service worker file already.
|
static String |
THEME_IMPORTS_D_TS_NAME |
static String |
THEME_IMPORTS_NAME |
static String |
TOKEN_FILE
File used to enable npm mode.
|
static String |
VITE_CONFIG
The name of the vite configuration file.
|
static String |
VITE_DEVMODE_TS
File name of Vite helper used in development mode.
|
static String |
VITE_GENERATED_CONFIG
The name of the generated vite configuration file.
|
static String |
WEBPACK_CONFIG
The name of the webpack configuration file.
|
static String |
WEBPACK_GENERATED
The name of the webpack generated configuration file.
|
static String |
WEBPACK_PREFIX_ALIAS
A special prefix used by webpack to map imports placed in the
DEFAULT_FRONTEND_DIR . |
static String |
YELLOW |
Modifier and Type | Method and Description |
---|---|
static void |
clearCachedStatsContent(VaadinService service)
Clears the
stats.json cache within this
VaadinContext . |
static String |
commandToString(String baseDir,
List<String> command)
Pretty prints a command line order.
|
static void |
console(String format,
Object message)
Intentionally send to console instead to log, useful when executing
external processes.
|
static ProcessBuilder |
createProcessBuilder(List<String> command)
Creates a process builder for the given list of program and arguments.
|
static void |
deleteDirectory(File directory)
Recursively delete given directory and contents.
|
static void |
deleteNodeModules(File nodeModules)
Try to remove the
node_modules directory, if it exists inside the
given base directory. |
static String |
executeCommand(List<String> command)
Executes a given command as a native process.
|
static InputStream |
getFrontendFileFromDevModeHandler(VaadinService service,
String path)
Get the contents of a frontend file from the running dev server.
|
static String |
getIndexHtmlContent(VaadinService service)
Gets the content of the
frontend/index.html file which is
served by webpack-dev-server in dev-mode and read from classpath in
production mode. |
static String |
getOsName()
Get the Operating System name from the
os.name system property. |
static FrontendVersion |
getPackageVersionFromJson(elemental.json.JsonObject sourceJson,
String pkg,
String versionOrigin)
Tries to parse the given package's frontend version or if it doesn't
exist, returns
null . |
static String |
getProjectFrontendDir(DeploymentConfiguration configuration)
Get directory where project's frontend files are located.
|
static String |
getStatsAssetsByChunkName(VaadinService service)
Load the asset chunks from
stats.json . |
static String |
getUnixPath(Path source)
Get path as a String in Unix form.
|
static String |
getUnixRelativePath(Path source,
Path target)
Get relative path from a source path to a target path in Unix form.
|
static File |
getVaadinHomeDirectory()
Gets vaadin home directory (
".vaadin" folder in the user home
dir). |
protected static FrontendVersion |
getVersion(String tool,
List<String> versionCommand) |
static boolean |
isWebpackConfigFile(File file)
Checks whether the
file is a webpack configuration file with the
expected content (includes a configuration generated by Flow). |
static boolean |
isWindows()
Check if the current os is Windows.
|
static FrontendVersion |
parseFrontendVersion(String versionString)
Parse the version number of node/npm from version output string.
|
static FallbackChunk |
readFallbackChunk(elemental.json.JsonObject object)
Read fallback chunk data from a json object.
|
static File |
resolveFrontendPath(File projectRoot,
String path)
Looks up the frontend resource at the given path.
|
static File |
resolveFrontendPath(File projectRoot,
String path,
File frontendDirectory)
Looks up the fronted resource at the given path.
|
static String |
streamToString(InputStream inputStream)
Read a stream and copy the content into a String using system line
separators for all 'carriage return' characters.
|
public static final String PROJECT_BASEDIR
public static final String DEFAULT_NODE_DIR
Constants.PACKAGE_JSON
, WEBPACK_CONFIG
,
NODE_MODULES
.
By default it's the project root folder.public static final String NODE_MODULES
NODE_PATH
.public static final String FRONTEND
public static final String GENERATED
public static final String DEFAULT_FRONTEND_DIR
DEFAULT_NODE_DIR
By default it is /frontend
in the project folder.public static final String WEBPACK_CONFIG
public static final String VITE_CONFIG
public static final String VITE_GENERATED_CONFIG
public static final String WEBPACK_GENERATED
public static final String SERVICE_WORKER_SRC
public static final String SERVICE_WORKER_SRC_JS
public static final String FLOW_NPM_PACKAGE_NAME
public static final String DEFAULT_FLOW_RESOURCES_FOLDER
InitParameters.BUILD_FOLDER
.@Deprecated public static final String DEAULT_FLOW_RESOURCES_FOLDER
public static final String DEFAULT_GENERATED_DIR
InitParameters.BUILD_FOLDER
.public static final String IMPORTS_NAME
DEFAULT_GENERATED_DIR
folder.public static final String IMPORTS_D_TS_NAME
IMPORTS_NAME
file.public static final String THEME_IMPORTS_D_TS_NAME
public static final String THEME_IMPORTS_NAME
public static final String BOOTSTRAP_FILE_NAME
GENERATED
folder. The bootstrap file is always executed in a
Vaadin app.public static final String INDEX_HTML
public static final String INDEX_TS
public static final String INDEX_JS
public static final String VITE_DEVMODE_TS
public static final String DEFAULT_CONNECT_JAVA_SOURCE_FOLDER
public static final String DEFAULT_CONNECT_APPLICATION_PROPERTIES
public static final String DEFAULT_CONNECT_OPENAPI_JSON_FILE
public static final String DEFAULT_PROJECT_FRONTEND_GENERATED_DIR
public static final String FALLBACK_IMPORTS_NAME
IMPORTS_NAME
file. It
is always generated in the DEFAULT_GENERATED_DIR
folder.public static final String PARAM_GENERATED_DIR
DEFAULT_GENERATED_DIR
folder.public static final String PARAM_FRONTEND_DIR
DEFAULT_FRONTEND_DIR
folder.public static final String PARAM_IGNORE_VERSION_CHECKS
true
to ignore node/npm tool version checks.public static final String WEBPACK_PREFIX_ALIAS
DEFAULT_FRONTEND_DIR
. e.g.
import 'Frontend/foo.js';
references the
filefrontend/foo.js
.public static final String TOKEN_FILE
public static final String CHUNKS
public static final String FALLBACK
public static final String EXPORT_CHUNK
public static final String CSS_IMPORTS
public static final String JS_MODULES
public static final String PARAM_TOKEN_FILE
TOKEN_FILE
.public static final String DISABLE_CHECK
public static final String YELLOW
public static final String RED
public static final String GREEN
public static final String BRIGHT_BLUE
public static String getOsName()
os.name
system property.public static boolean isWindows()
public static String streamToString(InputStream inputStream)
inputStream
- the input streampublic static ProcessBuilder createProcessBuilder(List<String> command)
command
- a list with the program and argumentspublic static void clearCachedStatsContent(VaadinService service)
stats.json
cache within this
VaadinContext
.service
- the vaadin service.public static String getIndexHtmlContent(VaadinService service) throws IOException
frontend/index.html
file which is
served by webpack-dev-server in dev-mode and read from classpath in
production mode. NOTE: In dev mode, the file content file is fetched via
webpack http request. So that we don't need to have a separate
index.html's content watcher, auto-reloading will work automatically,
like other files managed by webpack in `frontend/` folder.service
- the vaadin serviceIOException
- on error when reading filepublic static InputStream getFrontendFileFromDevModeHandler(VaadinService service, String path)
service
- the Vaadin service.path
- the file path.public static File resolveFrontendPath(File projectRoot, String path)
./
, first look in projectRoot/frontend
, then in
projectRoot/node_modules/@vaadin/flow-frontend
. If the path does
not start with ./
, look in node_modules
instead.projectRoot
- the project root folder.path
- the file path.File
, or null if the file doesn't exist.public static File resolveFrontendPath(File projectRoot, String path, File frontendDirectory)
./
, first look in projectRoot/frontendDirectory
, then in
projectRoot/node_modules/@vaadin/flow-frontend
. If the path does
not start with ./
, look in node_modules
instead.projectRoot
- the project root folder.path
- the file path.frontendDirectory
- the frontend directory.File
, or null if the file doesn't exist.public static String getStatsAssetsByChunkName(VaadinService service) throws IOException
stats.json
. We will only read the
file until we have reached the assetsByChunkName json and return that as
a json object string.
Note: The stats.json
is cached when external stats is
enabled or stats.json
is provided from the class path. To
clear the cache use clearCachedStatsContent(VaadinService)
.service
- the Vaadin service.null
if stats.json not found or content not found.IOException
- if an I/O error occurs while creating the input stream.public static String getProjectFrontendDir(DeploymentConfiguration configuration)
configuration
- the current deployment configurationDEFAULT_FRONTEND_DIR
or value of
PARAM_FRONTEND_DIR
if it is set.public static boolean isWebpackConfigFile(File file) throws IOException
file
is a webpack configuration file with the
expected content (includes a configuration generated by Flow).file
- a file to checktrue
iff the file exists and includes a generated
configurationIOException
- if an I/O error occurs while reading the filepublic static String getUnixRelativePath(Path source, Path target)
source
- the source pathtarget
- the target pathpublic static String getUnixPath(Path source)
source
- path to getpublic static FallbackChunk readFallbackChunk(elemental.json.JsonObject object)
object
- json object to read fallback chunk dataprotected static FrontendVersion getVersion(String tool, List<String> versionCommand) throws FrontendUtils.UnknownVersionException
public static String executeCommand(List<String> command) throws FrontendUtils.CommandExecutionException
command
- the command to be executed and it's arguments.FrontendUtils.CommandExecutionException
- if the process completes exceptionally.public static FrontendVersion parseFrontendVersion(String versionString) throws IOException
versionString
- string containing version output, typically produced by
tool --version
IOException
- if parsing failspublic static File getVaadinHomeDirectory()
".vaadin"
folder in the user home
dir).
The directory is created if it's doesn't exist.
public static String commandToString(String baseDir, List<String> command)
baseDir
- the current directorycommand
- the command and it's argumentspublic static FrontendVersion getPackageVersionFromJson(elemental.json.JsonObject sourceJson, String pkg, String versionOrigin)
null
. In case the value cannot be parsed, logs an
error and returns null
.sourceJson
- json object that has the packagepkg
- the package nameversionOrigin
- origin of the version (like a file), used in error messagenull
public static void console(String format, Object message)
format
- Format of the line to send to console, it must contain a `%s`
outlet for the messagemessage
- the string to showpublic static void deleteNodeModules(File nodeModules) throws IOException
node_modules
directory, if it exists inside the
given base directory. Note that pnpm uses symlinks internally, so delete
utilities that follow symlinks when deleting and/or modifying permissions
may not work as intended.nodeModules
- the node_modules
directoryIOException
- on failure to delete any one file, or if the directory name
is not node_modules
public static void deleteDirectory(File directory) throws IOException
Will not delete contents of symlink or junction directories, only the link file.
directory
- directory to deleteIOException
- on failure to delete or read any one fileCopyright © 2024. All rights reserved.