The commands of the Chassis Assets build, its configuration, the rules of each platform, the checks, the library and its use in CI.
This documentation is a work in progress. Some information may be incomplete, outdated, or differ from the current product behavior.
Introduction
The build copies the files of source/<brand>/<app>/<type>/ to dist/<platform>/<app>/<brand>/. On the way it leaves out the formats a platform does not use, renames each file for the platform, and sorts Android image variants into density folders. By default it does not resize, convert or re-encode a file: the options of Optimization and Image formats do the last two.
This page is the reference of the build: its commands and options, the chassis block that configures it, the rules of each platform, the checks that read its output, the releases, and the library behind the commands.
Prerequisites
The build needs Node.js 22.12 or later and the package @chassis-ui/assets, which has no dependencies: a plain install brings nothing else. The options that convert files load a package each, an optional peer dependency that you install beside the build when you use the option: sharp and svgo for --optimize, --webp and --avif, subset-font for --subset, and svg2vectordrawable for --vector-drawables.
Run every command from the root of the repository of assets, or name it with --cwd. A clone needs its Git LFS files, see Build fails on pointers.
Commands
Each command is chassis-assets <command>, run with npx chassis-assets where the package is installed, and each one prints its options with --help. The scripts that chassis-assets init writes into package.json call them: npm run build, lint, verify, archive and analyze.
| Command | What it does |
|---|---|
chassis-assets build | Builds every job of the configuration into dist/ |
chassis-assets lfs | Prints the Git LFS paths that a build with the same filters reads, for git lfs pull --include |
chassis-assets archive | Writes one zip per platform, app and brand of an existing output, for a release, see Releases |
chassis-assets manifest | Writes the list of the files of an existing output with their sizes and hashes, see Releases |
chassis-assets diff --base <manifest> | Reports the files added, removed, renamed and changed since a manifest, see Releases |
chassis-assets release-notes [version] | Prints the entry of a version in CHANGELOG.md, and exits 1 without one, see Releases |
chassis-assets check-native | Compiles an existing output with the tools of Xcode and of Android, see Native checks |
chassis-assets init [dir] | Writes the baseline of a repository of assets into a folder, see the quick start |
chassis-assets static-font <font> <output...> <axis>=<value> | Writes the static font of a variable font at a weight to each output, see Files by weight |
chassis-assets validate | Checks an existing output against the source and the configuration |
chassis-assets contract | Checks that an existing output has the files its consumers read by name |
chassis-assets verify | Runs the validator, then the contract check |
chassis-assets lint-source | Checks the names and the layout of source/, and the fonts against their stylesheets |
chassis-assets analyze | Reports sizes, types, the largest files and files with the same content |
Build options
The options of chassis-assets build select the jobs, the folders and what happens to the output that is already there.
| Option | What it does |
|---|---|
--brand <name...> | Only these brands |
--app <name...> | Only these apps |
--platform <name...> | Only these platforms |
--type <name...> | Only these type folders of an app, such as images and icons |
--include <pattern...> | Only the files that match a pattern, by their path in the folder of the app, such as "images/home/**" |
--clean | Remove the output first, of the selected jobs when filtered |
--no-clean | Keep the output even for a full build |
--out <dir> | Output folder, dist by default |
--cwd <dir> | Repository root, by default the nearest folder upward whose package.json has a chassis block |
--watch | Build, then build the jobs of a brand and an app again when a file of theirs under source/ changes |
--dry-run | Print the jobs and their file counts, write nothing |
--allow-lfs-pointers | Copy Git LFS pointer files instead of failing. CHASSIS_ALLOW_LFS_POINTERS=1 does the same |
--vector-drawables | Write the SVG icons of Android as vector drawables, .xml in place of .svg. Needs svg2vectordrawable |
--asset-catalog | Write the images of iOS as an asset catalog, Assets.xcassets in place of images/ |
--icon-catalog | Write the icons of iOS as an asset catalog, Icons.xcassets in place of icons/ |
--res | Write the fonts, images and icons of Android as a res/ folder, with night folders for a pair x_light and x_dark, drawable-nodpi for an image of one size, and with --vector-drawables the app icon |
--optimize | Write the images again under their names where that makes them smaller, with the settings of chassis.optimize. Needs sharp and svgo |
--webp | Write the PNG and JPEG images as WebP too: beside the file on the web, in place of it on Android. Needs sharp |
--avif | Write the PNG and JPEG images of the web as AVIF too. Needs sharp |
--subset [range...] | Write the WOFF and WOFF2 fonts of the web again under their names with the characters of the ranges only, such as latin or U+0370-03FF. Default: chassis.subset, or latin and latin-ext. Needs subset-font |
--split, --no-split | With --subset, write each font that a stylesheet declares once per range too, with a rule per range in the stylesheet, or write a font in one file. Default: split of chassis.subset, or one file |
--quiet | Print errors only |
--help, -h | Print the options |
--version, -v | Print the version |
Filters
A filter takes one or more values, and the filters combine: the build runs the jobs that match all of them.
npx chassis-assets build --brand acme
npx chassis-assets build --platform ios android
npx chassis-assets build --brand acme --app site --platform webA value that the configuration does not have fails the build and names the configured values. Filters that match no job together, such as an app with a platform it is not built for, fail the build too.
File filters
The --type and --include options build a part of a job: the build reads only the files of an app that match, and writes them where a full build does, with the same names. Use them when you read a part of the output, to fetch and copy that part only.
npx chassis-assets build --type images icons
npx chassis-assets build --brand acme --app site --include "fonts/**" "images/logo/**"--type names type folders. --include takes patterns of paths as they are in source/, relative to the folder of the app, so with the source names and not the names of a platform. A file has to pass both options when both are given.
| Pattern | Matches |
|---|---|
images/logo/wordmark.svg | That file |
images/logo | Every file under the folder, at any depth |
images/* | The files of images/ itself, not of its subfolders |
images/**/*.svg | The SVG files of images/, at any depth |
images/onboarding/welcome-{light,dark}{,@2x}.png | Four files: {a,b} is one of its alternatives, an empty one too |
Quote a pattern, or the shell expands it. A build with a file filter keeps the rest of dist/, as a build with any filter does. Filters that match no file fail the build. Filters that match no file of one job among several warn, and that job gets no folder. The validator checks a full build, so chassis-assets verify fails on an output of a part.
A file that the filters leave out is not read, so it may be a Git LFS pointer. chassis-assets lfs takes the same filters and prints the paths of source/ that the build reads, separated by commas, which is the value git lfs pull --include takes. A folder whose files are all read is one path. In a clone made without the Git LFS files, fetch the files of a build and run it:
FILTERS=(--brand acme --app site --include "fonts/**" "images/logo/**")
git lfs pull --include "$(chassis-assets lfs "${FILTERS[@]}")"
npx chassis-assets build "${FILTERS[@]}"Cleaning
A build without filters removes dist/ first, so the output holds nothing of an earlier build. A build with filters keeps dist/ and writes over the files of its jobs, so you can build one job after another.
npx chassis-assets build # removes dist/, builds every job
npx chassis-assets build --no-clean # keeps dist/, builds every job
npx chassis-assets build --brand acme --platform web # keeps dist/, builds the selected jobs
npx chassis-assets build --clean --brand acme --app site # removes the folders of the selected jobs firstWith filters, --clean removes the folders of the selected jobs only. The output of the other jobs stays.
Watch
The --watch option builds once, then keeps running and builds again when a file under source/ changes. Use it while you export from a design tool, with the filters of the jobs you look at:
npx chassis-assets build --watch --platform ios --app mobileA change builds the jobs it belongs to, and no other. A file of a brand builds the jobs of that brand and its app. A file of the default brand builds the jobs of its app for every brand, since every brand gets it. A file of a _shared folder builds every app of its brand. Changes that come together, as an export of many files does, are one build.
A job is built whole, into a folder that is removed first, so a file you delete from source/ is gone from the output and the output of a job is always what a build of it writes. Every other option of the build applies to each of these builds. A build that fails prints its error, and the watch goes on. Hidden files and the other files the build ignores start no build. Stop the watch with Ctrl + C.
The watch reads package.json when it starts: after a change to the chassis block, start it again.
Vector drawables
The --vector-drawables option writes each SVG file under icons/ of an Android job as a vector drawable, the format the res/drawable/ folder of an app takes. It is off by default, and the output of every other platform and type stays as it is.
npm install svg2vectordrawable
npx chassis-assets build --vector-drawablesThe file keeps its folder and its name and gets the .xml extension: icons/ic_arrow_right_solid.svg becomes icons/ic_arrow_right_solid.xml. A path without a fill color is filled black, which a tint replaces in the app.
The conversion is the one step of the build that uses a package, svg2vectordrawable, and the build loads it only with this option. Without the package the build stops before it removes anything and names the package as the fix. An SVG without a shape stays an SVG and the build warns about it. A file that is not an SVG fails the build.
Asset catalog
The --asset-catalog option moves the images of an iOS job from images/ into Assets.xcassets, the folder Xcode reads image sets from. It is off by default, needs nothing installed, and leaves the output of every other platform and type as it is.
npx chassis-assets build --asset-catalogThe files of one base name are one image set, with the Contents.json that Xcode writes: images/badge.png, images/badge@2x.png and images/badge@3x.png become Assets.xcassets/badge.imageset/, each file in the slot of its indicator. An SVG or a PDF without a raster of its name is an image set of one file that keeps its vector data. A subfolder of images/ is a folder of the catalog that provides a namespace, so images/logo/mark@2x.png is in Assets.xcassets/logo/mark.imageset/ and an app names it logo/mark.
A file without a place in an image set stays in images/, and the build warns once per job with the number of such files. These are an SVG or a PDF beside a raster of its name, a variant with another indicator than @1x, @2x or @3x, a second file for one slot, and any format but PNG, JPEG, SVG and PDF. The files of <name>_light and <name>_dark are one image set, <name>, with the dark files in the row of the dark appearance. They stay two sets when one is a vector and the other a raster, or when a set of <name> exists.
The --icon-catalog option does the same for the icons of an iOS job, from icons/ into Icons.xcassets. An icon SVG that paints only in currentcolor renders as a template, in the tint of its view; one with another color or a gradient keeps its colors. An SVG that holds <symbol> elements is no image, and stays in icons/.
npx chassis-assets build --asset-catalog --icon-catalogOptimization
The --optimize option writes each image of images/ again under its own name, when that makes the file smaller. It is off by default: the files of source/ are what the designer exported, and the default build copies them as they are.
npm install sharp svgo
npx chassis-assets build --optimizeWithout settings the option changes no pixel that anyone sees. What it does to a format:
| Format | Without settings | With a setting of chassis.optimize |
|---|---|---|
| PNG | Compressed again, every pixel kept | png.quality reduces the colors to a palette |
| JPEG | Left as it is: a JPEG cannot be encoded again without a loss | jpeg.quality encodes it again |
| SVG | Comments, metadata and white space removed, the shapes kept | svg.precision rounds the coordinates and rewrites the paths |
| WebP, GIF and any other | Left as it is |
A file keeps its name on every platform, so nothing that reads the output changes. A file that would not get smaller stays as it was copied. The ids of an SVG and the symbols of a sprite are kept, since a page refers to them from outside the file. A file with the extension of an image that is no image fails the build, which names the file.
The option uses the packages sharp and svgo, which the build loads only with it. Without the packages the build stops before it removes anything and names the package as the fix. The chassis.optimize block has the settings.
The archives of a release are built with this option, and with no other: an archive has the files and the names of a default build, with smaller PNG and SVG images.
Image formats
The --webp and --avif options write each PNG and JPEG image of images/ in a second format. Both are off by default, and both use the package sharp.
npm install sharp
npx chassis-assets build --webp # WebP for the web and Android
npx chassis-assets build --webp --avif # and AVIF for the webWhere the file is written depends on the platform:
| Platform | --webp | --avif |
|---|---|---|
| Web | hero.webp beside hero.png, for a <picture> element to choose from | hero.avif beside hero.png |
| Android | hero.webp in place of hero.png, when it is smaller: a resource has one file per name | Nothing |
| iOS | Nothing | Nothing |
A WebP of a PNG is lossless without settings, so on Android the image is the same and the file is smaller. A WebP of a JPEG and every AVIF are encoded with the quality of chassis.optimize. An SVG, a GIF and a WebP of the source get no second format.
A file of source/ wins over the one the build would write: when the designer exported hero.webp beside hero.png, that WebP is copied and none is written. With --optimize, the second format is written from the source image, not from the optimized one.
Font subsets
The --subset option writes each WOFF and WOFF2 font of a web job again under its own name, with the characters of a list of Unicode ranges only. It is off by default: a font of source/ holds every script its designer drew, and the default build copies it whole.
npm install subset-font
npx chassis-assets build --subset # the ranges of chassis.subset, or latin and latin-ext
npx chassis-assets build --subset latin greek # these ranges
npx chassis-assets build --subset U+0020-007E # a range by its code pointsA range is a name or a range of code points written as U+0370-03FF. A name stands for the code points that Google Fonts serves under it. The values of the option win over the chassis.subset block, and without either the build keeps latin and latin-ext.
| Name | Characters |
|---|---|
latin | Basic Latin and Latin-1, general punctuation and the euro sign: the letters of Western European languages |
latin-ext | The letters of the other languages written in Latin letters, such as Turkish, Polish and Czech |
cyrillic, cyrillic-ext | Cyrillic, and its historic and less common letters |
greek, greek-ext | Greek, and polytonic Greek |
vietnamese | The letters and tone marks of Vietnamese |
math | Mathematical operators, arrows, and the Greek letters and the alphabets of formulas |
symbols | Arrows, geometric shapes, dingbats and pictographs |
symbols2 | Box drawing and block characters, such as the lines of a file tree in a code font |
A font keeps its name, its format and its layout features, such as the ligatures of a code font, so the stylesheets of fonts/ and the pages that load them stay as they are. A character outside the ranges is drawn with the next font of the font-family list. A font that would not get smaller stays as it was copied, and so does a font that has no character of the ranges, with a warning that names it.
A variable font keeps its axes. A browser uses an axis without being asked: it sets the optical size, opsz, from the font size of the text, so a heading is drawn in another cut than a paragraph. To leave an axis out of the fonts of a brand, fix it at a value with axes of the chassis.subset block. The build then writes each font that has the axis without it, as the font it is at that value, and the file is smaller.
A font is one file with the characters of every range. With the --split option, the build also writes each font that a stylesheet of fonts/ declares once per range, beside it, and writes the @font-face rule of the stylesheet once per range, each with the unicode-range of its file. A browser then downloads the file of a range only when the page has a character of that range.
npx chassis-assets build --subset latin latin-ext --splitdist/web/<app>/<brand>/fonts/
├── fonts.css -> a rule per range, with its unicode-range
├── ui-latin-ext.woff2 -> the characters of latin-ext
├── ui-latin.woff2 -> the characters of latin
├── ui.woff2 -> the characters of both ranges, as without split
└── ...The file of a range has the name of the font, a hyphen and the name of the range: ui-latin.woff2, and code-u2500-257f.woff2 for the range U+2500-257F. A font gets no file for a range that it has no character of. The font itself stays, with the characters of every range, for a page that writes its own rules.
The rules of the range you name first are the last ones in the stylesheet. A browser reads the rules of a family from the last to the first, so a character that two ranges hold is drawn with the file of the first range.
Three kinds of rules and fonts stay as they are. A rule with a unicode-range of its own is left to you. A rule whose src names something else than a WOFF or WOFF2 font of the folder is left with a warning. A font that no stylesheet declares, such as the files by weight beside a variable font, stays one file.
The split costs a page that has characters of two ranges: the two files share glyphs and are larger together than the one file. A browser also shapes the text of each file on its own, so a pair of letters from two files has no kerning. So the split is a choice of each build: --split and --no-split win over split of the chassis.subset block, which is the choice of the repository. --split without --subset fails the build.
Only the fonts of fonts/ of a web job are written again. The TTF and OTF fonts of iOS and Android stay whole, and so does a font file outside fonts/. A file with the extension of a font that is no font fails the build, which names the file.
The option uses the package subset-font, which the build loads only with it. Without the package the build stops before it removes anything and names the package as the fix. Check the license of a font before you publish a subset of it: a license may ask for another name for a changed font.
Res folder
The --res option moves the files of an Android job that the res/ folder of an app takes into one, dist/android/<app>/<brand>/res/. It is off by default, needs nothing installed, and leaves the output of every other platform as it is.
npx chassis-assets build --res
npx chassis-assets build --res --vector-drawables # with the icons, needs svg2vectordrawableA TTF or OTF file of fonts/ moves to res/font/. A PNG, WebP, JPEG or GIF file of images/ moves to the folder of res/ that is named as its density folder, so images/logo/drawable-xhdpi/mark.png becomes res/drawable-xhdpi/mark.png. An image with no density folder at all goes to res/drawable-nodpi/, which Android does not scale. A vector drawable of icons/ moves to res/drawable/, which makes --vector-drawables the option that brings the icons into res/.
A pair <name>_light and <name>_dark of one folder is the resource <name>, with the dark files in the folders of the night qualifier: res/drawable-xhdpi/<name>.png and res/drawable-night-xhdpi/<name>.png. A vector and a raster stay apart, and a drawable with the name of a pair fails the build. With --vector-drawables, a bundle <name>.adaptive becomes the app icon res/mipmap-anydpi-v26/<name>.xml, see App icons; without it the bundle stays, with a warning that names the option.
The res/ folder does not nest, so the subfolders of images/ and icons/ are dropped. When two folders hold an image of one name, the folder nearest to images/ gets the resource with every density it has, and the files of the other folder stay. The source lint warns about those files.
A file without a place in res/ stays where it is, and the build warns once per job with the number of such files. These are the font licenses, every SVG file, a second file of a name in another format, such as text.otf beside text.ttf or a WebP beside a PNG, and a name that cannot be a resource: one that starts with a digit, or a word of Java such as default.
Configuration
The chassis block of the package.json of the repository of assets names what is built, and holds the optional settings: optimize, subset, ignore and formats. What the checks verify is in a file of its own, see Checks file. The block of a repository with two brands and two apps:
{
"chassis": {
"defaults": {
"brandFolder": "_default"
},
"build": {
"brands": ["acme", "globex"],
"apps": {
"site": ["web"],
"mobile": ["ios", "android"]
}
}
}
}chassis.defaults
brandFolder is the name of the default brand in source/, the folder whose files every brand gets. It is _default unless the block says otherwise. Each brand folder, the default one included, may hold a _shared folder beside its apps, whose files every app of the brand gets, under the files of the app.
chassis.build
brands and apps name the folders of source/ that the build reads and the folders of dist/ that it writes.
| Key | Type | Meaning |
|---|---|---|
brands | Array of strings | The brands to build. A brand needs no folder in source/: without one it gets the default files |
apps | Object | Each app, with the array of platforms it is built for: web, ios, android |
chassis.optimize
optimize holds the settings of --optimize, --webp and --avif. The block is optional, each key is optional, and it turns nothing on: only the options do. A block that is not valid fails a build with one of the three options, before the output is removed.
{
"chassis": {
"optimize": {
"types": ["images"],
"png": { "quality": null },
"jpeg": { "quality": null },
"svg": { "precision": null },
"webp": { "quality": 80, "lossless": true },
"avif": { "quality": 60, "lossless": false }
}
}
}These are the values without a block.
| Key | Type | Meaning |
|---|---|---|
types | Array of strings | The type folders whose files are optimized and written in a second format. Add "icons" for the icons of a brand of your own |
png.quality | 1 to 100, or null | null compresses a PNG again and keeps every pixel. A number reduces its colors to a palette, which is smaller and not the same image |
jpeg.quality | 1 to 100, or null | null leaves a JPEG as it is. A number encodes it again at that quality |
svg | Object, or false | false leaves an SVG as it is |
svg.precision | 0 to 8, or null | null keeps the shapes. A number rounds the coordinates to that many decimals and rewrites the paths, which is much smaller and changes pixels at the edge of a shape |
webp.lossless, avif.lossless | Boolean | Whether the format of a PNG is written without a loss. A JPEG is always written with quality |
webp.quality, avif.quality | 1 to 100 | The quality of the format of a JPEG, and of a PNG without lossless |
The settings are in package.json and not in options of the command, so that every build of a commit writes the same files. There is no setting for a single file: to choose the bytes of one image, commit that image as the designer exported it, in the format it is wanted in.
chassis.subset
subset holds the settings of --subset: the ranges, the axes that are fixed, and whether a font is split by range. The block is optional, and it turns nothing on: only the option does. A block that is not valid fails a build with the option, before the output is removed.
{
"chassis": {
"subset": {
"ranges": ["latin", "latin-ext"],
"axes": {
"acme": { "opsz": 14 }
},
"split": true
}
}
}ranges is an array of the names and the code point ranges that Font subsets describes, and every font of a web job gets the same ranges. Without it the ranges are latin and latin-ext.
axes names, for a brand, the axes of a variable font to fix and the value of each. A key is a brand of chassis.build.brands, and a key under it is the tag of an axis as the font names it, such as opsz or wdth. The build fixes an axis in every font of the web output of the brand that has it, and writes a font without it as it would without the setting. Without axes no axis is fixed.
A value outside the axis of a font fails the build, which names the file and the values the axis spans. An axis that no font of the brand has is a warning.
split is true or false. With true, a font that a stylesheet declares is written once per range too, and the stylesheet gets a rule per range, as Font subsets describes. Without it a font is one file. The --split and --no-split options of a build win over it.
chassis.ignore
ignore lists names of files and folders that the build leaves out, beside the ones of Ignored files. The list is optional, and without it the build ignores what it always did.
{
"chassis": {
"ignore": ["*.bak", "notes.md", "drafts"]
}
}A pattern is a name, not a path: it matches a file or a folder of that name at any depth, in every brand and every app. * stands for any run of characters, and the match is case-sensitive. A folder that matches is left out with everything in it. A pattern with a slash fails the build.
The list adds to the names the build ignores and takes none away. The source lint, the validator, the analyzer, chassis-assets lfs and --watch read the same list, so a file you ignore is no file for them either.
chassis.formats
formats names, for a platform and a type folder, the extensions the platform keeps of that type. The block is optional. Use it when your application needs a format that the platform rules leave out, such as TTF fonts on the web or WebP images on iOS.
{
"chassis": {
"formats": {
"web": {
"fonts": [".woff2", ".ttf", ".css", ".txt"]
},
"ios": {
"images": [".png", ".jpg", ".webp"]
}
}
}
}A key is a platform, and a key under it is fonts, images or icons, the type folders that have a rule. Any other folder is copied in every format, and has no setting. An extension is written with its dot, and its case does not matter.
A list replaces the rule of the platform for the type, it does not add to it. Name every format you want to keep: .txt for the licenses of the fonts, .css and .scss for their stylesheets. A platform or a type that the block does not name keeps its rule, and an empty list keeps no file of the type.
The options of a build work on the files that are kept, each with the formats it reads. A TTF file that the web keeps is copied whole, since --subset writes WOFF and WOFF2 fonts only. The validator reads the block, and expects in the output the files that it keeps.
A block that is not valid fails the build before the output is removed, and names each problem: a platform without a processor, another folder than the three, or an extension without its dot.
Jobs
A job is one brand, one app and one platform. The build runs every brand for every platform of every app, and writes each job to dist/<platform>/<app>/<brand>/, the layout that Chassis Tokens uses too.
In the chassis block of package.json, two brands and two apps:
{
"chassis": {
"build": {
"brands": ["acme", "globex"],
"apps": {
"site": ["web"],
"mobile": ["ios", "android"]
}
}
}
}The build of this configuration writes these folders:
dist/web/site/acme/
dist/web/site/globex/
dist/ios/mobile/acme/
dist/ios/mobile/globex/
dist/android/mobile/acme/
dist/android/mobile/globex/Platform rules
Each platform has a processor that says which formats it keeps and how a file is named. The rules of a type apply to the files of its folder, fonts/, images/ or icons/, and any other folder is copied in every format. The formats of the table are the rules without a chassis.formats block, which replaces the formats of a platform for a type.
| Rule | Web | iOS | Android |
|---|---|---|---|
| Names | kebab-case | snake_case | snake_case |
Indicator @2x, @3x | Kept in the name | Kept in the name | Removed from the name |
fonts/ | WOFF, WOFF2, CSS, SCSS, TXT | TTF, OTF, TXT | TTF, OTF, TXT |
images/ | Every format | Every format but WebP. An asset catalog with --asset-catalog | Every format, in density folders. In res/ with --res |
icons/ | Every format | SVG, PDF, PNG | SVG, with the ic_ prefix. Vector drawables with --vector-drawables |
| Subfolders | Kept | Kept | Kept, with the density folders inside each |
The pages of the fonts, the images and the icons show the output of each type.
Renaming
A name is lowercased, and every space, underscore, dot inside the name or other character becomes the separator of the platform: a hyphen for the web, an underscore for iOS and Android. Hero Banner@2x.png is hero-banner@2x.png for the web and hero_banner@2x.png for iOS.
When two files of a folder get the same name on a platform, the file copied last wins, and the build warns with Filename collision: "<name>" → "<new name>" (conflicts with "<other name>"). A brand file over the default file of the same name is the override, not a collision. Names that keep the rules of the design guidelines do not collide.
Ignored files
The build does not copy the files that an operating system or an editor leaves behind: .DS_Store, Thumbs.db, desktop.ini, .gitkeep, and names that match ._*, *~, *.swp, *.tmp or *.temp. It removes a folder that is empty after the format rules. A name that starts with a dot is left out too. To leave out more names, list them in chassis.ignore.
Checks
The checks read source/ or an existing output and change nothing. Each exits with 1 when it fails, so a script or a CI job stops there.
Validator
chassis-assets validate checks an existing output against the source and the configuration. Run it after a full build.
npx chassis-assets build
npx chassis-assets validateIt checks that the output and the source exist, that every job has its folder and the type folders of its source, that every source file is there under the name of the platform, that the output has no fewer files than the source and no empty folder, and that the names keep the rules of the platform. --out <dir> reads another folder than dist/.
Contract check
A contract is a list of files that a consumer reads by name from the output of one job. chassis-assets contract checks the contracts of chassis.checks.json, and names each missing file and its reader.
npx chassis-assets contract
npx chassis-assets verifychassis-assets verify runs the validator and then the contract check. A repository without contracts has nothing to check, and the command is the validator alone.
Source lint
chassis-assets lint-source checks source/ against the naming rules of the design guidelines.
It fails on a name or a folder that is not of lowercase letters, digits and hyphens, on an indicator that is not at the end of a name, on an extension with capitals, on a file outside a type folder, and on a Git LFS pointer in place of a file. It warns about a brand or an app folder that the configuration does not name, which the build does not read.
The message suggests a name that keeps the rules. A file that breaks a rule on purpose is listed in lint.allow of the checks file with the reason, and is printed as a warning.
The lint also reads the fonts. For each @font-face rule of a stylesheet in fonts/, it opens the file the rule declares and compares the two, as a brand gets them, with its own files over those of the default brand and the files of an app over those of its _shared folder. It fails when the file is of another family than the rule names, when its weight is not the weight of the rule or its weight axis does not hold the range of the rule, when one is italic and the other is not, and when the rule declares a file that is not in the folder. A rule that loads a font from a service is not read.
A rule declares the file of the web, and the apps get the file of the same name in another format, which no rule declares. The lint checks a rule against those files too: a rule for ui.woff2 is also the rule of ui.ttf in the same folder, and of an .otf or a .woff file of that name. It also fails when two files of one name are not one font in two formats, and names both files with what differs: the family, the weight, the style, the axes, the version or the number of glyphs.
It warns about a font of the default brand that a brand gets beside a family of its own, where no stylesheet of the brand declares the family of that font. The file is in the output of the brand, and nothing loads it. It also warns about a format() of a rule that is not the format of its file.
For an app with Android, the lint reads the images and the icons of each brand as --res with --vector-drawables would place them. The res/ folder has no subfolders, so images/badge.png and images/onboarding/badge@2x.png are both the resource badge, and --res keeps the file of the folder nearest to images/. The lint warns about the other file, with the jobs it is left out of, so that one of the two is renamed before an app misses it.
Analyzer
chassis-assets analyze reports on source/ and on an existing output: the file types, the files per platform, brand and app, the largest files, and the files with the same content. It takes the filters of the build.
npx chassis-assets analyze
npx chassis-assets analyze --brand acme --platform webFiles with the same content are listed per group, for the source and for the output apart. An app that holds a copy of the files of another app shows up there.
Checks file
What the checks verify is in chassis.checks.json, beside package.json. The build does not read it. The file is optional: without it there is no contract to check and no name that the source lint keeps.
contracts
contracts holds, for a job written as <platform>/<app>/<brand>, the files that a consumer reads by name from its output.
| Key | Type | Meaning |
|---|---|---|
reader | String | Who reads the files, printed when one is missing |
files | Array of strings | Paths that have to be there, relative to the output of the job. {a,b} stands for each alternative |
sets | Array | Patterns of files that are read together, with * and {a,b}. When the output has a file that matches, it has to have that file with every other alternative too. An entry is a pattern, or an object with pattern and except, a list of patterns to leave out |
In chassis.checks.json, a contract with a list of files and a set:
{
"contracts": {
"web/site/acme": [
{
"reader": "the layout of the site",
"files": ["fonts/fonts.css", "images/logo/wordmark.svg"]
},
{
"reader": "the gallery of the site",
"sets": ["images/gallery/*/{light,dark}/*{,@2x}.png"]
}
]
}
}The set says that every image of the gallery is there in the light and in the dark mode, each at the base size and at @2x.
lint.allow
lint.allow lists the files of source/ that break a naming rule and are kept. The source lint prints a warning for them instead of an error.
| Key | Type | Meaning |
|---|---|---|
pattern | String | The path of the file, relative to source/, with * for one folder |
reason | String | Why the name is kept, printed with the warning |
In chassis.checks.json, the entry of a file whose name a tool chose:
{
"lint": {
"allow": [
{
"pattern": "*/*/data/brand.tokens.json",
"reason": "the name the tokens export writes, read by name"
}
]
}
}Custom platforms
A platform is a processor: a module of lib/build/processors/ of the package with the formats the platform keeps and a function that names a file. The package loads no processor from outside itself, so a fourth platform is a change to the package: a pull request to its repository, or a fork of it that adds the module to the registry of lib/build/processors/index.js and names the platform in an app of the chassis block.
A processor has allowedFontFormats, allowedIconFormats and excludedImageFormats, and renameFile(fileName). It may place an image itself with processImage(), as the Android processor does for the density folders, with imageFolder(fileName) for the folder the image goes to. The options of the build each ask a processor for a property: vectorDrawables, assetCatalog, res, imageFormats and subset, as the modules of the three platforms show.
Library
The commands are thin entries over modules that a script can import. An imported function takes its options as an object, never reads the command line, and throws where the command would exit.
Import them from the package, installed in the repository of assets or beside it. This script builds one job into a folder of its own and reads the result:
import ChassisAssets from '@chassis-ui/assets'
import AssetAnalyzer from '@chassis-ui/assets/lib/commands/analyze-assets.js'
import { generateAssets } from '@chassis-ui/assets/lib/build/build-assets.js'
// The root of the repository of assets: where package.json and source/ are
const cwd = new URL('./', import.meta.url).pathname
// The build, with the options of the command line. Throws on an unknown brand
const result = await generateAssets({
brands: ['acme'],
apps: ['site'],
platforms: ['web'],
cwd,
out: 'dist',
quiet: true
})
console.log(result.filesProcessed, result.jobs)
// The configuration as an object
const assets = new ChassisAssets('package.json', { cwd })
console.log(assets.getBrands(), assets.getCombinations())
// The analyzer. analyze() is synchronous
const analyzer = new AssetAnalyzer({ brands: ['acme'], platforms: ['web'], cwd, quiet: true })
analyzer.analyze()
console.log(analyzer.stats.totalFiles, analyzer.stats.duplicatesInSource.length)generateAssets
generateAssets(options) of build-assets.js is the build. It resolves to the statistics of the run, with filesProcessed, filesRenamed, filesConverted, imageSets, resourceFiles, filesOptimized, bytesSaved, filesGenerated, fontsSubsetted, fontBytesSaved, fontAxesFixed, fontRangeFiles, warnings and jobs, and throws on a failure. Its options are brands, apps, platforms, types, include, clean, quiet, cwd, out, dryRun, allowLfsPointers, vectorDrawables, assetCatalog, res, optimize, webp, avif, subset and split.
ChassisAssets
new ChassisAssets(configPath, { cwd, out }) of api/index.js reads the configuration of package.json in cwd.
| Method | Returns |
|---|---|
getBrands() | The configured brands |
getApps() | The names of the configured apps |
getPlatforms(app) | The platforms of one app |
getAllPlatforms() | Every platform that an app names |
getCombinations() | Every job, as brand, app and platform |
assetsExist(brand, app) | Whether the source has files for the brand and the app |
getAssetInventory(brand, app) | The source files of the brand and the app, by type |
build(options) | The result of generateAssets() with brands, apps, platforms, types, include, clean, quiet, vectorDrawables, assetCatalog, res, optimize, webp, avif and subset |
getStats() | The numbers of brands, apps, jobs, source files and output files |
validate() | The errors and the warnings of the configuration and the source |
AssetAnalyzer
new AssetAnalyzer({ brands, apps, platforms, quiet, cwd, out }) of analyze-assets.js takes the filters and the folders. analyze() fills stats: totalFiles, totalSize, fileTypes, platforms, brands, apps, largestFiles, duplicatesInSource and duplicatesInDist. formatBytes(bytes) formats a size for reading.
Releases
A release of a repository of assets is one archive per job, <name>-<platform>-<app>-<brand>-<version>.zip, with the content of dist/<platform>/<app>/<brand>/ at its top level. chassis-assets archive writes them from an existing output, with the name and the version of package.json, into archives/.
npx chassis-assets build --optimize
npx chassis-assets archive
npx chassis-assets archive --to /tmp/release --prefix acme --release 1.2.0--to <dir> writes them elsewhere, and --prefix <name> and --release <version> name them instead of package.json; the archives of the prefix already in the folder are removed first. The archives are written with Node.js alone, and an archive holds up to 65,535 files.
The release workflow that chassis-assets init writes runs on a push to main, and does nothing when the version of package.json already has a tag v<version>. For a new version, it reads the entry of the version with chassis-assets release-notes, and stops when CHANGELOG.md has none. It builds every job with the build:release script, which adds --asset-catalog and --icon-catalog, verifies them, writes the archives and the manifest, and creates the tag and the GitHub release with them attached and the entry as its body. A version with a prerelease part, such as 0.2.0-next.0, is marked as a prerelease.
chassis-assets manifest writes <name>-manifest-<version>.json, the size and the SHA-256 of every file by job. dist/ is not committed, so the manifest of a release is what the next version compares against, and it names the version of the package that built it. After a build of the same kind, chassis-assets diff reports what the changelog entry has to name, in Markdown:
gh release download v1.1.0 --pattern '*-manifest-*' --dir /tmp/base
npm run build:release
npx chassis-assets diff --base /tmp/base/acme-assets-manifest-1.1.0.jsonContinuous integration
A CI job builds the output it needs and checks it. Every download of a Git LFS file counts against the Git LFS bandwidth of the owner of the repository, so the checkout leaves pointers, a cache keyed by the ids of the objects keeps them between runs, and git lfs pull downloads only the objects that changed. The pull passes the token of the run for that command only, since the checkout keeps no credentials. The install brings the package and nothing else. chassis-assets init writes this workflow, for npm or for pnpm, with the actions pinned to a commit:
name: CI
on:
push:
branches: [main]
pull_request:
permissions:
contents: read
jobs:
assets:
name: Assets
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v7
with:
persist-credentials: false
- name: List the Git LFS objects
run: git lfs ls-files --long | cut -d ' ' -f1 | sort > .lfs-ids
- name: Cache the Git LFS objects
uses: actions/cache@v6
with:
path: .git/lfs
key: lfs-${{ hashFiles('.lfs-ids') }}
restore-keys: lfs-
- name: Pull the Git LFS objects
env:
TOKEN: ${{ github.token }}
run: |
rm .lfs-ids
AUTH=$(printf 'x-access-token:%s' "$TOKEN" | base64 | tr -d '\n')
git -c "http.$GITHUB_SERVER_URL/.extraheader=AUTHORIZATION: basic $AUTH" lfs pull
- name: Setup Node.js
uses: actions/setup-node@v7
with:
node-version-file: .nvmrc
cache: npm
- name: Install
run: npm ci
- name: Check the changelog
run: npm run release-notes
- name: Lint source
run: npm run lint
- name: Build
run: npm run build
- name: Verify
run: npm run verifyNative checks
A file that the source lint, the build and the validator pass can still fail when an app compiles it. chassis-assets check-native compiles an existing output as an app does: the asset catalogs and the .icon bundles of iOS with actool, which needs Xcode, and the res/ folders of Android with aapt2, which needs the Android SDK in ANDROID_HOME. --platform ios or --platform android picks one, and without it the check takes the platforms with a folder in the output.
For a repository with iOS or Android, chassis-assets init writes .github/workflows/native.yml, with a build job and one job per platform. It runs when source/, chassis.checks.json, package.json or the lockfile changes. The build job pulls the Git LFS files as CI does and builds with build:release, and each platform job downloads that output, with no Git LFS file, and compiles it. The iOS job needs a macOS runner, whose minutes cost more on a private repository: remove the job when that is not worth it. For Android, build:release adds --res --vector-drawables, and init adds svg2vectordrawable as a development dependency.
To build one platform per job, give each job a filter, such as chassis-assets build --platform ios, and keep its folder, dist/ios/. A job that needs the names and not the binaries, such as the source lint alone, can skip the Git LFS files and pass --allow-lfs-pointers.
Best practices
These practices keep a build short while you work, and keep the paths of the output stable for the consumers.
- Build a part while you work:
chassis-assets build --brand acme --platform webwrites one job and keeps the rest ofdist/. - Run a full build before the checks:
chassis-assets validateandchassis-assets verifyexpect the output of every job. - Start with the default brand: put the files that every brand shares in
source/_default/<app>/, and add to a brand folder only what is its own. A file that every app of a brand uses goes in its_shared/folder, once. - Keep brand and app names in lowercase with hyphens: they are folder names in
source/and indist/, and a consumer reads its files by that path. A name that starts with_is no brand and no app, and the build fails on it.
Avoid the habits that undo this:
- Do not commit
dist/: every consumer builds it from the source. - Do not rename a brand or an app without telling the consumers: the name is part of every path of its output.
Troubleshooting
Each entry gives the message or the symptom, then the cause and the fix.
Build fails on pointers
The build stops with <count> source file(s) are Git LFS pointers, not files: <files>. The clone has no Git LFS files, so a font or an image is a pointer of a few lines. Install Git LFS, run git lfs pull, and build again. Pass --allow-lfs-pointers only where the binaries are not needed. With --type or --include, fetch the files of the filters only, see File filters.
Unknown brand
The build stops with Unknown brand "<name>". Configured: <names>, or the same for an app or a platform. A filter has a value that the chassis block does not name. Use a name of the list.
No job selected
The build stops with The filters select no job. Check --brand, --app and --platform together. Each value is configured, and no app has that platform. Run chassis-assets build --dry-run to see the jobs.
Validator misses files
chassis-assets validate fails after a filtered build and names the folders or the files of other jobs. The validator checks every job of the configuration. Run chassis-assets build without filters, then validate.
Next steps
Continue with one of these pages:
- Design guidelines: the naming rules that the source lint checks.
- Fonts, images, icons and other assets: the rules of each type.
- Architecture: the modules of the build, its tests and the output contract.