Auto-format Framework (#160545)
This auto-formats all *.dart files in the repository outside of the `engine` subdirectory and enforces that these files stay formatted with a presubmit check. **Reviewers:** Please carefully review all the commits except for the one titled "formatted". The "formatted" commit was auto-generated by running `dev/tools/format.sh -a -f`. The other commits were hand-crafted to prepare the repo for the formatting change. I recommend reviewing the commits one-by-one via the "Commits" tab and avoiding Github's "Files changed" tab as it will likely slow down your browser because of the size of this PR. --------- Co-authored-by: Kate Lovett <katelovett@google.com> Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
8e0993eda8
commit
5491c8c146
@@ -67,12 +67,7 @@ const String dataDir = 'dev/tools/gen_defaults/data';
|
||||
Future<void> main(List<String> args) async {
|
||||
// Parse arguments
|
||||
final ArgParser parser = ArgParser();
|
||||
parser.addFlag(
|
||||
'verbose',
|
||||
abbr: 'v',
|
||||
help: 'Enable verbose output',
|
||||
negatable: false,
|
||||
);
|
||||
parser.addFlag('verbose', abbr: 'v', help: 'Enable verbose output', negatable: false);
|
||||
final ArgResults argResults = parser.parse(args);
|
||||
final bool verbose = argResults['verbose'] as bool;
|
||||
|
||||
@@ -96,6 +91,8 @@ Future<void> main(List<String> args) async {
|
||||
final Map<String, dynamic> colorLightTokens = _readTokenFile(File('$dataDir/color_light.json'));
|
||||
final Map<String, dynamic> colorDarkTokens = _readTokenFile(File('$dataDir/color_dark.json'));
|
||||
|
||||
// The verifyTokenTemplatesUpdateCorrectFiles check in dev/bots/analyze.dart depends on the exact formatting of the next few lines.
|
||||
// dart format off
|
||||
// Generate tokens files.
|
||||
ChipTemplate('Chip', '$materialLib/chip.dart', tokens).updateFile();
|
||||
ActionChipTemplate('ActionChip', '$materialLib/action_chip.dart', tokens).updateFile();
|
||||
@@ -150,6 +147,7 @@ Future<void> main(List<String> args) async {
|
||||
TextFieldTemplate('TextField', '$materialLib/text_field.dart', tokens).updateFile();
|
||||
TabsTemplate('Tabs', '$materialLib/tabs.dart', tokens).updateFile();
|
||||
TypographyTemplate('Typography', '$materialLib/typography.dart', tokens).updateFile();
|
||||
// dart format on
|
||||
|
||||
tokenLogger.printVersionUsage(verbose: verbose);
|
||||
tokenLogger.printTokensUsage(verbose: verbose);
|
||||
|
||||
@@ -5,9 +5,12 @@
|
||||
import 'template.dart';
|
||||
|
||||
class ActionChipTemplate extends TokenTemplate {
|
||||
const ActionChipTemplate(super.blockName, super.fileName, super.tokens, {
|
||||
const ActionChipTemplate(
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
super.textThemePrefix = '_textTheme.'
|
||||
super.textThemePrefix = '_textTheme.',
|
||||
});
|
||||
|
||||
static const String tokenGroup = 'md.comp.assist-chip';
|
||||
|
||||
@@ -6,10 +6,7 @@ import 'template.dart';
|
||||
|
||||
class AppBarTemplate extends TokenTemplate {
|
||||
const AppBarTemplate(super.blockName, super.fileName, super.tokens)
|
||||
: super(
|
||||
colorSchemePrefix: '_colors.',
|
||||
textThemePrefix: '_textTheme.',
|
||||
);
|
||||
: super(colorSchemePrefix: '_colors.', textThemePrefix: '_textTheme.');
|
||||
|
||||
@override
|
||||
String generate() => '''
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
import 'template.dart';
|
||||
|
||||
class BadgeTemplate extends TokenTemplate {
|
||||
const BadgeTemplate(super.blockName, super.fileName, super.tokens, {
|
||||
const BadgeTemplate(
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
});
|
||||
|
||||
|
||||
@@ -5,9 +5,12 @@
|
||||
import 'template.dart';
|
||||
|
||||
class BannerTemplate extends TokenTemplate {
|
||||
const BannerTemplate(super.blockName, super.fileName, super.tokens, {
|
||||
const BannerTemplate(
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
super.textThemePrefix = '_textTheme.'
|
||||
super.textThemePrefix = '_textTheme.',
|
||||
});
|
||||
|
||||
@override
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
import 'template.dart';
|
||||
|
||||
class BottomAppBarTemplate extends TokenTemplate {
|
||||
const BottomAppBarTemplate(super.blockName, super.fileName, super.tokens, {
|
||||
const BottomAppBarTemplate(
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
});
|
||||
|
||||
|
||||
@@ -5,7 +5,11 @@
|
||||
import 'template.dart';
|
||||
|
||||
class ButtonTemplate extends TokenTemplate {
|
||||
const ButtonTemplate(this.tokenGroup, super.blockName, super.fileName, super.tokens, {
|
||||
const ButtonTemplate(
|
||||
this.tokenGroup,
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
});
|
||||
|
||||
|
||||
@@ -5,7 +5,11 @@
|
||||
import 'template.dart';
|
||||
|
||||
class CardTemplate extends TokenTemplate {
|
||||
const CardTemplate(this.tokenGroup, super.blockName, super.fileName, super.tokens, {
|
||||
const CardTemplate(
|
||||
this.tokenGroup,
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
});
|
||||
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
import 'template.dart';
|
||||
|
||||
class CheckboxTemplate extends TokenTemplate {
|
||||
const CheckboxTemplate(super.blockName, super.fileName, super.tokens, {
|
||||
const CheckboxTemplate(
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
});
|
||||
|
||||
|
||||
@@ -5,9 +5,12 @@
|
||||
import 'template.dart';
|
||||
|
||||
class ChipTemplate extends TokenTemplate {
|
||||
const ChipTemplate(super.blockName, super.fileName, super.tokens, {
|
||||
const ChipTemplate(
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
super.textThemePrefix = '_textTheme.'
|
||||
super.textThemePrefix = '_textTheme.',
|
||||
});
|
||||
|
||||
static const String tokenGroup = 'md.comp.filter-chip';
|
||||
|
||||
@@ -6,7 +6,13 @@ import 'template.dart';
|
||||
import 'token_logger.dart';
|
||||
|
||||
class ColorSchemeTemplate extends TokenTemplate {
|
||||
ColorSchemeTemplate(this._colorTokensLight, this._colorTokensDark, super.blockName, super.fileName, super.tokens);
|
||||
ColorSchemeTemplate(
|
||||
this._colorTokensLight,
|
||||
this._colorTokensDark,
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens,
|
||||
);
|
||||
|
||||
// Map of light color scheme token data from tokens.
|
||||
final Map<String, dynamic> _colorTokensLight;
|
||||
|
||||
@@ -5,9 +5,12 @@
|
||||
import 'template.dart';
|
||||
|
||||
class DatePickerTemplate extends TokenTemplate {
|
||||
const DatePickerTemplate(super.blockName, super.fileName, super.tokens, {
|
||||
const DatePickerTemplate(
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
super.textThemePrefix = '_textTheme.'
|
||||
super.textThemePrefix = '_textTheme.',
|
||||
});
|
||||
|
||||
String _layerOpacity(String layerToken) {
|
||||
@@ -26,9 +29,9 @@ class DatePickerTemplate extends TokenTemplate {
|
||||
String _stateColor(String componentToken, String? type, String state) {
|
||||
final String baseColor = color(
|
||||
type != null
|
||||
? '$componentToken.$type.$state.state-layer.color'
|
||||
: '$componentToken.$state.state-layer.color',
|
||||
''
|
||||
? '$componentToken.$type.$state.state-layer.color'
|
||||
: '$componentToken.$state.state-layer.color',
|
||||
'',
|
||||
);
|
||||
if (baseColor.isEmpty) {
|
||||
return 'null';
|
||||
|
||||
@@ -5,9 +5,12 @@
|
||||
import 'template.dart';
|
||||
|
||||
class DialogTemplate extends TokenTemplate {
|
||||
const DialogTemplate(super.blockName, super.fileName, super.tokens, {
|
||||
const DialogTemplate(
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
super.textThemePrefix = '_textTheme.'
|
||||
super.textThemePrefix = '_textTheme.',
|
||||
});
|
||||
|
||||
@override
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
import 'template.dart';
|
||||
|
||||
class ExpansionTileTemplate extends TokenTemplate {
|
||||
const ExpansionTileTemplate(super.blockName, super.fileName, super.tokens, {
|
||||
const ExpansionTileTemplate(
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
});
|
||||
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
import 'template.dart';
|
||||
|
||||
class FABTemplate extends TokenTemplate {
|
||||
const FABTemplate(super.blockName, super.fileName, super.tokens, {
|
||||
const FABTemplate(
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
super.textThemePrefix = '_textTheme.',
|
||||
});
|
||||
|
||||
@@ -5,9 +5,12 @@
|
||||
import 'template.dart';
|
||||
|
||||
class FilterChipTemplate extends TokenTemplate {
|
||||
const FilterChipTemplate(super.blockName, super.fileName, super.tokens, {
|
||||
const FilterChipTemplate(
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
super.textThemePrefix = '_textTheme.'
|
||||
super.textThemePrefix = '_textTheme.',
|
||||
});
|
||||
|
||||
static const String tokenGroup = 'md.comp.filter-chip';
|
||||
|
||||
@@ -5,7 +5,11 @@
|
||||
import 'template.dart';
|
||||
|
||||
class IconButtonTemplate extends TokenTemplate {
|
||||
const IconButtonTemplate(this.tokenGroup, super.blockName, super.fileName, super.tokens, {
|
||||
const IconButtonTemplate(
|
||||
this.tokenGroup,
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
});
|
||||
|
||||
@@ -185,7 +189,8 @@ class IconButtonTemplate extends TokenTemplate {
|
||||
}
|
||||
|
||||
String _minimumSize() {
|
||||
if (tokenAvailable('$tokenGroup.container.height') && tokenAvailable('$tokenGroup.container.width')) {
|
||||
if (tokenAvailable('$tokenGroup.container.height') &&
|
||||
tokenAvailable('$tokenGroup.container.width')) {
|
||||
return '''
|
||||
|
||||
const MaterialStatePropertyAll<Size>(Size(${getToken('$tokenGroup.container.width')}, ${getToken('$tokenGroup.container.height')}))''';
|
||||
@@ -313,5 +318,4 @@ class _${blockName}DefaultsM3 extends ButtonStyle {
|
||||
InteractiveInkFeatureFactory? get splashFactory => Theme.of(context).splashFactory;
|
||||
}
|
||||
''';
|
||||
|
||||
}
|
||||
|
||||
@@ -5,9 +5,12 @@
|
||||
import 'template.dart';
|
||||
|
||||
class InputChipTemplate extends TokenTemplate {
|
||||
const InputChipTemplate(super.blockName, super.fileName, super.tokens, {
|
||||
const InputChipTemplate(
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
super.textThemePrefix = '_textTheme.'
|
||||
super.textThemePrefix = '_textTheme.',
|
||||
});
|
||||
|
||||
static const String tokenGroup = 'md.comp.input-chip';
|
||||
|
||||
@@ -5,9 +5,12 @@
|
||||
import 'template.dart';
|
||||
|
||||
class InputDecoratorTemplate extends TokenTemplate {
|
||||
const InputDecoratorTemplate(super.blockName, super.fileName, super.tokens, {
|
||||
const InputDecoratorTemplate(
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
super.textThemePrefix = '_textTheme.'
|
||||
super.textThemePrefix = '_textTheme.',
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -54,7 +57,7 @@ class _${blockName}DefaultsM3 extends InputDecorationTheme {
|
||||
}
|
||||
if (states.contains(MaterialState.error)) {
|
||||
if (states.contains(MaterialState.focused)) {
|
||||
return ${mergedBorder('md.comp.filled-text-field.error.focus.active-indicator','md.comp.filled-text-field.focus.active-indicator')};
|
||||
return ${mergedBorder('md.comp.filled-text-field.error.focus.active-indicator', 'md.comp.filled-text-field.focus.active-indicator')};
|
||||
}
|
||||
if (states.contains(MaterialState.hovered)) {
|
||||
return ${border('md.comp.filled-text-field.error.hover.active-indicator')};
|
||||
@@ -77,7 +80,7 @@ class _${blockName}DefaultsM3 extends InputDecorationTheme {
|
||||
}
|
||||
if (states.contains(MaterialState.error)) {
|
||||
if (states.contains(MaterialState.focused)) {
|
||||
return ${mergedBorder('md.comp.outlined-text-field.error.focus.outline','md.comp.outlined-text-field.focus.outline')};
|
||||
return ${mergedBorder('md.comp.outlined-text-field.error.focus.outline', 'md.comp.outlined-text-field.focus.outline')};
|
||||
}
|
||||
if (states.contains(MaterialState.hovered)) {
|
||||
return ${border('md.comp.outlined-text-field.error.hover.outline')};
|
||||
@@ -221,15 +224,17 @@ class _${blockName}DefaultsM3 extends InputDecorationTheme {
|
||||
|
||||
/// Generate a [BorderSide] for the given components.
|
||||
String mergedBorder(String componentToken1, String componentToken2) {
|
||||
final String borderColor = componentColor(componentToken1)!= 'null'
|
||||
? componentColor(componentToken1)
|
||||
: componentColor(componentToken2);
|
||||
final double width = (
|
||||
getToken('$componentToken1.width', optional: true) ??
|
||||
getToken('$componentToken1.height', optional: true) ??
|
||||
getToken('$componentToken2.width', optional: true) ??
|
||||
getToken('$componentToken2.height', optional: true) ??
|
||||
1.0) as double;
|
||||
final String borderColor =
|
||||
componentColor(componentToken1) != 'null'
|
||||
? componentColor(componentToken1)
|
||||
: componentColor(componentToken2);
|
||||
final double width =
|
||||
(getToken('$componentToken1.width', optional: true) ??
|
||||
getToken('$componentToken1.height', optional: true) ??
|
||||
getToken('$componentToken2.width', optional: true) ??
|
||||
getToken('$componentToken2.height', optional: true) ??
|
||||
1.0)
|
||||
as double;
|
||||
return 'BorderSide(color: $borderColor${width != 1.0 ? ", width: $width" : ""})';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
import 'template.dart';
|
||||
|
||||
class ListTileTemplate extends TokenTemplate {
|
||||
const ListTileTemplate(super.blockName, super.fileName, super.tokens, {
|
||||
const ListTileTemplate(
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
super.textThemePrefix = '_textTheme.',
|
||||
});
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
import 'template.dart';
|
||||
|
||||
class MenuTemplate extends TokenTemplate {
|
||||
const MenuTemplate(super.blockName, super.fileName, super.tokens, {
|
||||
const MenuTemplate(
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
});
|
||||
|
||||
@@ -247,10 +250,7 @@ class _MenuDefaultsM3 extends MenuStyle {
|
||||
|
||||
@override
|
||||
MaterialStateProperty<Color?>? get surfaceTintColor {
|
||||
return ${componentColor('md.comp.menu.container.surface-tint-layer') == 'null'
|
||||
? 'const MaterialStatePropertyAll<Color?>(Colors.transparent)'
|
||||
: 'MaterialStatePropertyAll<Color?>(${componentColor('md.comp.menu.container.surface-tint-layer')})'
|
||||
};
|
||||
return ${componentColor('md.comp.menu.container.surface-tint-layer') == 'null' ? 'const MaterialStatePropertyAll<Color?>(Colors.transparent)' : 'MaterialStatePropertyAll<Color?>(${componentColor('md.comp.menu.container.surface-tint-layer')})'};
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -8,33 +8,37 @@ import 'token_logger.dart';
|
||||
class MotionTemplate extends TokenTemplate {
|
||||
/// Since we generate the tokens dynamically, we need to store them and log
|
||||
/// them manually, instead of using [getToken].
|
||||
MotionTemplate(String blockName, String fileName, this.tokens, this.tokensLogger) : super(blockName, fileName, tokens);
|
||||
MotionTemplate(String blockName, String fileName, this.tokens, this.tokensLogger)
|
||||
: super(blockName, fileName, tokens);
|
||||
Map<String, dynamic> tokens;
|
||||
TokenLogger tokensLogger;
|
||||
|
||||
// List of duration tokens.
|
||||
late List<MapEntry<String, dynamic>> durationTokens = tokens.entries.where(
|
||||
(MapEntry<String, dynamic> entry) => entry.key.contains('.duration.')
|
||||
).toList()
|
||||
..sort(
|
||||
(MapEntry<String, dynamic> a, MapEntry<String, dynamic> b) => (a.value as double).compareTo(b.value as double)
|
||||
);
|
||||
late List<MapEntry<String, dynamic>> durationTokens =
|
||||
tokens.entries
|
||||
.where((MapEntry<String, dynamic> entry) => entry.key.contains('.duration.'))
|
||||
.toList()
|
||||
..sort(
|
||||
(MapEntry<String, dynamic> a, MapEntry<String, dynamic> b) =>
|
||||
(a.value as double).compareTo(b.value as double),
|
||||
);
|
||||
|
||||
// List of easing curve tokens.
|
||||
late List<MapEntry<String, dynamic>> easingCurveTokens = tokens.entries.where(
|
||||
(MapEntry<String, dynamic> entry) => entry.key.contains('.easing.')
|
||||
).toList()
|
||||
..sort(
|
||||
// Sort the legacy curves at the end of the list.
|
||||
(MapEntry<String, dynamic> a, MapEntry<String, dynamic> b) => a.key.contains('legacy') ? 1 : a.key.compareTo(b.key)
|
||||
);
|
||||
late List<MapEntry<String, dynamic>> easingCurveTokens =
|
||||
tokens.entries
|
||||
.where((MapEntry<String, dynamic> entry) => entry.key.contains('.easing.'))
|
||||
.toList()
|
||||
..sort(
|
||||
// Sort the legacy curves at the end of the list.
|
||||
(MapEntry<String, dynamic> a, MapEntry<String, dynamic> b) =>
|
||||
a.key.contains('legacy') ? 1 : a.key.compareTo(b.key),
|
||||
);
|
||||
|
||||
String durationTokenString(String token, dynamic tokenValue) {
|
||||
tokensLogger.log(token);
|
||||
final String tokenName = token.split('.').last.replaceAll('-', '').replaceFirst('Ms', '');
|
||||
final int milliseconds = (tokenValue as double).toInt();
|
||||
return
|
||||
'''
|
||||
return '''
|
||||
/// The $tokenName duration (${milliseconds}ms) in the Material specification.
|
||||
///
|
||||
/// See also:
|
||||
@@ -47,11 +51,12 @@ class MotionTemplate extends TokenTemplate {
|
||||
|
||||
String easingCurveTokenString(String token, dynamic tokenValue) {
|
||||
tokensLogger.log(token);
|
||||
final String tokenName = token
|
||||
.replaceFirst('md.sys.motion.easing.', '')
|
||||
.replaceAllMapped(RegExp(r'[-\.](\w)'), (Match match) {
|
||||
final String tokenName = token.replaceFirst('md.sys.motion.easing.', '').replaceAllMapped(
|
||||
RegExp(r'[-\.](\w)'),
|
||||
(Match match) {
|
||||
return match.group(1)!.toUpperCase();
|
||||
});
|
||||
},
|
||||
);
|
||||
return '''
|
||||
/// The $tokenName easing curve in the Material specification.
|
||||
///
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
import 'template.dart';
|
||||
|
||||
class NavigationBarTemplate extends TokenTemplate {
|
||||
const NavigationBarTemplate(super.blockName, super.fileName, super.tokens, {
|
||||
const NavigationBarTemplate(
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
super.textThemePrefix = '_textTheme.',
|
||||
});
|
||||
|
||||
@@ -5,9 +5,12 @@
|
||||
import 'template.dart';
|
||||
|
||||
class NavigationDrawerTemplate extends TokenTemplate {
|
||||
const NavigationDrawerTemplate(super.blockName, super.fileName, super.tokens, {
|
||||
const NavigationDrawerTemplate(
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
super.textThemePrefix = '_textTheme.'
|
||||
super.textThemePrefix = '_textTheme.',
|
||||
});
|
||||
|
||||
@override
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
import 'template.dart';
|
||||
|
||||
class NavigationRailTemplate extends TokenTemplate {
|
||||
const NavigationRailTemplate(super.blockName, super.fileName, super.tokens, {
|
||||
const NavigationRailTemplate(
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
super.textThemePrefix = '_textTheme.',
|
||||
});
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
import 'template.dart';
|
||||
|
||||
class PopupMenuTemplate extends TokenTemplate {
|
||||
const PopupMenuTemplate(super.blockName, super.fileName, super.tokens, {
|
||||
const PopupMenuTemplate(
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
super.textThemePrefix = '_textTheme.',
|
||||
});
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
import 'template.dart';
|
||||
|
||||
class ProgressIndicatorTemplate extends TokenTemplate {
|
||||
const ProgressIndicatorTemplate(super.blockName, super.fileName, super.tokens, {
|
||||
const ProgressIndicatorTemplate(
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
});
|
||||
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
import 'template.dart';
|
||||
|
||||
class RadioTemplate extends TokenTemplate {
|
||||
const RadioTemplate(super.blockName, super.fileName, super.tokens, {
|
||||
const RadioTemplate(
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
});
|
||||
|
||||
|
||||
@@ -5,13 +5,18 @@
|
||||
import 'template.dart';
|
||||
|
||||
class SearchBarTemplate extends TokenTemplate {
|
||||
const SearchBarTemplate(super.blockName, super.fileName, super.tokens, {
|
||||
const SearchBarTemplate(
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
super.textThemePrefix = '_textTheme.'
|
||||
super.textThemePrefix = '_textTheme.',
|
||||
});
|
||||
|
||||
String _surfaceTint() {
|
||||
final String? color = colorOrTransparent('md.comp.search-bar.container.surface-tint-layer.color');
|
||||
final String? color = colorOrTransparent(
|
||||
'md.comp.search-bar.container.surface-tint-layer.color',
|
||||
);
|
||||
final String surfaceTintColor = 'MaterialStatePropertyAll<Color>($color);';
|
||||
if (color == 'Colors.transparent') {
|
||||
return 'const $surfaceTintColor';
|
||||
|
||||
@@ -5,9 +5,12 @@
|
||||
import 'template.dart';
|
||||
|
||||
class SearchViewTemplate extends TokenTemplate {
|
||||
const SearchViewTemplate(super.blockName, super.fileName, super.tokens, {
|
||||
const SearchViewTemplate(
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
super.textThemePrefix = '_textTheme.'
|
||||
super.textThemePrefix = '_textTheme.',
|
||||
});
|
||||
|
||||
@override
|
||||
|
||||
@@ -5,7 +5,11 @@
|
||||
import 'template.dart';
|
||||
|
||||
class SegmentedButtonTemplate extends TokenTemplate {
|
||||
const SegmentedButtonTemplate(this.tokenGroup, super.blockName, super.fileName, super.tokens, {
|
||||
const SegmentedButtonTemplate(
|
||||
this.tokenGroup,
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
});
|
||||
|
||||
|
||||
@@ -5,7 +5,11 @@
|
||||
import 'template.dart';
|
||||
|
||||
class SliderTemplate extends TokenTemplate {
|
||||
const SliderTemplate(this.tokenGroup, super.blockName, super.fileName, super.tokens, {
|
||||
const SliderTemplate(
|
||||
this.tokenGroup,
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
});
|
||||
|
||||
|
||||
@@ -6,8 +6,11 @@ import 'template.dart';
|
||||
|
||||
class SnackbarTemplate extends TokenTemplate {
|
||||
const SnackbarTemplate(
|
||||
this.tokenGroup, super.blockName, super.fileName, super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.'
|
||||
this.tokenGroup,
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
});
|
||||
|
||||
final String tokenGroup;
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
import 'template.dart';
|
||||
|
||||
class SwitchTemplate extends TokenTemplate {
|
||||
const SwitchTemplate(super.blockName, super.fileName, super.tokens, {
|
||||
const SwitchTemplate(
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
});
|
||||
|
||||
@@ -231,5 +234,4 @@ class _SwitchConfigM3 with _SwitchConfig {
|
||||
Size get switchMinSize => const Size(kMinInteractiveDimension, kMinInteractiveDimension - 8.0);
|
||||
}
|
||||
''';
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
import 'template.dart';
|
||||
|
||||
class TabsTemplate extends TokenTemplate {
|
||||
const TabsTemplate(super.blockName, super.fileName, super.tokens, {
|
||||
const TabsTemplate(
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
super.textThemePrefix = '_textTheme.',
|
||||
});
|
||||
@@ -160,5 +163,4 @@ class _${blockName}SecondaryDefaultsM3 extends TabBarThemeData {
|
||||
static double indicatorWeight = ${getToken('md.comp.secondary-navigation-tab.active-indicator.height')};
|
||||
}
|
||||
''';
|
||||
|
||||
}
|
||||
|
||||
@@ -8,9 +8,12 @@ import 'token_logger.dart';
|
||||
|
||||
/// Base class for code generation templates.
|
||||
abstract class TokenTemplate {
|
||||
const TokenTemplate(this.blockName, this.fileName, this._tokens, {
|
||||
const TokenTemplate(
|
||||
this.blockName,
|
||||
this.fileName,
|
||||
this._tokens, {
|
||||
this.colorSchemePrefix = 'Theme.of(context).colorScheme.',
|
||||
this.textThemePrefix = 'Theme.of(context).textTheme.'
|
||||
this.textThemePrefix = 'Theme.of(context).textTheme.',
|
||||
});
|
||||
|
||||
/// Name of the code block that this template will generate.
|
||||
@@ -58,6 +61,13 @@ abstract class TokenTemplate {
|
||||
// Design token database by the script:
|
||||
// dev/tools/gen_defaults/bin/gen_defaults.dart.
|
||||
|
||||
// dart format off
|
||||
''';
|
||||
|
||||
// TODO(goderbauer): Update the script to output auto-formatted code and remove
|
||||
// "dart format off/on" from headerComment and footerComment.
|
||||
static const String footerComment = '''
|
||||
// dart format on
|
||||
''';
|
||||
|
||||
static const String endGeneratedComment = '''
|
||||
@@ -95,6 +105,7 @@ abstract class TokenTemplate {
|
||||
buffer.write(beginComment);
|
||||
buffer.write(headerComment);
|
||||
buffer.write(generate());
|
||||
buffer.write(footerComment);
|
||||
buffer.write(endComment);
|
||||
buffer.write(contentAfterBlock);
|
||||
File(fileName).writeAsStringSync(buffer.toString());
|
||||
@@ -194,8 +205,14 @@ abstract class TokenTemplate {
|
||||
if (!tokenAvailable(widthToken) && !tokenAvailable(heightToken)) {
|
||||
throw Exception('Unable to find width, height, or size tokens for $componentToken');
|
||||
}
|
||||
final String? width = _numToString(tokenAvailable(widthToken) ? getToken(widthToken)! as num : double.infinity, 0);
|
||||
final String? height = _numToString(tokenAvailable(heightToken) ? getToken(heightToken)! as num : double.infinity, 0);
|
||||
final String? width = _numToString(
|
||||
tokenAvailable(widthToken) ? getToken(widthToken)! as num : double.infinity,
|
||||
0,
|
||||
);
|
||||
final String? height = _numToString(
|
||||
tokenAvailable(heightToken) ? getToken(heightToken)! as num : double.infinity,
|
||||
0,
|
||||
);
|
||||
return 'const Size($width, $height)';
|
||||
}
|
||||
return 'const Size.square(${_numToString(getToken(sizeToken))})';
|
||||
@@ -207,8 +224,8 @@ abstract class TokenTemplate {
|
||||
/// - "SHAPE_FAMILY_ROUNDED_CORNERS" which maps to [RoundedRectangleBorder].
|
||||
/// - "SHAPE_FAMILY_CIRCULAR" which maps to a [StadiumBorder].
|
||||
String shape(String componentToken, [String prefix = 'const ']) {
|
||||
|
||||
final Map<String, dynamic> shape = getToken(getToken('$componentToken.shape') as String) as Map<String, dynamic>;
|
||||
final Map<String, dynamic> shape =
|
||||
getToken(getToken('$componentToken.shape') as String) as Map<String, dynamic>;
|
||||
switch (shape['family']) {
|
||||
case 'SHAPE_FAMILY_ROUNDED_CORNERS':
|
||||
final double topLeft = shape['topLeft'] as double;
|
||||
@@ -223,18 +240,18 @@ abstract class TokenTemplate {
|
||||
}
|
||||
if (topLeft == topRight && bottomLeft == bottomRight) {
|
||||
return '${prefix}RoundedRectangleBorder(borderRadius: BorderRadius.vertical('
|
||||
'${topLeft > 0 ? 'top: Radius.circular($topLeft)':''}'
|
||||
'${topLeft > 0 && bottomLeft > 0 ? ',':''}'
|
||||
'${bottomLeft > 0 ? 'bottom: Radius.circular($bottomLeft)':''}'
|
||||
'))';
|
||||
'${topLeft > 0 ? 'top: Radius.circular($topLeft)' : ''}'
|
||||
'${topLeft > 0 && bottomLeft > 0 ? ',' : ''}'
|
||||
'${bottomLeft > 0 ? 'bottom: Radius.circular($bottomLeft)' : ''}'
|
||||
'))';
|
||||
}
|
||||
return '${prefix}RoundedRectangleBorder(borderRadius: '
|
||||
'BorderRadius.only('
|
||||
'topLeft: Radius.circular(${shape['topLeft']}), '
|
||||
'topRight: Radius.circular(${shape['topRight']}), '
|
||||
'bottomLeft: Radius.circular(${shape['bottomLeft']}), '
|
||||
'bottomRight: Radius.circular(${shape['bottomRight']})))';
|
||||
case 'SHAPE_FAMILY_CIRCULAR':
|
||||
'BorderRadius.only('
|
||||
'topLeft: Radius.circular(${shape['topLeft']}), '
|
||||
'topRight: Radius.circular(${shape['topRight']}), '
|
||||
'bottomLeft: Radius.circular(${shape['bottomLeft']}), '
|
||||
'bottomRight: Radius.circular(${shape['bottomRight']})))';
|
||||
case 'SHAPE_FAMILY_CIRCULAR':
|
||||
return '${prefix}StadiumBorder()';
|
||||
}
|
||||
print('Unsupported shape family type: ${shape['family']} for $componentToken');
|
||||
@@ -243,27 +260,24 @@ abstract class TokenTemplate {
|
||||
|
||||
/// Generate a [BorderSide] for the given component.
|
||||
String border(String componentToken) {
|
||||
|
||||
if (!tokenAvailable('$componentToken.color')) {
|
||||
return 'null';
|
||||
}
|
||||
final String borderColor = componentColor(componentToken);
|
||||
final double width = (
|
||||
getToken('$componentToken.width', optional: true) ??
|
||||
getToken('$componentToken.height', optional: true) ??
|
||||
1.0
|
||||
) as double;
|
||||
final double width =
|
||||
(getToken('$componentToken.width', optional: true) ??
|
||||
getToken('$componentToken.height', optional: true) ??
|
||||
1.0)
|
||||
as double;
|
||||
return 'BorderSide(color: $borderColor${width != 1.0 ? ", width: $width" : ""})';
|
||||
}
|
||||
|
||||
/// Generate a [TextTheme] text style name for the given component token.
|
||||
String textStyle(String componentToken) {
|
||||
|
||||
return '$textThemePrefix${getToken("$componentToken.text-style")}';
|
||||
}
|
||||
|
||||
String textStyleWithColor(String componentToken) {
|
||||
|
||||
if (!tokenAvailable('$componentToken.text-style')) {
|
||||
return 'null';
|
||||
}
|
||||
|
||||
@@ -5,9 +5,12 @@
|
||||
import 'template.dart';
|
||||
|
||||
class TimePickerTemplate extends TokenTemplate {
|
||||
const TimePickerTemplate(super.blockName, super.fileName, super.tokens, {
|
||||
const TimePickerTemplate(
|
||||
super.blockName,
|
||||
super.fileName,
|
||||
super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
super.textThemePrefix = '_textTheme.'
|
||||
super.textThemePrefix = '_textTheme.',
|
||||
});
|
||||
|
||||
static const String tokenGroup = 'md.comp.time-picker';
|
||||
|
||||
@@ -13,8 +13,8 @@ class TokenLogger {
|
||||
|
||||
void init({
|
||||
required Map<String, dynamic> allTokens,
|
||||
required Map<String, List<String>> versionMap
|
||||
}){
|
||||
required Map<String, List<String>> versionMap,
|
||||
}) {
|
||||
_allTokens = allTokens;
|
||||
_versionMap = versionMap;
|
||||
}
|
||||
@@ -83,7 +83,11 @@ class TokenLogger {
|
||||
|
||||
if (_unavailableTokens.isNotEmpty) {
|
||||
print('');
|
||||
print('\x1B[31m' 'Some referenced tokens do not exist: ${_unavailableTokens.length}' '\x1B[0m');
|
||||
print(
|
||||
'\x1B[31m'
|
||||
'Some referenced tokens do not exist: ${_unavailableTokens.length}'
|
||||
'\x1B[0m',
|
||||
);
|
||||
for (final String token in _unavailableTokens) {
|
||||
print(' $token');
|
||||
}
|
||||
|
||||
@@ -20,21 +20,51 @@ abstract final class _M3Typography {
|
||||
|
||||
String _textTheme(String name, String baseline) {
|
||||
final StringBuffer theme = StringBuffer('static const TextTheme $name = TextTheme(\n');
|
||||
theme.writeln(' displayLarge: ${_textStyleDef('md.sys.typescale.display-large', '$name displayLarge 2021', baseline)},');
|
||||
theme.writeln(' displayMedium: ${_textStyleDef('md.sys.typescale.display-medium', '$name displayMedium 2021', baseline)},');
|
||||
theme.writeln(' displaySmall: ${_textStyleDef('md.sys.typescale.display-small', '$name displaySmall 2021', baseline)},');
|
||||
theme.writeln(' headlineLarge: ${_textStyleDef('md.sys.typescale.headline-large', '$name headlineLarge 2021', baseline)},');
|
||||
theme.writeln(' headlineMedium: ${_textStyleDef('md.sys.typescale.headline-medium', '$name headlineMedium 2021', baseline)},');
|
||||
theme.writeln(' headlineSmall: ${_textStyleDef('md.sys.typescale.headline-small', '$name headlineSmall 2021', baseline)},');
|
||||
theme.writeln(' titleLarge: ${_textStyleDef('md.sys.typescale.title-large', '$name titleLarge 2021', baseline)},');
|
||||
theme.writeln(' titleMedium: ${_textStyleDef('md.sys.typescale.title-medium', '$name titleMedium 2021', baseline)},');
|
||||
theme.writeln(' titleSmall: ${_textStyleDef('md.sys.typescale.title-small', '$name titleSmall 2021', baseline)},');
|
||||
theme.writeln(' labelLarge: ${_textStyleDef('md.sys.typescale.label-large', '$name labelLarge 2021', baseline)},');
|
||||
theme.writeln(' labelMedium: ${_textStyleDef('md.sys.typescale.label-medium', '$name labelMedium 2021', baseline)},');
|
||||
theme.writeln(' labelSmall: ${_textStyleDef('md.sys.typescale.label-small', '$name labelSmall 2021', baseline)},');
|
||||
theme.writeln(' bodyLarge: ${_textStyleDef('md.sys.typescale.body-large', '$name bodyLarge 2021', baseline)},');
|
||||
theme.writeln(' bodyMedium: ${_textStyleDef('md.sys.typescale.body-medium', '$name bodyMedium 2021', baseline)},');
|
||||
theme.writeln(' bodySmall: ${_textStyleDef('md.sys.typescale.body-small', '$name bodySmall 2021', baseline)},');
|
||||
theme.writeln(
|
||||
' displayLarge: ${_textStyleDef('md.sys.typescale.display-large', '$name displayLarge 2021', baseline)},',
|
||||
);
|
||||
theme.writeln(
|
||||
' displayMedium: ${_textStyleDef('md.sys.typescale.display-medium', '$name displayMedium 2021', baseline)},',
|
||||
);
|
||||
theme.writeln(
|
||||
' displaySmall: ${_textStyleDef('md.sys.typescale.display-small', '$name displaySmall 2021', baseline)},',
|
||||
);
|
||||
theme.writeln(
|
||||
' headlineLarge: ${_textStyleDef('md.sys.typescale.headline-large', '$name headlineLarge 2021', baseline)},',
|
||||
);
|
||||
theme.writeln(
|
||||
' headlineMedium: ${_textStyleDef('md.sys.typescale.headline-medium', '$name headlineMedium 2021', baseline)},',
|
||||
);
|
||||
theme.writeln(
|
||||
' headlineSmall: ${_textStyleDef('md.sys.typescale.headline-small', '$name headlineSmall 2021', baseline)},',
|
||||
);
|
||||
theme.writeln(
|
||||
' titleLarge: ${_textStyleDef('md.sys.typescale.title-large', '$name titleLarge 2021', baseline)},',
|
||||
);
|
||||
theme.writeln(
|
||||
' titleMedium: ${_textStyleDef('md.sys.typescale.title-medium', '$name titleMedium 2021', baseline)},',
|
||||
);
|
||||
theme.writeln(
|
||||
' titleSmall: ${_textStyleDef('md.sys.typescale.title-small', '$name titleSmall 2021', baseline)},',
|
||||
);
|
||||
theme.writeln(
|
||||
' labelLarge: ${_textStyleDef('md.sys.typescale.label-large', '$name labelLarge 2021', baseline)},',
|
||||
);
|
||||
theme.writeln(
|
||||
' labelMedium: ${_textStyleDef('md.sys.typescale.label-medium', '$name labelMedium 2021', baseline)},',
|
||||
);
|
||||
theme.writeln(
|
||||
' labelSmall: ${_textStyleDef('md.sys.typescale.label-small', '$name labelSmall 2021', baseline)},',
|
||||
);
|
||||
theme.writeln(
|
||||
' bodyLarge: ${_textStyleDef('md.sys.typescale.body-large', '$name bodyLarge 2021', baseline)},',
|
||||
);
|
||||
theme.writeln(
|
||||
' bodyMedium: ${_textStyleDef('md.sys.typescale.body-medium', '$name bodyMedium 2021', baseline)},',
|
||||
);
|
||||
theme.writeln(
|
||||
' bodySmall: ${_textStyleDef('md.sys.typescale.body-small', '$name bodySmall 2021', baseline)},',
|
||||
);
|
||||
theme.write(' );');
|
||||
return theme.toString();
|
||||
}
|
||||
@@ -57,7 +87,8 @@ abstract final class _M3Typography {
|
||||
}
|
||||
|
||||
String _fontWeight(String textStyleTokenName) {
|
||||
final String weightValue = getToken(getToken('$textStyleTokenName.weight') as String).toString();
|
||||
final String weightValue =
|
||||
getToken(getToken('$textStyleTokenName.weight') as String).toString();
|
||||
return 'FontWeight.w$weightValue';
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,11 @@ void main() {
|
||||
|
||||
// Have a test template append new parameterized content to the end of
|
||||
// the file.
|
||||
final Map<String, dynamic> tokens = <String, dynamic>{'version': '0.0', 'foo': 'Foobar', 'bar': 'Barfoo'};
|
||||
final Map<String, dynamic> tokens = <String, dynamic>{
|
||||
'version': '0.0',
|
||||
'foo': 'Foobar',
|
||||
'bar': 'Barfoo',
|
||||
};
|
||||
TestTemplate('Test', tempFile.path, tokens).updateFile();
|
||||
|
||||
expect(tempFile.readAsStringSync(), '''
|
||||
@@ -58,12 +62,13 @@ void main() {
|
||||
// Design token database by the script:
|
||||
// dev/tools/gen_defaults/bin/gen_defaults.dart.
|
||||
|
||||
// dart format off
|
||||
static final String tokenFoo = 'Foobar';
|
||||
static final String tokenBar = 'Barfoo';
|
||||
// dart format on
|
||||
|
||||
// END GENERATED TOKEN PROPERTIES - Test
|
||||
''');
|
||||
|
||||
} finally {
|
||||
tempDir.deleteSync(recursive: true);
|
||||
}
|
||||
@@ -87,15 +92,21 @@ static final String tokenBar = 'Barfoo';
|
||||
// Design token database by the script:
|
||||
// dev/tools/gen_defaults/bin/gen_defaults.dart.
|
||||
|
||||
// dart format off
|
||||
static final String tokenFoo = 'Foobar';
|
||||
static final String tokenBar = 'Barfoo';
|
||||
// dart format on
|
||||
|
||||
// END GENERATED TOKEN PROPERTIES - Test
|
||||
''');
|
||||
|
||||
// Have a test template append new parameterized content to the end of
|
||||
// the file.
|
||||
final Map<String, dynamic> tokens = <String, dynamic>{'version': '0.0', 'foo': 'foo', 'bar': 'bar'};
|
||||
final Map<String, dynamic> tokens = <String, dynamic>{
|
||||
'version': '0.0',
|
||||
'foo': 'foo',
|
||||
'bar': 'bar',
|
||||
};
|
||||
TestTemplate('Test', tempFile.path, tokens).updateFile();
|
||||
|
||||
expect(tempFile.readAsStringSync(), '''
|
||||
@@ -110,12 +121,13 @@ static final String tokenBar = 'Barfoo';
|
||||
// Design token database by the script:
|
||||
// dev/tools/gen_defaults/bin/gen_defaults.dart.
|
||||
|
||||
// dart format off
|
||||
static final String tokenFoo = 'foo';
|
||||
static final String tokenBar = 'bar';
|
||||
// dart format on
|
||||
|
||||
// END GENERATED TOKEN PROPERTIES - Test
|
||||
''');
|
||||
|
||||
} finally {
|
||||
tempDir.deleteSync(recursive: true);
|
||||
}
|
||||
@@ -135,7 +147,11 @@ static final String tokenBar = 'bar';
|
||||
|
||||
// Update file with a template for 'Block 1'
|
||||
{
|
||||
final Map<String, dynamic> tokens = <String, dynamic>{'version': '0.0', 'foo': 'foo', 'bar': 'bar'};
|
||||
final Map<String, dynamic> tokens = <String, dynamic>{
|
||||
'version': '0.0',
|
||||
'foo': 'foo',
|
||||
'bar': 'bar',
|
||||
};
|
||||
TestTemplate('Block 1', tempFile.path, tokens).updateFile();
|
||||
}
|
||||
expect(tempFile.readAsStringSync(), '''
|
||||
@@ -150,8 +166,10 @@ static final String tokenBar = 'bar';
|
||||
// Design token database by the script:
|
||||
// dev/tools/gen_defaults/bin/gen_defaults.dart.
|
||||
|
||||
// dart format off
|
||||
static final String tokenFoo = 'foo';
|
||||
static final String tokenBar = 'bar';
|
||||
// dart format on
|
||||
|
||||
// END GENERATED TOKEN PROPERTIES - Block 1
|
||||
''');
|
||||
@@ -159,7 +177,11 @@ static final String tokenBar = 'bar';
|
||||
// Update file with a template for 'Block 2', which should append but not
|
||||
// disturb the code in 'Block 1'.
|
||||
{
|
||||
final Map<String, dynamic> tokens = <String, dynamic>{'version': '0.0', 'foo': 'bar', 'bar': 'foo'};
|
||||
final Map<String, dynamic> tokens = <String, dynamic>{
|
||||
'version': '0.0',
|
||||
'foo': 'bar',
|
||||
'bar': 'foo',
|
||||
};
|
||||
TestTemplate('Block 2', tempFile.path, tokens).updateFile();
|
||||
}
|
||||
expect(tempFile.readAsStringSync(), '''
|
||||
@@ -174,8 +196,10 @@ static final String tokenBar = 'bar';
|
||||
// Design token database by the script:
|
||||
// dev/tools/gen_defaults/bin/gen_defaults.dart.
|
||||
|
||||
// dart format off
|
||||
static final String tokenFoo = 'foo';
|
||||
static final String tokenBar = 'bar';
|
||||
// dart format on
|
||||
|
||||
// END GENERATED TOKEN PROPERTIES - Block 1
|
||||
|
||||
@@ -186,8 +210,10 @@ static final String tokenBar = 'bar';
|
||||
// Design token database by the script:
|
||||
// dev/tools/gen_defaults/bin/gen_defaults.dart.
|
||||
|
||||
// dart format off
|
||||
static final String tokenFoo = 'bar';
|
||||
static final String tokenBar = 'foo';
|
||||
// dart format on
|
||||
|
||||
// END GENERATED TOKEN PROPERTIES - Block 2
|
||||
''');
|
||||
@@ -195,7 +221,11 @@ static final String tokenBar = 'foo';
|
||||
// Update 'Block 1' again which should just update that block,
|
||||
// leaving 'Block 2' undisturbed.
|
||||
{
|
||||
final Map<String, dynamic> tokens = <String, dynamic>{'version': '0.0', 'foo': 'FOO', 'bar': 'BAR'};
|
||||
final Map<String, dynamic> tokens = <String, dynamic>{
|
||||
'version': '0.0',
|
||||
'foo': 'FOO',
|
||||
'bar': 'BAR',
|
||||
};
|
||||
TestTemplate('Block 1', tempFile.path, tokens).updateFile();
|
||||
}
|
||||
expect(tempFile.readAsStringSync(), '''
|
||||
@@ -210,8 +240,10 @@ static final String tokenBar = 'foo';
|
||||
// Design token database by the script:
|
||||
// dev/tools/gen_defaults/bin/gen_defaults.dart.
|
||||
|
||||
// dart format off
|
||||
static final String tokenFoo = 'FOO';
|
||||
static final String tokenBar = 'BAR';
|
||||
// dart format on
|
||||
|
||||
// END GENERATED TOKEN PROPERTIES - Block 1
|
||||
|
||||
@@ -222,12 +254,13 @@ static final String tokenBar = 'BAR';
|
||||
// Design token database by the script:
|
||||
// dev/tools/gen_defaults/bin/gen_defaults.dart.
|
||||
|
||||
// dart format off
|
||||
static final String tokenFoo = 'bar';
|
||||
static final String tokenBar = 'foo';
|
||||
// dart format on
|
||||
|
||||
// END GENERATED TOKEN PROPERTIES - Block 2
|
||||
''');
|
||||
|
||||
} finally {
|
||||
tempDir.deleteSync(recursive: true);
|
||||
}
|
||||
@@ -244,12 +277,13 @@ static final String tokenBar = 'foo';
|
||||
'bottomLeft': 3.0,
|
||||
'bottomRight': 4.0,
|
||||
},
|
||||
'shape.full': <String, dynamic>{
|
||||
'family': 'SHAPE_FAMILY_CIRCULAR',
|
||||
},
|
||||
'shape.full': <String, dynamic>{'family': 'SHAPE_FAMILY_CIRCULAR'},
|
||||
};
|
||||
final TestTemplate template = TestTemplate('Test', 'foobar.dart', tokens);
|
||||
expect(template.shape('foo'), 'const RoundedRectangleBorder(borderRadius: BorderRadius.only(topLeft: Radius.circular(1.0), topRight: Radius.circular(2.0), bottomLeft: Radius.circular(3.0), bottomRight: Radius.circular(4.0)))');
|
||||
expect(
|
||||
template.shape('foo'),
|
||||
'const RoundedRectangleBorder(borderRadius: BorderRadius.only(topLeft: Radius.circular(1.0), topRight: Radius.circular(2.0), bottomLeft: Radius.circular(3.0), bottomRight: Radius.circular(4.0)))',
|
||||
);
|
||||
expect(template.shape('bar'), 'const StadiumBorder()');
|
||||
});
|
||||
|
||||
@@ -263,7 +297,7 @@ static final String tokenBar = 'foo';
|
||||
final ZoneSpecification spec = ZoneSpecification(
|
||||
print: (_, __, ___, String msg) {
|
||||
printLog.add(msg);
|
||||
}
|
||||
},
|
||||
);
|
||||
return Zone.current.fork(specification: spec).run<void>(testFn);
|
||||
};
|
||||
@@ -286,151 +320,190 @@ static final String tokenBar = 'foo';
|
||||
'v2.0.0': <String>['file_2.json, file_3.json'],
|
||||
};
|
||||
|
||||
test('can print empty usage', overridePrint(() {
|
||||
logger.printVersionUsage(verbose: true);
|
||||
expect(printLog, contains('Versions used: '));
|
||||
test(
|
||||
'can print empty usage',
|
||||
overridePrint(() {
|
||||
logger.printVersionUsage(verbose: true);
|
||||
expect(printLog, contains('Versions used: '));
|
||||
|
||||
logger.printTokensUsage(verbose: true);
|
||||
expect(printLog, contains('Tokens used: 0/0'));
|
||||
}));
|
||||
logger.printTokensUsage(verbose: true);
|
||||
expect(printLog, contains('Tokens used: 0/0'));
|
||||
}),
|
||||
);
|
||||
|
||||
test('can print version usage', overridePrint(() {
|
||||
versionMap.addAll(testVersions);
|
||||
test(
|
||||
'can print version usage',
|
||||
overridePrint(() {
|
||||
versionMap.addAll(testVersions);
|
||||
|
||||
logger.printVersionUsage(verbose: false);
|
||||
logger.printVersionUsage(verbose: false);
|
||||
|
||||
expect(printLog, contains('Versions used: v1.0.0, v2.0.0'));
|
||||
}));
|
||||
expect(printLog, contains('Versions used: v1.0.0, v2.0.0'));
|
||||
}),
|
||||
);
|
||||
|
||||
test('can print version usage (verbose)', overridePrint(() {
|
||||
versionMap.addAll(testVersions);
|
||||
test(
|
||||
'can print version usage (verbose)',
|
||||
overridePrint(() {
|
||||
versionMap.addAll(testVersions);
|
||||
|
||||
logger.printVersionUsage(verbose: true);
|
||||
logger.printVersionUsage(verbose: true);
|
||||
|
||||
expect(printLog, contains('Versions used: v1.0.0, v2.0.0'));
|
||||
expect(printLog, contains(' v1.0.0:'));
|
||||
expect(printLog, contains(' file_1.json'));
|
||||
expect(printLog, contains(' v2.0.0:'));
|
||||
expect(printLog, contains(' file_2.json, file_3.json'));
|
||||
}));
|
||||
expect(printLog, contains('Versions used: v1.0.0, v2.0.0'));
|
||||
expect(printLog, contains(' v1.0.0:'));
|
||||
expect(printLog, contains(' file_1.json'));
|
||||
expect(printLog, contains(' v2.0.0:'));
|
||||
expect(printLog, contains(' file_2.json, file_3.json'));
|
||||
}),
|
||||
);
|
||||
|
||||
test('can log and print tokens usage', overridePrint(() {
|
||||
allTokens['foo'] = 'value';
|
||||
test(
|
||||
'can log and print tokens usage',
|
||||
overridePrint(() {
|
||||
allTokens['foo'] = 'value';
|
||||
|
||||
logger.log('foo');
|
||||
logger.printTokensUsage(verbose: false);
|
||||
logger.log('foo');
|
||||
logger.printTokensUsage(verbose: false);
|
||||
|
||||
expect(printLog, contains('Tokens used: 1/1'));
|
||||
}));
|
||||
expect(printLog, contains('Tokens used: 1/1'));
|
||||
}),
|
||||
);
|
||||
|
||||
test('can log and print tokens usage (verbose)', overridePrint(() {
|
||||
allTokens['foo'] = 'value';
|
||||
test(
|
||||
'can log and print tokens usage (verbose)',
|
||||
overridePrint(() {
|
||||
allTokens['foo'] = 'value';
|
||||
|
||||
logger.log('foo');
|
||||
logger.printTokensUsage(verbose: true);
|
||||
logger.log('foo');
|
||||
logger.printTokensUsage(verbose: true);
|
||||
|
||||
expect(printLog, contains('✅ foo'));
|
||||
expect(printLog, contains('Tokens used: 1/1'));
|
||||
}));
|
||||
expect(printLog, contains('✅ foo'));
|
||||
expect(printLog, contains('Tokens used: 1/1'));
|
||||
}),
|
||||
);
|
||||
|
||||
test('detects invalid logs', overridePrint(() {
|
||||
allTokens['foo'] = 'value';
|
||||
test(
|
||||
'detects invalid logs',
|
||||
overridePrint(() {
|
||||
allTokens['foo'] = 'value';
|
||||
|
||||
logger.log('baz');
|
||||
logger.log('foobar');
|
||||
logger.printTokensUsage(verbose: true);
|
||||
logger.log('baz');
|
||||
logger.log('foobar');
|
||||
logger.printTokensUsage(verbose: true);
|
||||
|
||||
expect(printLog, contains('❌ foo'));
|
||||
expect(printLog, contains('Tokens used: 0/1'));
|
||||
expect(printLog, contains(errorColoredString('Some referenced tokens do not exist: 2')));
|
||||
expect(printLog, contains(' baz'));
|
||||
expect(printLog, contains(' foobar'));
|
||||
}));
|
||||
expect(printLog, contains('❌ foo'));
|
||||
expect(printLog, contains('Tokens used: 0/1'));
|
||||
expect(printLog, contains(errorColoredString('Some referenced tokens do not exist: 2')));
|
||||
expect(printLog, contains(' baz'));
|
||||
expect(printLog, contains(' foobar'));
|
||||
}),
|
||||
);
|
||||
|
||||
test("color function doesn't log when providing a default", overridePrint(() {
|
||||
allTokens['color_foo_req'] = 'value';
|
||||
test(
|
||||
"color function doesn't log when providing a default",
|
||||
overridePrint(() {
|
||||
allTokens['color_foo_req'] = 'value';
|
||||
|
||||
// color_foo_opt is not available, but because it has a default value, it won't warn about it
|
||||
// color_foo_opt is not available, but because it has a default value, it won't warn about it
|
||||
|
||||
TestColorTemplate('block', 'filename', allTokens).generate();
|
||||
logger.printTokensUsage(verbose: true);
|
||||
TestColorTemplate('block', 'filename', allTokens).generate();
|
||||
logger.printTokensUsage(verbose: true);
|
||||
|
||||
expect(printLog, contains('✅ color_foo_req'));
|
||||
expect(printLog, contains('Tokens used: 1/1'));
|
||||
}));
|
||||
expect(printLog, contains('✅ color_foo_req'));
|
||||
expect(printLog, contains('Tokens used: 1/1'));
|
||||
}),
|
||||
);
|
||||
|
||||
test('color function logs when not providing a default', overridePrint(() {
|
||||
// Nor color_foo_req or color_foo_opt are available, but only color_foo_req will be logged.
|
||||
// This mimics a token being removed, but expected to exist.
|
||||
test(
|
||||
'color function logs when not providing a default',
|
||||
overridePrint(() {
|
||||
// Nor color_foo_req or color_foo_opt are available, but only color_foo_req will be logged.
|
||||
// This mimics a token being removed, but expected to exist.
|
||||
|
||||
TestColorTemplate('block', 'filename', allTokens).generate();
|
||||
logger.printTokensUsage(verbose: true);
|
||||
TestColorTemplate('block', 'filename', allTokens).generate();
|
||||
logger.printTokensUsage(verbose: true);
|
||||
|
||||
expect(printLog, contains('Tokens used: 0/0'));
|
||||
expect(printLog, contains(errorColoredString('Some referenced tokens do not exist: 1')));
|
||||
expect(printLog, contains(' color_foo_req'));
|
||||
}));
|
||||
expect(printLog, contains('Tokens used: 0/0'));
|
||||
expect(printLog, contains(errorColoredString('Some referenced tokens do not exist: 1')));
|
||||
expect(printLog, contains(' color_foo_req'));
|
||||
}),
|
||||
);
|
||||
|
||||
test('border function logs width token when available', overridePrint(() {
|
||||
allTokens['border_foo.color'] = 'red';
|
||||
allTokens['border_foo.width'] = 3.0;
|
||||
test(
|
||||
'border function logs width token when available',
|
||||
overridePrint(() {
|
||||
allTokens['border_foo.color'] = 'red';
|
||||
allTokens['border_foo.width'] = 3.0;
|
||||
|
||||
TestBorderTemplate('block', 'filename', allTokens).generate();
|
||||
logger.printTokensUsage(verbose: true);
|
||||
TestBorderTemplate('block', 'filename', allTokens).generate();
|
||||
logger.printTokensUsage(verbose: true);
|
||||
|
||||
expect(printLog, contains('✅ border_foo.color'));
|
||||
expect(printLog, contains('✅ border_foo.width'));
|
||||
expect(printLog, contains('Tokens used: 2/2'));
|
||||
}));
|
||||
expect(printLog, contains('✅ border_foo.color'));
|
||||
expect(printLog, contains('✅ border_foo.width'));
|
||||
expect(printLog, contains('Tokens used: 2/2'));
|
||||
}),
|
||||
);
|
||||
|
||||
test('border function logs height token when width token not available', overridePrint(() {
|
||||
allTokens['border_foo.color'] = 'red';
|
||||
allTokens['border_foo.height'] = 3.0;
|
||||
test(
|
||||
'border function logs height token when width token not available',
|
||||
overridePrint(() {
|
||||
allTokens['border_foo.color'] = 'red';
|
||||
allTokens['border_foo.height'] = 3.0;
|
||||
|
||||
TestBorderTemplate('block', 'filename', allTokens).generate();
|
||||
logger.printTokensUsage(verbose: true);
|
||||
TestBorderTemplate('block', 'filename', allTokens).generate();
|
||||
logger.printTokensUsage(verbose: true);
|
||||
|
||||
expect(printLog, contains('✅ border_foo.color'));
|
||||
expect(printLog, contains('✅ border_foo.height'));
|
||||
expect(printLog, contains('Tokens used: 2/2'));
|
||||
}));
|
||||
expect(printLog, contains('✅ border_foo.color'));
|
||||
expect(printLog, contains('✅ border_foo.height'));
|
||||
expect(printLog, contains('Tokens used: 2/2'));
|
||||
}),
|
||||
);
|
||||
|
||||
test("border function doesn't log when width or height tokens not available", overridePrint(() {
|
||||
allTokens['border_foo.color'] = 'red';
|
||||
test(
|
||||
"border function doesn't log when width or height tokens not available",
|
||||
overridePrint(() {
|
||||
allTokens['border_foo.color'] = 'red';
|
||||
|
||||
TestBorderTemplate('block', 'filename', allTokens).generate();
|
||||
logger.printTokensUsage(verbose: true);
|
||||
TestBorderTemplate('block', 'filename', allTokens).generate();
|
||||
logger.printTokensUsage(verbose: true);
|
||||
|
||||
expect(printLog, contains('✅ border_foo.color'));
|
||||
expect(printLog, contains('Tokens used: 1/1'));
|
||||
}));
|
||||
expect(printLog, contains('✅ border_foo.color'));
|
||||
expect(printLog, contains('Tokens used: 1/1'));
|
||||
}),
|
||||
);
|
||||
|
||||
test('can log and dump versions & tokens to a file', overridePrint(() {
|
||||
versionMap.addAll(testVersions);
|
||||
allTokens['foo'] = 'value';
|
||||
allTokens['bar'] = 'value';
|
||||
test(
|
||||
'can log and dump versions & tokens to a file',
|
||||
overridePrint(() {
|
||||
versionMap.addAll(testVersions);
|
||||
allTokens['foo'] = 'value';
|
||||
allTokens['bar'] = 'value';
|
||||
|
||||
logger.log('foo');
|
||||
logger.log('bar');
|
||||
logger.dumpToFile('test.json');
|
||||
logger.log('foo');
|
||||
logger.log('bar');
|
||||
logger.dumpToFile('test.json');
|
||||
|
||||
final String fileContent = File('test.json').readAsStringSync();
|
||||
expect(fileContent, contains('Versions used, v1.0.0, v2.0.0'));
|
||||
expect(fileContent, contains('bar,'));
|
||||
expect(fileContent, contains('foo'));
|
||||
}));
|
||||
final String fileContent = File('test.json').readAsStringSync();
|
||||
expect(fileContent, contains('Versions used, v1.0.0, v2.0.0'));
|
||||
expect(fileContent, contains('bar,'));
|
||||
expect(fileContent, contains('foo'));
|
||||
}),
|
||||
);
|
||||
|
||||
test('integration test', overridePrint(() {
|
||||
allTokens['foo'] = 'value';
|
||||
allTokens['bar'] = 'value';
|
||||
test(
|
||||
'integration test',
|
||||
overridePrint(() {
|
||||
allTokens['foo'] = 'value';
|
||||
allTokens['bar'] = 'value';
|
||||
|
||||
TestTemplate('block', 'filename', allTokens).generate();
|
||||
logger.printTokensUsage(verbose: true);
|
||||
TestTemplate('block', 'filename', allTokens).generate();
|
||||
logger.printTokensUsage(verbose: true);
|
||||
|
||||
expect(printLog, contains('✅ foo'));
|
||||
expect(printLog, contains('✅ bar'));
|
||||
expect(printLog, contains('Tokens used: 2/2'));
|
||||
}));
|
||||
expect(printLog, contains('✅ foo'));
|
||||
expect(printLog, contains('✅ bar'));
|
||||
expect(printLog, contains('Tokens used: 2/2'));
|
||||
}),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user