avocado
avocado
is a command line tool (similar to svgo
) that optimizes Android
VectorDrawable
(VD) and AnimatedVectorDrawable
(AVD) xml files.
Installation
You can install avocado
using npm w/ the following command:
npm install -g avocado
Usage
Usage: avocado [options] [file] Options: -V, --version output the version number -s, --string <string> input VD or AVD string -i, --input <file> input file/directory, or "-" for STDIN -o, --output <file> output file/directory (same as the input file by default), or "-" for STDOUT -d, --dir <dir> optimizes and rewrite all *.xml files in a directory -q, --quiet only output error messages -h, --help output usage information
Examples
# Optimize (and overwrite) a VD/AVD file. avocado vector.xml # Optimize (and overwrite) multiple VD/AVD files. avocado *.xml # Optimize a VD/AVD file and write the output to a new file. avocado vector.xml -o vector_min.xml # Optimize a VD/AVD using standard input and standard output. cat vector.xml | avocado -i - -o - > vector_min.xml # Optimize (and overwrite) all of the VD/AVD files in a directory. avocado -d path/to/directory # Optimize all VD/AVD files in a directory and write them to a new directory. avocado -d path/to/input/directory -o path/to/output/directory # Optimize all files ending with '.xml' and write them to a new directory. avocado *.xml -o path/to/output/directory # Pass a string as input and write the output to a new file. avocado -s '<vector>...</vector>' -o vector_min.xml
avocado
rewrites the VectorDrawable
using the smallest number of <group>
s and <path>
s possible, reducing their file sizes and making them faster to parse and draw at runtime. The example below shows the contents of a VectorDrawable
before and after being run through avocado
.
Before
After
Build instructions
If you want to contribute, first be sure to install the latest version of
Node.js
and npm
.
If you're not sure what IDE to use, I highly recommend checking out
vscode.
Then clone this repository and in the root directory, run:
npm install
To build the tool, run:
npm run build
To test the tool, run:
npm run test