Exporting XLRs
XLR creation is done through the Player CLI which can be added to your project like so:
npm i @player-cli/cliyarn add @player-cli/clipnpm add @player-cli/cliExporting Base Type Definitions
Section titled “Exporting Base Type Definitions”If you want to compile all exported interfaces/types and are using our Bazel rules, you will want to use the js_xlr_pipeline macro and set the xlr_mode option to "types".
js_xlr_pipeline( package_name = "<package name>", xlr_mode = "types", cli = "@player-cli/cli")If you are not using our Bazel rules, run the Player CLI as part of your build
player xlr compile -m types <other options>Exporting Plugin Capabilities
Section titled “Exporting Plugin Capabilities”If you are writing a Player Plugin, you’ll first need to have your plugin extend the ExtendedPlayerPlugin interface and fill in the generics with an array of the interfaces/types for each Capability. In order, the generics denote:
- Assets
- Views
- Expressions
- Data Types
- Formatters
- Validators
All six generics default to void, so you only need to fill in the ones your plugin actually provides. A plugin that only exports Assets doesn’t need to touch the remaining five.
For example, you can see how its done below in the core reference assets plugin
export class ReferenceAssetsPlugin implements PlayerPlugin, ExtendedPlayerPlugin< [InputAsset, TextAsset, ActionAsset, InfoAsset, CollectionAsset] >If you are using our Bazel rules, you will want to use the same js_xlr_pipeline macro. The default mode is "plugin" so the xlr_mode option can be omitted or explicitly set if desired.
js_xlr_pipeline( package_name = "<package name>", build_deps = [...], peer_deps = [...], test_deps = [...], deps = [...], xlr_mode = "plugin", cli = "@player-cli/cli")Non-Bazel
Section titled “Non-Bazel”Otherwise, if you are not using Bazel then run the following command as part of your build
player xlr compile -m plugin <other options>Reverse Direction: Generating TypeScript from XLRs
Section titled “Reverse Direction: Generating TypeScript from XLRs”The conversion also works backwards. @xlr-lib/xlr-converters exports exportTypesToTypeScript(typesToExport, importMap), which takes a list of XLR NamedTypes and generates a TypeScript .d.ts file body from them. This is useful for tooling that only has XLR JSON to work with (no original source) but still needs TypeScript types, for example generating types for a cross-platform consumer. See Architecture for where this fits into the broader package layout.