relottie-cli
Command line interface to inspect and change Lottie files with relottie.
Contents
- What is this?
- When should I use this?
- Install
- CLI
- Examples
- Example: config files (JSON, YAML, JS)
- Compatibility
- Security
- Acknowledgments
What is this?
This package is a command line interface (CLI) that you can use in your terminal or in npm scripts and the like to inspect and change lottie files. This CLI is built around relottie, which is an ecosystem of plugins that work with lottie as structured data, specifically ASTs (abstract syntax trees). You can choose from the 10+ plugins that already exist or make your own.
See the monorepo readme for info on what the relottie ecosystem is.
When should I use this?
You can use this package when you want to work with the lottie files in your
project from the command line.
relottie-cli
has many options and you can combine it with many plugins, so it
should be possible to do what you want.
If not, you can always use relottie
itself manually in a script.
Install
This package is ESM only. In Node.js (version 14.14+, or 16.0+) install with npm:
CLI
The interface of relottie-cli
is explained as follows on its help page
(relottie --help
):
More information on all these options is available at
unified-args
, which does the work.
relottie-cli
is unified-args
preconfigured to:
- Load
@lottiefiles/relottie-
plugins - Search for lottie extensions
.json
- Ignore paths found in
.relottieignore
files - Load configuration from
.relottierc
,.relottierc.js
, etc files - Use configuration from
relottieConfig
fields inpackage.json
files
Examples
This example converts LottieJSON into Lottie AST last with relottie-cli
.
It assumes you’re in a Node.js package.
First, install the CLI and plugins:
Now, add an npm script in your package.json
:
Observe that the above change adds a relottie
plugins script, which can be run with
npm run generate:last
.
It runs relottie on all lottie files under (lottie-animation
) directory
(it’s better to specify the folder because Lottie files are JSON format) and rewrites them (--output
).
Run ./node_modules/.bin/relottie --help
for more info on the CLI.
Then, add a relottieConfig
to your package.json
to configure relottie:
👉 Note: you must remove the comments in the above examples when copy/pasting them, as comments are not supported in
package.json
files.
Finally, you can run the npm script to replace Lottie Files with last files in your project:
Example: config files (JSON, YAML, JS)
In the previous example, we saw that relottie-cli
was configured from within a
package.json
file.
That’s a good place when the configuration is relatively short, when you have a
package.json
, and when you don’t need comments (which are not allowed in
JSON).
You can also define configuration in separate files in different languages.
With the package.json
config as inspiration, here’s a JavaScript version that
can be placed in .relottierc.js
:
This is the same configuration in YAML, which can be placed in .relottierc.yml
:
When relottie-cli
is about to process a lottie file it’ll search the file
system upwards for configuration files starting at the folder where that file
exists.
Take the following file structure as an illustration:
When folder/subfolder/file.json
is processed, the closest config file is
folder/subfolder/.relottierc.json
.
For folder/readme.md
, it’s folder/.relottierc.js
.
The order of precedence is as follows.
Earlier wins (so in the above file structure folder/.relottierc.js
wins over
folder/package.json
):
.relottierc
(JSON).relottierc.json
(JSON) (we should not use it since Lottie files are.json
formats).relottierc.cjs
(CJS).relottierc.mjs
(ESM).relottierc.js
(CJS or ESM, depending ontype: 'module'
inpackage.json
).relottierc.yaml
(YAML).relottierc.yml
(YAML)package.json
withrelottieConfig
field
Compatibility
Projects maintained by the unified collective are compatible with all maintained versions of Node.js. As of now, that is Node.js 14.14+, and 16.0+. Our projects sometimes work with older versions, but this is not guaranteed.
Security
As last properties can have expressions, and improper use of last can open you up to cross-site scripting cross-site scripting (XSS). Carefully assess each plugin and the risks involved in using them.
Contribute
Any contributions are welcome.
By interacting with this repository, organization, or community you agree to abide by its terms.