LiquidJS substitutions
To increase reusability, it is possible to use substitutions in in all xpm metadata definitions. The syntax is more elaborate than the simple variable substitution, and is using the LiquidJS template engine syntax, which accepts the full LiquidJS syntax.
The LiquidJS definitions are:
- variables, like
{{ configuration.name }} - filters, like
{{ configuration.name | downcase }} - tags, like
{% if os.platform != 'win32' %}xpm run execute --config synthetic-posix-cmake-debug{% endif %}
For more details, please see the documentation for the
xpack/xpm-liquid-ts module, where
the substitutions are implemented.
Predefined variables
The LiquidJS syntax to include variables uses double curly braces:
{{variable}}
Example:
"install": "xpm install --config {{configuration.name}}"
The main source for variables are the properties maps.
When substitutions occur within a build configuration, the properties
defined in the build configuration take precedence over properties
with the same name defined at the project level.
The available variables are:
package.*- the entirepackage.jsonparsedproperties.*- user defined string propertiesconfiguration.name- the name of the current configurationconfiguration.*- the entire current configuration parsedenv.*- the Node.js process environmentos.*- the Node.jsosdefinitionsos.EOLos.arch(like 'arm', 'arm64', 'ia32', 'x64')os.constantsos.cpusos.endiannessos.homediros.hostnameos.platform(like 'darwin', 'linux', 'win32')os.releaseos.tmpdiros.typeos.version(available since Node 12)
path.*definitionspath.delimiter(;for Windows,:for POSIX)path.sep(\on Windows,/on POSIX)path.win32.delimiter(;)path.win32.sep(\)path.posix.delimiter(:)path.posix.sep(/)
Custom filters
Filters act like pipes processing strings. The syntax is similar to the shell pipe syntax:
{{variable|filter}}
Example:
"buildFolderRelativePath": "{{'build' | path_join: configuration.name | to_filename | downcase}}"
In addition to the standard LiquidJS filters, the following xpm specific filters are also available:
path_basenamepath_dirnamepath_normalizepath_joinpath_relativepath_posix_basenamepath_posix_dirnamepath_posix_normalizepath_posix_joinpath_posix_relativepath_win32_basenamepath_win32_dirnamepath_win32_normalizepath_win32_joinpath_win32_relativeutil_formatto_filenameto_posix_filenameto_win32_filename
Multi-line definitions
If multiple lines are generated via loops, line terminators can be inserted
with {{ os.EOL }}), for example:
{% for command in package.xpack.my_commands %}{{ command }}{{ os.EOL }}{% endfor %}