fixed inconsistent file names for *_chip.dart files and added a test (#111364)
This commit is contained in:
parent
f13737ce6a
commit
e2ab3e581e
@ -201,6 +201,10 @@ Future<void> run(List<String> arguments) async {
|
|||||||
} finally {
|
} finally {
|
||||||
outDir.deleteSync(recursive: true);
|
outDir.deleteSync(recursive: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure gen_default links the correct files
|
||||||
|
printProgress('Correct file names in gen_defaults.dart...');
|
||||||
|
await verifyTokenTemplatesUpdateCorrectFiles(flutterRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -278,6 +282,56 @@ Future<void> verifyNoDoubleClamp(String workingDirectory) async {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Verify Token Templates are mapped to correct file names while generating
|
||||||
|
/// M3 defaults in /dev/tools/gen_defaults/bin/gen_defaults.dart.
|
||||||
|
Future<void> verifyTokenTemplatesUpdateCorrectFiles(String workingDirectory) async {
|
||||||
|
final List<String> errors = <String>[];
|
||||||
|
|
||||||
|
String getMaterialDirPath(List<String> lines) {
|
||||||
|
final String line = lines.firstWhere((String line) => line.contains('String materialLib'));
|
||||||
|
final String relativePath = line.substring(line.indexOf("'") + 1, line.lastIndexOf("'"));
|
||||||
|
return path.join(workingDirectory, relativePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
String getFileName(String line) {
|
||||||
|
const String materialLibString = r"'$materialLib/";
|
||||||
|
final String leftClamp = line.substring(line.indexOf(materialLibString) + materialLibString.length);
|
||||||
|
return leftClamp.substring(0, leftClamp.indexOf("'"));
|
||||||
|
}
|
||||||
|
|
||||||
|
final String genDefaultsBinDir = '$workingDirectory/dev/tools/gen_defaults/bin';
|
||||||
|
final File file = File(path.join(genDefaultsBinDir, 'gen_defaults.dart'));
|
||||||
|
final List<String> lines = file.readAsLinesSync();
|
||||||
|
final String materialDirPath = getMaterialDirPath(lines);
|
||||||
|
bool atLeastOneTargetLineExists = false;
|
||||||
|
|
||||||
|
for (final String line in lines) {
|
||||||
|
if (line.contains('updateFile();')) {
|
||||||
|
atLeastOneTargetLineExists = true;
|
||||||
|
final String fileName = getFileName(line);
|
||||||
|
final String filePath = path.join(materialDirPath, fileName);
|
||||||
|
final File file = File(filePath);
|
||||||
|
|
||||||
|
if (!file.existsSync()) {
|
||||||
|
errors.add('file $filePath does not exist.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(atLeastOneTargetLineExists, 'No lines exist that this test expects to '
|
||||||
|
'verify. Check if the target file is correct or remove this test');
|
||||||
|
|
||||||
|
// Fail if any errors
|
||||||
|
if (errors.isNotEmpty) {
|
||||||
|
final String s = errors.length > 1 ? 's' : '';
|
||||||
|
final String itThem = errors.length > 1 ? 'them' : 'it';
|
||||||
|
foundError(<String>[
|
||||||
|
...errors,
|
||||||
|
'${bold}Please correct the file name$s or remove $itThem from /dev/tools/gen_defaults/bin/gen_defaults.dart$reset',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Verify tool test files end in `_test.dart`.
|
/// Verify tool test files end in `_test.dart`.
|
||||||
///
|
///
|
||||||
/// The test runner will only recognize files ending in `_test.dart` as tests to
|
/// The test runner will only recognize files ending in `_test.dart` as tests to
|
||||||
|
@ -17,17 +17,17 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:gen_defaults/action_chip_template.dart';
|
||||||
import 'package:gen_defaults/app_bar_template.dart';
|
import 'package:gen_defaults/app_bar_template.dart';
|
||||||
import 'package:gen_defaults/banner_template.dart';
|
import 'package:gen_defaults/banner_template.dart';
|
||||||
import 'package:gen_defaults/button_template.dart';
|
import 'package:gen_defaults/button_template.dart';
|
||||||
import 'package:gen_defaults/card_template.dart';
|
import 'package:gen_defaults/card_template.dart';
|
||||||
import 'package:gen_defaults/checkbox_template.dart';
|
import 'package:gen_defaults/checkbox_template.dart';
|
||||||
import 'package:gen_defaults/chip_action_template.dart';
|
|
||||||
import 'package:gen_defaults/chip_filter_template.dart';
|
|
||||||
import 'package:gen_defaults/chip_input_template.dart';
|
|
||||||
import 'package:gen_defaults/dialog_template.dart';
|
import 'package:gen_defaults/dialog_template.dart';
|
||||||
import 'package:gen_defaults/fab_template.dart';
|
import 'package:gen_defaults/fab_template.dart';
|
||||||
|
import 'package:gen_defaults/filter_chip_template.dart';
|
||||||
import 'package:gen_defaults/icon_button_template.dart';
|
import 'package:gen_defaults/icon_button_template.dart';
|
||||||
|
import 'package:gen_defaults/input_chip_template.dart';
|
||||||
import 'package:gen_defaults/input_decorator_template.dart';
|
import 'package:gen_defaults/input_decorator_template.dart';
|
||||||
import 'package:gen_defaults/navigation_bar_template.dart';
|
import 'package:gen_defaults/navigation_bar_template.dart';
|
||||||
import 'package:gen_defaults/navigation_rail_template.dart';
|
import 'package:gen_defaults/navigation_rail_template.dart';
|
||||||
@ -104,6 +104,7 @@ Future<void> main(List<String> args) async {
|
|||||||
tokens['colorsLight'] = _readTokenFile('color_light.json');
|
tokens['colorsLight'] = _readTokenFile('color_light.json');
|
||||||
tokens['colorsDark'] = _readTokenFile('color_dark.json');
|
tokens['colorsDark'] = _readTokenFile('color_dark.json');
|
||||||
|
|
||||||
|
ActionChipTemplate('ActionChip', '$materialLib/action_chip.dart', tokens).updateFile();
|
||||||
AppBarTemplate('AppBar', '$materialLib/app_bar.dart', tokens).updateFile();
|
AppBarTemplate('AppBar', '$materialLib/app_bar.dart', tokens).updateFile();
|
||||||
BannerTemplate('Banner', '$materialLib/banner.dart', tokens).updateFile();
|
BannerTemplate('Banner', '$materialLib/banner.dart', tokens).updateFile();
|
||||||
ButtonTemplate('md.comp.elevated-button', 'ElevatedButton', '$materialLib/elevated_button.dart', tokens).updateFile();
|
ButtonTemplate('md.comp.elevated-button', 'ElevatedButton', '$materialLib/elevated_button.dart', tokens).updateFile();
|
||||||
@ -113,13 +114,12 @@ Future<void> main(List<String> args) async {
|
|||||||
ButtonTemplate('md.comp.text-button', 'TextButton', '$materialLib/text_button.dart', tokens).updateFile();
|
ButtonTemplate('md.comp.text-button', 'TextButton', '$materialLib/text_button.dart', tokens).updateFile();
|
||||||
CardTemplate('Card', '$materialLib/card.dart', tokens).updateFile();
|
CardTemplate('Card', '$materialLib/card.dart', tokens).updateFile();
|
||||||
CheckboxTemplate('Checkbox', '$materialLib/checkbox.dart', tokens).updateFile();
|
CheckboxTemplate('Checkbox', '$materialLib/checkbox.dart', tokens).updateFile();
|
||||||
ChipActionTemplate('ActionChip', '$materialLib/action_chip.dart', tokens).updateFile();
|
|
||||||
ChipFilterTemplate('FilterChip', '$materialLib/filter_chip.dart', tokens).updateFile();
|
|
||||||
ChipFilterTemplate('FilterChip', '$materialLib/choice_chip.dart', tokens).updateFile();
|
|
||||||
ChipInputTemplate('InputChip', '$materialLib/input_chip.dart', tokens).updateFile();
|
|
||||||
DialogTemplate('Dialog', '$materialLib/dialog.dart', tokens).updateFile();
|
DialogTemplate('Dialog', '$materialLib/dialog.dart', tokens).updateFile();
|
||||||
FABTemplate('FAB', '$materialLib/floating_action_button.dart', tokens).updateFile();
|
FABTemplate('FAB', '$materialLib/floating_action_button.dart', tokens).updateFile();
|
||||||
|
FilterChipTemplate('ChoiceChip', '$materialLib/choice_chip.dart', tokens).updateFile();
|
||||||
|
FilterChipTemplate('FilterChip', '$materialLib/filter_chip.dart', tokens).updateFile();
|
||||||
IconButtonTemplate('IconButton', '$materialLib/icon_button.dart', tokens).updateFile();
|
IconButtonTemplate('IconButton', '$materialLib/icon_button.dart', tokens).updateFile();
|
||||||
|
InputChipTemplate('InputChip', '$materialLib/input_chip.dart', tokens).updateFile();
|
||||||
InputDecoratorTemplate('InputDecorator', '$materialLib/input_decorator.dart', tokens).updateFile();
|
InputDecoratorTemplate('InputDecorator', '$materialLib/input_decorator.dart', tokens).updateFile();
|
||||||
NavigationBarTemplate('NavigationBar', '$materialLib/navigation_bar.dart', tokens).updateFile();
|
NavigationBarTemplate('NavigationBar', '$materialLib/navigation_bar.dart', tokens).updateFile();
|
||||||
NavigationRailTemplate('NavigationRail', '$materialLib/navigation_rail.dart', tokens).updateFile();
|
NavigationRailTemplate('NavigationRail', '$materialLib/navigation_rail.dart', tokens).updateFile();
|
||||||
|
@ -4,9 +4,9 @@
|
|||||||
|
|
||||||
import 'template.dart';
|
import 'template.dart';
|
||||||
|
|
||||||
class ChipActionTemplate extends TokenTemplate {
|
class ActionChipTemplate extends TokenTemplate {
|
||||||
|
|
||||||
const ChipActionTemplate(super.blockName, super.fileName, super.tokens);
|
const ActionChipTemplate(super.blockName, super.fileName, super.tokens);
|
||||||
|
|
||||||
static const String tokenGroup = 'md.comp.assist-chip';
|
static const String tokenGroup = 'md.comp.assist-chip';
|
||||||
static const String variant = '.flat';
|
static const String variant = '.flat';
|
@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
import 'template.dart';
|
import 'template.dart';
|
||||||
|
|
||||||
class ChipFilterTemplate extends TokenTemplate {
|
class FilterChipTemplate extends TokenTemplate {
|
||||||
const ChipFilterTemplate(super.blockName, super.fileName, super.tokens);
|
const FilterChipTemplate(super.blockName, super.fileName, super.tokens);
|
||||||
|
|
||||||
static const String tokenGroup = 'md.comp.filter-chip';
|
static const String tokenGroup = 'md.comp.filter-chip';
|
||||||
static const String variant = '.flat';
|
static const String variant = '.flat';
|
@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
import 'template.dart';
|
import 'template.dart';
|
||||||
|
|
||||||
class ChipInputTemplate extends TokenTemplate {
|
class InputChipTemplate extends TokenTemplate {
|
||||||
const ChipInputTemplate(super.blockName, super.fileName, super.tokens);
|
const InputChipTemplate(super.blockName, super.fileName, super.tokens);
|
||||||
|
|
||||||
static const String tokenGroup = 'md.comp.input-chip';
|
static const String tokenGroup = 'md.comp.input-chip';
|
||||||
static const String variant = '';
|
static const String variant = '';
|
Loading…
x
Reference in New Issue
Block a user