## Description This improves defaults generation with logging, stats, and token validation. This PR includes these changes: * introduce `TokenLogger`, with a verbose mode * prints versions and tokens usage to the console * outputs `generated/used_tokens.csv`, a list of all used tokens, for use by Google * find token files in `data` automatically * hide tokens `Map` * tokens can be obtained using existing resolvers (e.g. `color`, `shape`), or directly through `getToken`. * tokens can be checked for existence with `tokenAvailable` * remove version from template, since the tokens are aggregated and multiple versions are possible (as is the case currently), it does not make sense to attribute a single version * improve documentation ## Related Issues - Fixes https://github.com/flutter/flutter/issues/122602 ## Tests - Added tests for `TokenLogger` - Regenerated tokens, no-op except version removal ## Future work A future PR should replace or remove the following invalid tokens usages <img width="578" alt="image" src="https://github.com/flutter/flutter/assets/6655696/b6f9e5a7-523f-4f72-94f9-1b0bf4cc9f00">
1.2 KiB
Token Defaults Generator
Script that generates component theme data defaults based on token data.
Usage
Run this program from the root of the git repository:
dart dev/tools/gen_defaults/bin/gen_defaults.dart [-v]
This updates generated/used_tokens.csv and the various component theme files.
Templates
There is a template file for every component that needs defaults from
the token database. These templates are implemented as subclasses of
TokenTemplate. This base class provides some utilities and a structure
for adding a new block of generated code to the bottom of a given file.
Templates need to override the generate method to provide the generated
code block as a string.
See lib/fab_template.dart for an example that generates defaults for the
Floating Action Button.
Tokens
Tokens are stored in JSON files in data/, and are sourced from
an internal Google database.
template.dart should provide nearly all useful token resolvers
(e.g. color, shape, etc.). For special cases in which one shouldn't
be defined, use getToken to get the raw token value. The script, through
the various revolvers and getToken, validates tokens, keeps track of
which tokens are used, and generates generated/used_tokens.csv.