diff --git a/packages/command/bin/flutter_gen_command.dart b/packages/command/bin/flutter_gen_command.dart index e334d398..21f33c36 100644 --- a/packages/command/bin/flutter_gen_command.dart +++ b/packages/command/bin/flutter_gen_command.dart @@ -5,7 +5,6 @@ import 'package:flutter_gen_core/flutter_generator.dart'; import 'package:flutter_gen_core/utils/cast.dart'; import 'package:flutter_gen_core/version.gen.dart'; - void main(List args) { final parser = ArgParser(); parser.addOption( diff --git a/packages/command/test/flutter_gen_command_test.dart b/packages/command/test/flutter_gen_command_test.dart index 79faa9ac..e954681d 100644 --- a/packages/command/test/flutter_gen_command_test.dart +++ b/packages/command/test/flutter_gen_command_test.dart @@ -4,7 +4,6 @@ import 'package:flutter_gen_core/version.gen.dart'; import 'package:test/test.dart'; import 'package:test_process/test_process.dart'; - final separator = Platform.pathSeparator; void main() { diff --git a/packages/core/lib/flutter_generator.dart b/packages/core/lib/flutter_generator.dart index d306e333..ead77f5b 100644 --- a/packages/core/lib/flutter_generator.dart +++ b/packages/core/lib/flutter_generator.dart @@ -4,6 +4,7 @@ import 'package:dart_style/dart_style.dart'; import 'package:flutter_gen_core/generators/assets_generator.dart'; import 'package:flutter_gen_core/generators/colors_generator.dart'; import 'package:flutter_gen_core/generators/fonts_generator.dart'; +import 'package:flutter_gen_core/generators/shaders_generator.dart'; import 'package:flutter_gen_core/settings/config.dart'; import 'package:flutter_gen_core/utils/file.dart'; import 'package:path/path.dart'; @@ -15,6 +16,7 @@ class FlutterGenerator { this.assetsName = 'assets.gen.dart', this.colorsName = 'colors.gen.dart', this.fontsName = 'fonts.gen.dart', + this.shadersName = 'shaders.gen.dart', }); final File pubspecFile; @@ -22,6 +24,7 @@ class FlutterGenerator { final String assetsName; final String colorsName; final String fontsName; + final String shadersName; Future build({Config? config, FileWriter? writer}) async { config ??= loadPubspecConfigOrNull(pubspecFile, buildFile: buildFile); @@ -80,6 +83,17 @@ class FlutterGenerator { stdout.writeln('[FlutterGen] Generated: $fontsPath'); } + if (flutterGen.shaders.enabled && flutter.shaders.isNotEmpty) { + final generated = await generateShaders( + ShadersGenConfig.fromConfig(pubspecFile, config), + formatter, + ); + final shadersPath = + normalize(join(pubspecFile.parent.path, output, shadersName)); + writer(generated, shadersPath); + stdout.writeln('[FlutterGen] Generated: $shadersPath'); + } + stdout.writeln('[FlutterGen] Finished generating.'); } } diff --git a/packages/core/lib/generators/shaders_generator.dart b/packages/core/lib/generators/shaders_generator.dart new file mode 100644 index 00000000..c171c6dc --- /dev/null +++ b/packages/core/lib/generators/shaders_generator.dart @@ -0,0 +1,602 @@ +import 'dart:collection'; +import 'dart:io'; + +import 'package:collection/collection.dart'; +import 'package:dart_style/dart_style.dart'; +import 'package:dartx/dartx.dart' hide IterableSorted; +import 'package:flutter_gen_core/generators/generator_helper.dart'; +import 'package:flutter_gen_core/generators/integrations/integration.dart'; +import 'package:flutter_gen_core/settings/config.dart'; +import 'package:flutter_gen_core/settings/flavored_shader.dart'; +import 'package:flutter_gen_core/settings/pubspec.dart'; +import 'package:flutter_gen_core/settings/shader_type.dart'; +import 'package:flutter_gen_core/utils/error.dart'; +import 'package:flutter_gen_core/utils/string.dart'; +import 'package:glob/glob.dart'; +import 'package:path/path.dart'; +import 'package:yaml/yaml.dart'; + +class ShadersGenConfig { + ShadersGenConfig._( + this.rootPath, + this._packageName, + this.flutterGen, + this.shaders, + this.exclude, + ); + + factory ShadersGenConfig.fromConfig(File pubspecFile, Config config) { + return ShadersGenConfig._( + pubspecFile.parent.absolute.path, + config.pubspec.packageName, + config.pubspec.flutterGen, + config.pubspec.flutter.shaders, + config.pubspec.flutterGen.shaders.exclude.map(Glob.new).toList(), + ); + } + + final String rootPath; + final String _packageName; + final FlutterGen flutterGen; + final List shaders; + final List exclude; + + String get packageParameterLiteral => + flutterGen.shaders.outputs.packageParameterEnabled ? _packageName : ''; +} + +Future generateShaders( + ShadersGenConfig config, + DartFormatter formatter, +) async { + if (config.shaders.isEmpty) { + throw const InvalidSettingsException( + 'The value of "flutter/shaders:" is incorrect.', + ); + } + + // ignore: deprecated_member_use_from_same_package + final deprecatedStyle = config.flutterGen.shaders.style != null; + final deprecatedPackageParam = + // ignore: deprecated_member_use_from_same_package + config.flutterGen.shaders.packageParameterEnabled != null; + if (deprecatedStyle || deprecatedPackageParam) { + stderr.writeln(''' + + ░░░░ + + ██ + ██░░██ + ░░ ░░ ██░░░░░░██ ░░░░ + ██░░░░░░░░░░██ + ██░░░░░░░░░░██ + ██░░░░░░░░░░░░░░██ + ██░░░░░░██████░░░░░░██ + ██░░░░░░██████░░░░░░██ + ██░░░░░░░░██████░░░░░░░░██ + ██░░░░░░░░██████░░░░░░░░██ + ██░░░░░░░░░░██████░░░░░░░░░░██ + ██░░░░░░░░░░░░██████░░░░░░░░░░░░██ + ██░░░░░░░░░░░░██████░░░░░░░░░░░░██ + ██░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░██ + ██░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██ + ██░░░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░░░██ + ██░░░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░░░██ + ██░░░░░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░░░░░██ + ░░ ██░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██ + ██████████████████████████████████████████ + + + ░░'''); + } + if (deprecatedStyle && deprecatedPackageParam) { + stderr.writeln(''' + ┌────────────────────────────────────────────────────────────────────────────────────────────────┐ + │ ⚠️ Warning │ + │ The `style` and `package_parameter_enabled` property moved from shader to under shader.output. │ + │ It should be changed in the following pubspec.yaml. │ + │ https://github.com/FlutterGen/flutter_gen/pull/294 │ + │ │ + │ [pubspec.yaml] │ + │ │ + │ flutter_gen: │ + │ shaders: │ + │ outputs: │ + │ style: snake-case │ + │ package_parameter_enabled: true │ + └────────────────────────────────────────────────────────────────────────────────────────────────┘'''); + } else if (deprecatedStyle) { + stderr.writeln(''' + ┌───────────────────────────────────────────────────────────────────────┐ + │ ⚠️ Warning │ + │ The `style` property moved from shader to under shader.output. │ + │ It should be changed in the following ways │ + │ https://github.com/FlutterGen/flutter_gen/pull/294 │ + │ │ + │ [pubspec.yaml] │ + │ │ + │ flutter_gen: │ + │ shaders: │ + │ outputs: │ + │ style: snake-case │ + └───────────────────────────────────────────────────────────────────────┘'''); + } else if (deprecatedPackageParam) { + stderr.writeln(''' + ┌────────────────────────────────────────────────────────────────────────────────────────┐ + │ ⚠️ Warning │ + │ The `package_parameter_enabled` property moved from shader to under shader.output. │ + │ It should be changed in the following pubspec.yaml. │ + │ https://github.com/FlutterGen/flutter_gen/pull/294 │ + │ │ + │ [pubspec.yaml] │ + │ │ + │ flutter_gen: │ + │ shaders: │ + │ outputs: │ + │ package_parameter_enabled: true │ + └────────────────────────────────────────────────────────────────────────────────────────┘'''); + } + + final classesBuffer = StringBuffer(); + if (config.flutterGen.shaders.outputs.isDotDelimiterStyle) { + final definition = await _dotDelimiterStyleDefinition(config); + classesBuffer.writeln(definition); + } else if (config.flutterGen.shaders.outputs.isSnakeCaseStyle) { + final definition = await _snakeCaseStyleDefinition(config); + classesBuffer.writeln(definition); + } else if (config.flutterGen.shaders.outputs.isCamelCaseStyle) { + final definition = await _camelCaseStyleDefinition(config); + classesBuffer.writeln(definition); + } else { + throw 'The value of "flutter_gen/shaders/style." is incorrect.'; + } + + final imports = {}; + + final importsBuffer = StringBuffer(); + for (final e in imports.sorted((a, b) => a.import.compareTo(b.import))) { + importsBuffer.writeln(import(e)); + } + + final buffer = StringBuffer(); + buffer.writeln(header); + buffer.writeln(ignore); + buffer.writeln(importsBuffer.toString()); + buffer.writeln(classesBuffer.toString()); + return formatter.format(buffer.toString()); +} + +String? generateShadersPackageNameForConfig(ShadersGenConfig config) { + if (config.flutterGen.shaders.outputs.packageParameterEnabled) { + return config._packageName; + } else { + return null; + } +} + +/// Returns a list of all relative path shaders that are to be considered. +List _getShaderRelativePathList( + /// The absolute root path of the shaders directory. + String rootPath, + + /// List of shaders as provided the `flutter -> shaders` + /// section in the pubspec.yaml. + List shaders, + + /// List of globs as provided the `flutter_gen -> shaders -> exclude` + /// section in the pubspec.yaml. + List excludes, +) { + // Normalize. + final normalizedShaders = {...shaders.whereType()}; + final normalizingMap = >{}; + // Resolve flavored shaders. + for (final map in shaders.whereType()) { + final path = (map['path'] as String).trim(); + final flavors = + (map['flavors'] as YamlList?)?.toSet().cast() ?? {}; + if (normalizingMap.containsKey(path)) { + // https://github.com/flutter/flutter/blob/5187cab7bdd434ca74abb45895d17e9fa553678a/packages/flutter_tools/lib/src/shader.dart#L1137-L1139 + throw StateError( + 'Multiple shaders entries include the file "$path", ' + 'but they specify different lists of flavors.', + ); + } + normalizingMap[path] = flavors; + } + for (final entry in normalizingMap.entries) { + normalizedShaders.add( + YamlMap.wrap({'path': entry.key, 'flavors': entry.value}), + ); + } + + final shaderRelativePathList = []; + for (final shader in normalizedShaders) { + final FlavoredShader tempShader; + if (shader is YamlMap) { + tempShader = + FlavoredShader(path: shader['path'], flavors: shader['flavors']); + } else { + tempShader = FlavoredShader(path: (shader as String).trim()); + } + final shaderAbsolutePath = join(rootPath, tempShader.path); + if (FileSystemEntity.isDirectorySync(shaderAbsolutePath)) { + shaderRelativePathList.addAll(Directory(shaderAbsolutePath) + .listSync() + .whereType() + .map( + (e) => tempShader.copyWith(path: relative(e.path, from: rootPath)), + ) + .toList()); + } else if (FileSystemEntity.isFileSync(shaderAbsolutePath)) { + shaderRelativePathList.add( + tempShader.copyWith(path: relative(shaderAbsolutePath, from: rootPath)), + ); + } + } + + if (excludes.isEmpty) { + return shaderRelativePathList; + } + return shaderRelativePathList + .where( + (shader) => !excludes.any((exclude) => exclude.matches(shader.path))) + .toList(); +} + +ShaderType _constructShaderTree( + List shaderRelativePathList, + String rootPath, +) { + // Relative path is the key + final shaderTypeMap = { + '.': ShaderType(rootPath: rootPath, path: '.', flavors: {}), + }; + for (final shader in shaderRelativePathList) { + String path = shader.path; + while (path != '.') { + shaderTypeMap.putIfAbsent( + path, + () => + ShaderType(rootPath: rootPath, path: path, flavors: shader.flavors), + ); + path = dirname(path); + } + } + // Construct the ShaderType tree + for (final shaderType in shaderTypeMap.values) { + if (shaderType.path == '.') { + continue; + } + final parentPath = dirname(shaderType.path); + shaderTypeMap[parentPath]?.addChild(shaderType); + } + return shaderTypeMap['.']!; +} + +Future<_Statement?> _createShaderTypeStatement( + ShadersGenConfig config, + UniqueShaderType shaderType, +) async { + final childShaderAbsolutePath = join(config.rootPath, shaderType.path); + if (FileSystemEntity.isDirectorySync(childShaderAbsolutePath)) { + final childClassName = '\$${shaderType.path.camelCase().capitalize()}Gen'; + return _Statement( + type: childClassName, + filePath: shaderType.posixStylePath, + name: shaderType.name, + value: '$childClassName()', + isConstConstructor: true, + isDirectory: true, + needDartDoc: false, + ); + } else if (!shaderType.isIgnoreFile) { + var shaderKey = shaderType.posixStylePath; + if (config.flutterGen.shaders.outputs.packageParameterEnabled) { + shaderKey = 'packages/${config._packageName}/$shaderKey'; + } + return _Statement( + type: 'String', + filePath: shaderType.posixStylePath, + name: shaderType.name, + value: '\'$shaderKey\'', + isConstConstructor: false, + isDirectory: false, + needDartDoc: true, + ); + } + return null; +} + +/// Generate style like Shaders.foo.bar +Future _dotDelimiterStyleDefinition( + ShadersGenConfig config, +) async { + final rootPath = Directory(config.rootPath).absolute.uri.toFilePath(); + final buffer = StringBuffer(); + final className = config.flutterGen.shaders.outputs.className; + final shaderRelativePathList = _getShaderRelativePathList( + rootPath, + config.shaders, + config.exclude, + ); + final shadersStaticStatements = <_Statement>[]; + + final shaderTypeQueue = ListQueue.from( + _constructShaderTree(shaderRelativePathList, rootPath).children, + ); + + while (shaderTypeQueue.isNotEmpty) { + final shaderType = shaderTypeQueue.removeFirst(); + String shaderPath = join(rootPath, shaderType.path); + final isDirectory = FileSystemEntity.isDirectorySync(shaderPath); + if (isDirectory) { + shaderPath = Directory(shaderPath).absolute.uri.toFilePath(); + } else { + shaderPath = File(shaderPath).absolute.uri.toFilePath(); + } + + final isRootShader = !isDirectory && + File(shaderPath).parent.absolute.uri.toFilePath() == rootPath; + // Handles directories, and explicitly handles root path shaders. + if (isDirectory || isRootShader) { + final List<_Statement?> results = await Future.wait( + shaderType.children + .mapToUniqueShaderType(camelCase, justBasename: true) + .map( + (e) => _createShaderTypeStatement(config, e), + ), + ); + final statements = results.whereType<_Statement>().toList(); + + if (shaderType.isDefaultShadersDirectory) { + shadersStaticStatements.addAll(statements); + } else if (!isDirectory && isRootShader) { + // Creates explicit statement. + final statement = await _createShaderTypeStatement( + config, + UniqueShaderType(shaderType: shaderType, style: camelCase), + ); + shadersStaticStatements.add(statement!); + } else { + final className = '\$${shaderType.path.camelCase().capitalize()}Gen'; + buffer.writeln( + _directoryClassGenDefinition( + className, + statements, + config.flutterGen.shaders.outputs.directoryPathEnabled + ? shaderType.posixStylePath + : null, + ), + ); + // Add this directory reference to Shaders class + // if we are not under the default shader folder + if (dirname(shaderType.path) == '.') { + shadersStaticStatements.add(_Statement( + type: className, + filePath: shaderType.posixStylePath, + name: shaderType.baseName.camelCase(), + value: '$className()', + isConstConstructor: true, + isDirectory: true, + needDartDoc: true, + )); + } + } + + shaderTypeQueue.addAll(shaderType.children); + } + } + final String? packageName = generateShadersPackageNameForConfig(config); + buffer.writeln( + _dotDelimiterStyleShadersClassDefinition( + className, + shadersStaticStatements, + packageName, + ), + ); + return buffer.toString(); +} + +/// Generate style like Shaders.foo_bar +Future _snakeCaseStyleDefinition( + ShadersGenConfig config, +) { + return _flatStyleDefinition( + config, + snakeCase, + ); +} + +/// Generate style like Shaders.fooBar +Future _camelCaseStyleDefinition( + ShadersGenConfig config, +) { + return _flatStyleDefinition( + config, + camelCase, + ); +} + +Future _flatStyleDefinition( + ShadersGenConfig config, + String Function(String) style, +) async { + final List paths = _getShaderRelativePathList( + config.rootPath, + config.shaders, + config.exclude, + ); + paths.sort(((a, b) => a.path.compareTo(b.path))); + final List<_Statement?> results = await Future.wait( + paths + .map( + (shaderPath) => ShaderType( + rootPath: config.rootPath, + path: shaderPath.path, + flavors: shaderPath.flavors, + ), + ) + .mapToUniqueShaderType(style) + .map( + (e) => _createShaderTypeStatement( + config, + e, + ), + ), + ); + final statements = results.whereType<_Statement>().toList(); + final className = config.flutterGen.shaders.outputs.className; + final String? packageName = generateShadersPackageNameForConfig(config); + return _flatStyleShadersClassDefinition(className, statements, packageName); +} + +String _flatStyleShadersClassDefinition( + String className, + List<_Statement> statements, + String? packageName, +) { + final statementsBlock = + statements.map((statement) => '''${statement.toDartDocString()} + ${statement.toStaticFieldString()} + ''').join('\n'); + final valuesBlock = _shaderValuesDefinition(statements, static: true); + return _shadersClassDefinition( + className, + statements, + statementsBlock, + valuesBlock, + packageName, + ); +} + +String _dotDelimiterStyleShadersClassDefinition( + String className, + List<_Statement> statements, + String? packageName, +) { + final statementsBlock = + statements.map((statement) => statement.toStaticFieldString()).join('\n'); + final valuesBlock = _shaderValuesDefinition(statements, static: true); + return _shadersClassDefinition( + className, + statements, + statementsBlock, + valuesBlock, + packageName, + ); +} + +String _shaderValuesDefinition( + List<_Statement> statements, { + bool static = false, +}) { + final values = statements.where((element) => !element.isDirectory); + if (values.isEmpty) return ''; + final names = values.map((value) => value.name).join(', '); + final type = values.every((element) => element.type == values.first.type) + ? values.first.type + : 'dynamic'; + + return ''' + /// List of all shaders + ${static ? 'static ' : ''}List<$type> get values => [$names];'''; +} + +String _shadersClassDefinition( + String className, + List<_Statement> statements, + String statementsBlock, + String valuesBlock, + String? packageName, +) { + return ''' +class $className { + $className._(); +${packageName != null ? "\n static const String package = '$packageName';" : ''} + + $statementsBlock + $valuesBlock +} +'''; +} + +String _directoryClassGenDefinition( + String className, + List<_Statement> statements, + String? directoryPath, +) { + final statementsBlock = statements.map((statement) { + final buffer = StringBuffer(); + if (statement.needDartDoc) { + buffer.writeln(statement.toDartDocString()); + } + buffer.writeln(statement.toGetterString()); + return buffer.toString(); + }).join('\n'); + final pathBlock = directoryPath != null + ? ''' + /// Directory path: $directoryPath + String get path => '$directoryPath'; +''' + : ''; + final valuesBlock = _shaderValuesDefinition(statements); + + return ''' +class $className { + const $className(); + + $statementsBlock + $pathBlock + $valuesBlock +} +'''; +} + +/// The generated statement for each shader, e.g +/// '$type get $name => ${isConstConstructor ? 'const' : ''} $value;'; +class _Statement { + const _Statement({ + required this.type, + required this.filePath, + required this.name, + required this.value, + required this.isConstConstructor, + required this.isDirectory, + required this.needDartDoc, + }); + + /// The type of this shader, e.g ShaderGenImage, SvgGenImage, String, etc. + final String type; + + /// The relative path of this shader from the root directory. + final String filePath; + + /// The variable name of this shader. + final String name; + + /// The code to instantiate this shader. e.g `ShaderGenImage('shaders/image.png');` + final String value; + + final bool isConstConstructor; + final bool isDirectory; + final bool needDartDoc; + + String toDartDocString() => '/// File path: $filePath'; + + String toGetterString() { + final buffer = StringBuffer(''); + if (isDirectory) { + buffer.writeln( + '/// Directory path: ' + '${Directory(filePath).path.replaceAll(r'\', r'/')}', + ); + } + buffer.writeln( + '$type get $name => ${isConstConstructor ? 'const' : ''} $value;', + ); + return buffer.toString(); + } + + String toStaticFieldString() => 'static const $type $name = $value;'; +} diff --git a/packages/core/lib/settings/config_default.dart b/packages/core/lib/settings/config_default.dart index d5ba4cef..93756bc9 100644 --- a/packages/core/lib/settings/config_default.dart +++ b/packages/core/lib/settings/config_default.dart @@ -41,6 +41,24 @@ flutter_gen: outputs: class_name: FontFamily + shaders: + # Optional + enabled: true + # Optional + outputs: + # Optional + # Set to true if you want this package to be a package dependency + # See: https://flutter.dev/docs/development/ui/assets-and-images#from-packages + package_parameter_enabled: false + # Optional + # Available values: + # - camel-case + # - snake-case + # - dot-delimiter + style: dot-delimiter + class_name: Shaders + exclude: [] + colors: # Optional enabled: true @@ -55,4 +73,6 @@ flutter: assets: [] # See: https://flutter.dev/docs/cookbook/design/fonts#2-declare-the-font-in-the-pubspec fonts: [] + # See: https://docs.flutter.dev/ui/design/graphics/fragment-shaders + shaders: [] '''; diff --git a/packages/core/lib/settings/flavored_shader.dart b/packages/core/lib/settings/flavored_shader.dart new file mode 100644 index 00000000..f0ef83b5 --- /dev/null +++ b/packages/core/lib/settings/flavored_shader.dart @@ -0,0 +1,19 @@ +class FlavoredShader { + const FlavoredShader({ + required this.path, + this.flavors = const {}, + }); + + final String path; + final Set flavors; + + FlavoredShader copyWith({String? path, Set? flavors}) { + return FlavoredShader( + path: path ?? this.path, + flavors: flavors ?? this.flavors, + ); + } + + @override + String toString() => 'FlavoredShader(path: $path, flavors: $flavors)'; +} diff --git a/packages/core/lib/settings/pubspec.dart b/packages/core/lib/settings/pubspec.dart index 6f8b9649..587cb37c 100644 --- a/packages/core/lib/settings/pubspec.dart +++ b/packages/core/lib/settings/pubspec.dart @@ -29,6 +29,7 @@ class Flutter { Flutter({ required this.assets, required this.fonts, + required this.shaders, }); @JsonKey(name: 'assets', required: true) @@ -37,6 +38,9 @@ class Flutter { @JsonKey(name: 'fonts', required: true) final List fonts; + @JsonKey(name: 'shaders', required: true) + final List shaders; + factory Flutter.fromJson(Map json) => _$FlutterFromJson(json); } @@ -58,6 +62,7 @@ class FlutterGen { required this.parseMetadata, required this.assets, required this.fonts, + required this.shaders, required this.integrations, required this.colors, }); @@ -77,6 +82,9 @@ class FlutterGen { @JsonKey(name: 'fonts', required: true) final FlutterGenFonts fonts; + @JsonKey(name: 'shaders', required: true) + final FlutterGenAssets shaders; + @JsonKey(name: 'integrations', required: true) final FlutterGenIntegrations integrations; diff --git a/packages/core/lib/settings/pubspec.g.dart b/packages/core/lib/settings/pubspec.g.dart index 88be3070..b349f964 100644 --- a/packages/core/lib/settings/pubspec.g.dart +++ b/packages/core/lib/settings/pubspec.g.dart @@ -32,7 +32,7 @@ Flutter _$FlutterFromJson(Map json) => $checkedCreate( ($checkedConvert) { $checkKeys( json, - requiredKeys: const ['assets', 'fonts'], + requiredKeys: const ['assets', 'fonts', 'shaders'], ); final val = Flutter( assets: $checkedConvert('assets', @@ -42,6 +42,8 @@ Flutter _$FlutterFromJson(Map json) => $checkedCreate( (v) => (v as List) .map((e) => FlutterFonts.fromJson(e as Map)) .toList()), + shaders: $checkedConvert('shaders', + (v) => (v as List).map((e) => e as Object).toList()), ); return val; }, @@ -74,6 +76,7 @@ FlutterGen _$FlutterGenFromJson(Map json) => $checkedCreate( 'parse_metadata', 'assets', 'fonts', + 'shaders', 'integrations', 'colors' ], @@ -86,6 +89,8 @@ FlutterGen _$FlutterGenFromJson(Map json) => $checkedCreate( 'assets', (v) => FlutterGenAssets.fromJson(v as Map)), fonts: $checkedConvert( 'fonts', (v) => FlutterGenFonts.fromJson(v as Map)), + shaders: $checkedConvert( + 'shaders', (v) => FlutterGenAssets.fromJson(v as Map)), integrations: $checkedConvert( 'integrations', (v) => FlutterGenIntegrations.fromJson(v as Map)), colors: $checkedConvert( diff --git a/packages/core/lib/settings/shader_type.dart b/packages/core/lib/settings/shader_type.dart new file mode 100644 index 00000000..9fef28c1 --- /dev/null +++ b/packages/core/lib/settings/shader_type.dart @@ -0,0 +1,218 @@ +import 'package:dartx/dartx.dart'; +import 'package:flutter_gen_core/utils/identifer.dart'; +import 'package:flutter_gen_core/utils/string.dart'; +import 'package:mime/mime.dart' show lookupMimeType; +import 'package:path/path.dart' as p; + +/// https://github.com/dart-lang/mime/blob/master/lib/src/default_extension_map.dart +class ShaderType { + ShaderType({ + required this.rootPath, + required this.path, + required this.flavors, + }); + + final String rootPath; + final String path; + final Set flavors; + + final List _children = List.empty(growable: true); + + bool get isDefaultShadersDirectory => path == 'shaders' || path == 'shader'; + + String? get mime => lookupMimeType(path); + + bool get isIgnoreFile { + switch (baseName) { + case '.DS_Store': + return true; + } + + switch (extension) { + case '.DS_Store': + case '.swp': + return true; + } + + return false; + } + + bool get isUnKnownMime => mime == null; + + /// Returns a name for this shader. + String get name => p.withoutExtension(path); + + String get baseName => p.basenameWithoutExtension(path); + + String get extension => p.extension(path); + + /// Returns the full absolute path for reading the shader file. + String get fullPath => p.join(rootPath, path); + + // Replace to Posix style for Windows separator. + String get posixStylePath => path.replaceAll(r'\', r'/'); + + List get children => _children.sortedBy((e) => e.path); + + void addChild(ShaderType type) { + _children.add(type); + } + + @override + String toString() => 'ShaderType(' + 'rootPath: $rootPath, ' + 'path: $path, ' + 'flavors: $flavors' + ')'; +} + +/// Represents a ShaderType with modifiers on it to mutate the [name] to ensure +/// it is unique in a larger list and a valid dart identifer. +/// +/// See [ShaderTypeIterable.mapToUniqueShaderType] for the algorithm. +class UniqueShaderType extends ShaderType { + UniqueShaderType({ + required ShaderType shaderType, + this.style = camelCase, + this.basenameOnly = false, + this.needExtension = false, + this.suffix = '', + }) : super( + rootPath: shaderType.rootPath, + path: shaderType.path, + flavors: shaderType.flavors, + ); + + /// Convert the shader name to a correctly styled name, e.g camelCase or + /// snakeCase. + final String Function(String) style; + + /// Include just the basename of the shader in the [name], + /// e.g. 'images/image.png' -> 'image'. + final bool basenameOnly; + + /// Include the extension in the [name], e.g. 'image.png' -> 'imagePng'. + bool needExtension; + + /// Optional suffix to append to the [name] to make it unique. Typically just + /// one or more '_' characters. + String suffix; + + /// Returns a identifier name, which is ideally unique and valid. + @override + String get name { + // Omit root directory from the name if it is either shader or shaders. + // TODO(bramp): Maybe move this into the _flatStyleDefinition + String result = path.replaceFirst(RegExp(r'^shader(s)?[/\\]'), ''); + if (basenameOnly) { + result = p.basename(result); + } + if (!needExtension) { + result = p.withoutExtension(result); + } + return style(convertToIdentifier(result)) + suffix; + } + + @override + String toString() { + return 'UniqueShaderType{' + 'rootPath: $rootPath, ' + 'path: $path, ' + 'style: $style, ' + 'needExtension: $needExtension, ' + 'suffix: $suffix}'; + } +} + +extension ShaderTypeIterable on Iterable { + /// Takes a Iterable and mutates the ShaderType's to ensure each + /// ShaderType has a unique name. + /// + /// The strategy is as follows: + /// + /// 1) Convert the shader file name, to a valid dart identifier, that is + /// - Replace non ASCII chars with ASCII. + /// - Ensure the name starts with a letter (not number or _). + /// - Style the name per the camelCase or snakeCase rules. + /// 2) Use the shader name without extension. If unique and not a dart reserved + /// word use that. + /// 3) Use the shader name with extension. If unique and not a dart reserved + /// word use that. + /// 4) If there are any collisions, append a underscore suffix to each item + /// until they are unique. + /// + /// Because the name change can cause it to clash with an existing name, the + /// code is run iteratively until no collision are found. This can be a little + /// more expensive, but it simplier. + /// + Iterable mapToUniqueShaderType( + String Function(String) style, { + bool justBasename = false, + }) { + List shaders = map((e) => UniqueShaderType( + shaderType: e, + style: style, + needExtension: false, + suffix: '', + basenameOnly: justBasename, + )).toList(); + + while (true) { + // Check if we have any name collisions. + final dups = shaders.groupBy((e) => e.name).values; + + // No more duplicates, so we can bail. + if (dups.every((list) => list.length == 1)) break; + + // Otherwise start to process the list and mutate the shaders as needed. + shaders = dups + .map((list) { + assert(list.isNotEmpty, + 'The groupBy list of shaders should not be empty.'); + + // Check the first element in the list. Since we grouped by each + // list element should have the same name. + final name = list[0].name; + final isValidIdentifer = isValidVariableIdentifier(name); + + // TODO(bramp): In future we should also check this name doesn't collide + // with the integration's class name (e.g ShaderGenImage). + + // No colissions for this name, carry on. + if (list.length == 1 && isValidIdentifer) { + return list; + } + + // We haven't added filename extensions yet, let's try that first + if (!list.every((e) => e.needExtension)) { + for (final e in list) { + e.needExtension = true; + } + + return list; + } + + // Ok, we must resolve the conflicts by adding suffixes. + String suffix = ''; + list.forEachIndexed((shader, index) { + // Shouldn't need to mutate the first item (unless it's an invalid + // identifer). + if (index == 0 && isValidIdentifer) return; + + // Append a extra suffixes to each item so they hopefully become unique + suffix = '${suffix}_'; + shader.suffix += suffix; + }); + + return list; + }) + .flatten() + .toList(); + } + + assert(shaders.map((e) => e.name).distinct().length == shaders.length, + 'There are duplicate names in the shader list.'); + + return shaders; + } +} diff --git a/packages/core/test/flutter_gen_test.dart b/packages/core/test/flutter_gen_test.dart index 4b269d96..a78e13ac 100644 --- a/packages/core/test/flutter_gen_test.dart +++ b/packages/core/test/flutter_gen_test.dart @@ -186,6 +186,7 @@ void main() { const assets = 'build_assets.gen.dart'; const colors = 'build_colors.gen.dart'; const fonts = 'build_fonts.gen.dart'; + const shaders = 'build_shaders.gen.dart'; await FlutterGenerator( File(pubspec), @@ -193,6 +194,7 @@ void main() { assetsName: assets, colorsName: colors, fontsName: fonts, + shadersName: shaders, ).build(); expect(File('test_resources/lib/build_gen/$assets').readAsStringSync(), isNotEmpty); @@ -200,6 +202,8 @@ void main() { isNotEmpty); expect(File('test_resources/lib/build_gen/$colors').readAsStringSync(), isNotEmpty); + expect(File('test_resources/lib/build_gen/$shaders').readAsStringSync(), + isNotEmpty); }); }); } diff --git a/packages/core/test/gen_test_helper.dart b/packages/core/test/gen_test_helper.dart index 917dd354..a37efefd 100644 --- a/packages/core/test/gen_test_helper.dart +++ b/packages/core/test/gen_test_helper.dart @@ -5,6 +5,7 @@ import 'package:flutter_gen_core/flutter_generator.dart'; import 'package:flutter_gen_core/generators/assets_generator.dart'; import 'package:flutter_gen_core/generators/colors_generator.dart'; import 'package:flutter_gen_core/generators/fonts_generator.dart'; +import 'package:flutter_gen_core/generators/shaders_generator.dart'; import 'package:flutter_gen_core/settings/config.dart'; import 'package:path/path.dart' as p; import 'package:test/test.dart'; @@ -131,6 +132,40 @@ Future> runFontsGen( return [actual, expected]; } +Future> runShadersGen( + String pubspec, + String generated, + String fact, { + String? build, +}) async { + final pubspecFile = File(pubspec); + + File? buildFile; + if (build != null) buildFile = File(build); + + await FlutterGenerator( + pubspecFile, + buildFile: buildFile, + shadersName: p.basename(generated), + ).build(); + + final config = loadPubspecConfig(pubspecFile, buildFile: buildFile); + final formatter = DartFormatter( + pageWidth: config.pubspec.flutterGen.lineLength, + lineEnding: '\n', + ); + + final actual = await generateShaders( + ShadersGenConfig.fromConfig(pubspecFile, config), + formatter, + ); + File(fact).writeAsStringSync(actual); + final expected = formatter.format( + File(fact).readAsStringSync().replaceAll('\r\n', '\n'), + ); + return [actual, expected]; +} + /// Fonts Future expectedFontsGen( String pubspec, @@ -146,6 +181,22 @@ Future expectedFontsGen( expect(actual, expected); } +/// Shaders +Future expectedShadersGen( + String pubspec, + String generated, + String fact, { + String? build, +}) async { + final results = await runShadersGen(pubspec, generated, fact, build: build); + final actual = results.first, expected = results.last; + expect( + File(generated).readAsStringSync(), + isNotEmpty, + ); + expect(actual, expected); +} + /// Verify generated package name. void expectedPackageNameGen( String pubspec, @@ -159,3 +210,17 @@ void expectedPackageNameGen( final actual = generatePackageNameForConfig(config); expect(actual, equals(fact)); } + +/// Verify shaders generated package name. +void expectedShadersPackageNameGen( + String pubspec, + String? fact, +) { + final pubspecFile = File(pubspec); + final config = ShadersGenConfig.fromConfig( + pubspecFile, + loadPubspecConfig(pubspecFile), + ); + final actual = generateShadersPackageNameForConfig(config); + expect(actual, equals(fact)); +} diff --git a/packages/core/test/shaders_gen_test.dart b/packages/core/test/shaders_gen_test.dart new file mode 100644 index 00000000..047dabb5 --- /dev/null +++ b/packages/core/test/shaders_gen_test.dart @@ -0,0 +1,234 @@ +import 'dart:io'; + +import 'package:dart_style/dart_style.dart'; +import 'package:dartx/dartx.dart'; +import 'package:flutter_gen_core/generators/shaders_generator.dart'; +import 'package:flutter_gen_core/settings/config.dart'; +import 'package:flutter_gen_core/settings/shader_type.dart'; +import 'package:flutter_gen_core/utils/error.dart'; +import 'package:flutter_gen_core/utils/string.dart'; +import 'package:test/test.dart'; + +import 'gen_test_helper.dart'; + +void main() { + group('Test Shaders generator', () { + test('Shaders on pubspec.yaml', () async { + const pubspec = 'test_resources/pubspec_shaders.yaml'; + const fact = 'test_resources/actual_data/shaders/shaders.gen.dart'; + const generated = 'test_resources/lib/gen/shaders.gen.dart'; + + await expectedShadersGen(pubspec, generated, fact); + }); + + test('Shaders snake-case style on pubspec.yaml', () async { + const pubspec = 'test_resources/pubspec_shaders_snake_case.yaml'; + const fact = + 'test_resources/actual_data/shaders/shaders_snake_case.gen.dart'; + const generated = 'test_resources/lib/gen/shaders_snake_case.gen.dart'; + + await expectedShadersGen(pubspec, generated, fact); + }); + + test('Shaders camel-case style on pubspec.yaml', () async { + const pubspec = 'test_resources/pubspec_shaders_camel_case.yaml'; + const fact = + 'test_resources/actual_data/shaders/shaders_camel_case.gen.dart'; + const generated = 'test_resources/lib/gen/shaders_camel_case.gen.dart'; + + await expectedShadersGen(pubspec, generated, fact); + }); + + test('Shaders with No lists on pubspec.yaml', () async { + final pubspec = File('test_resources/pubspec_shaders_no_list.yaml'); + final config = loadPubspecConfig(pubspec); + final formatter = DartFormatter( + pageWidth: config.pubspec.flutterGen.lineLength, lineEnding: '\n'); + + expect(() { + return generateShaders( + ShadersGenConfig.fromConfig(pubspec, config), formatter); + }, throwsA(isA())); + }); + + test('Shaders with directory path enabled', () async { + const pubspec = 'test_resources/pubspec_shaders_directory_path.yaml'; + const fact = + 'test_resources/actual_data/shaders/shaders_directory_path.gen.dart'; + const generated = + 'test_resources/lib/gen/shaders_directory_path.gen.dart'; + await expectedShadersGen(pubspec, generated, fact); + }); + + test('Shaders with excluded files and directories', () async { + const pubspec = 'test_resources/pubspec_shaders_exclude_files.yaml'; + const fact = + 'test_resources/actual_data/shaders/shaders_package_exclude_files.gen.dart'; + const generated = + 'test_resources/lib/gen/shaders_package_exclude_files.gen.dart'; + + await expectedShadersGen(pubspec, generated, fact); + }); + + test('Shaders with change the class name', () async { + const pubspec = 'test_resources/pubspec_shaders_change_class_name.yaml'; + const fact = + 'test_resources/actual_data/shaders/shaders_change_class_name.gen.dart'; + const generated = + 'test_resources/lib/gen/shaders_change_class_name.gen.dart'; + + await expectedShadersGen(pubspec, generated, fact); + }); + + test('Shaders with parse metadata enabled', () async { + const pubspec = 'test_resources/pubspec_shaders_parse_metadata.yaml'; + const fact = + 'test_resources/actual_data/shaders/shaders_parse_metadata.gen.dart'; + const generated = + 'test_resources/lib/gen/shaders_parse_metadata.gen.dart'; + + await expectedShadersGen(pubspec, generated, fact); + }); + + test('Shaders with flavored shaders', () async { + const pubspec = 'test_resources/pubspec_shaders_flavored.yaml'; + const fact = + 'test_resources/actual_data/shaders/shaders_flavored.gen.dart'; + const generated = 'test_resources/lib/gen/shaders_flavored.gen.dart'; + + await expectedShadersGen(pubspec, generated, fact); + }); + + test('Shaders with duplicate flavoring entries', () async { + const pubspec = + 'test_resources/pubspec_shaders_flavored_duplicate_entry.yaml'; + const fact = + 'test_resources/actual_data/shaders/shaders_flavored_duplicate_entry.gen.dart'; + const generated = + 'test_resources/lib/gen/shaders_flavored_duplicate_entry.gen.dart'; + + await expectLater( + () => runShadersGen(pubspec, generated, fact), + throwsA(isA()), + ); + }); + + test('Shaders with terrible names (camelCase)', () async { + // See [ShaderTypeIterable.mapToUniqueShaderType] for the rules for picking + // identifer names. + final tests = { + 'shaders/single.jpg': 'single', + + // Two shaders with overlapping names + 'shaders/logo.jpg': 'logoJpg', + 'shaders/logo.png': 'logoPng', + + // Two shaders with overlapping names, which when re-written overlaps with a 3rd. + 'shaders/profile.jpg': 'profileJpg', + 'shaders/profile.png': 'profilePng', + 'shaders/profilePng.jpg': 'profilePngJpg', + + // Shader overlapping with a directory name. + 'shaders/image': 'image', + // Directory + 'shaders/image.jpg': 'imageJpg', + + // Shader with no base name (but ends up overlapping the previous shader) + 'shaders/image/.jpg': 'imageJpg_', + + // Shader with non-ascii names + // TODO(bramp): Ideally would be 'francais' but that requires a heavy + // package that can transliterate non-ascii chars. + 'shaders/français.jpg': 'franAis', + + // Dart Reserved Words + // allowed + 'shaders/async.png': 'async', + // allowed + 'shaders/abstract.png': 'abstract', + // must be suffixed (but can use Png) + 'shaders/await.png': 'awaitPng', + // must be suffixed (but can use Png) + 'shaders/assert.png': 'assertPng', + // must be suffixed + 'shaders/await': 'await_', + // must be suffixed + 'shaders/assert': 'assert_', + + // Shader with a number as the first character + 'shaders/7up.png': 'a7up', + 'shaders/123.png': 'a123', + + // Case gets dropped with CamelCase (can causes conflict) + 'shaders/z.png': 'zPng', + 'shaders/Z.png': 'zPng_', + + // Case gets corrected. + 'shaders/CHANGELOG.md': 'changelog', + }; + + final List shaders = tests.keys + .sorted() + .map((e) => ShaderType(rootPath: '', path: e, flavors: {})) + .toList(); + + final got = shaders.mapToUniqueShaderType(camelCase); + + // Expect no duplicates. + final names = got.map((e) => e.name); + expect(names.sorted(), tests.values.sorted()); + }); + + test( + 'Shaders on pubspec_shaders.yaml and override with build_assets.yaml ', + () async { + const pubspec = 'test_resources/pubspec_shaders.yaml'; + const build = 'test_resources/build_assets.yaml'; + const fact = + 'test_resources/actual_data/shaders/build_shaders.gen.dart'; + const generated = 'test_resources/lib/build_gen/shaders.gen.dart'; + + await expectedShadersGen(pubspec, generated, fact, build: build); + }, + ); + + test( + 'Shaders on pubspec_shaders.yaml and override with build_runner_assets.yaml ', + () async { + const pubspec = 'test_resources/pubspec_shaders.yaml'; + const build = 'test_resources/build_runner_assets.yaml'; + const fact = + 'test_resources/actual_data/shaders/build_runner_shaders.gen.dart'; + const generated = 'test_resources/lib/build_gen/shaders.gen.dart'; + + await expectedShadersGen(pubspec, generated, fact, build: build); + }, + ); + + test( + 'Shaders on pubspec_shaders.yaml and override with build_empty.yaml ', + () async { + const pubspec = 'test_resources/pubspec_shaders.yaml'; + const build = 'test_resources/build_empty.yaml'; + const fact = 'test_resources/actual_data/shaders/build_empty.gen.dart'; + const generated = 'test_resources/lib/build_gen/shaders.gen.dart'; + + await expectedShadersGen(pubspec, generated, fact, build: build); + }, + ); + }); + + group('Test generatePackageNameForConfig', () { + test('Shaders on pubspec.yaml', () { + const pubspec = 'test_resources/pubspec_shaders.yaml'; + const fact = null; + expectedShadersPackageNameGen(pubspec, fact); + }); + + test('Shaders with package parameter enabled', () { + const pubspec = 'test_resources/pubspec_shaders_package_parameter.yaml'; + const fact = 'test'; + expectedShadersPackageNameGen(pubspec, fact); + }); + }); +} diff --git a/packages/core/test_resources/actual_data/build_assets.gen.dart b/packages/core/test_resources/actual_data/build_assets.gen.dart index 09e91354..482e6044 100644 --- a/packages/core/test_resources/actual_data/build_assets.gen.dart +++ b/packages/core/test_resources/actual_data/build_assets.gen.dart @@ -56,13 +56,16 @@ class $AssetsImagesGen { AssetGenImage get logo => const AssetGenImage('assets/images/logo.png'); /// File path: assets/images/profile.jpg - AssetGenImage get profileJpg => const AssetGenImage('assets/images/profile.jpg'); + AssetGenImage get profileJpg => + const AssetGenImage('assets/images/profile.jpg'); /// File path: assets/images/profile.png - AssetGenImage get profilePng => const AssetGenImage('assets/images/profile.png'); + AssetGenImage get profilePng => + const AssetGenImage('assets/images/profile.png'); /// List of all assets - List get values => [chip1, chip2, logo, profileJpg, profilePng]; + List get values => + [chip1, chip2, logo, profileJpg, profilePng]; } class $AssetsJsonGen { @@ -102,7 +105,8 @@ class $AssetsImagesChip3Gen { const $AssetsImagesChip3Gen(); /// File path: assets/images/chip3/chip3.jpg - AssetGenImage get chip3 => const AssetGenImage('assets/images/chip3/chip3.jpg'); + AssetGenImage get chip3 => + const AssetGenImage('assets/images/chip3/chip3.jpg'); /// List of all assets List get values => [chip3]; @@ -112,7 +116,8 @@ class $AssetsImagesChip4Gen { const $AssetsImagesChip4Gen(); /// File path: assets/images/chip4/chip4.jpg - AssetGenImage get chip4 => const AssetGenImage('assets/images/chip4/chip4.jpg'); + AssetGenImage get chip4 => + const AssetGenImage('assets/images/chip4/chip4.jpg'); /// List of all assets List get values => [chip4]; @@ -122,10 +127,12 @@ class $AssetsImagesIconsGen { const $AssetsImagesIconsGen(); /// File path: assets/images/icons/dart@test.svg - SvgGenImage get dartTest => const SvgGenImage('assets/images/icons/dart@test.svg'); + SvgGenImage get dartTest => + const SvgGenImage('assets/images/icons/dart@test.svg'); /// File path: assets/images/icons/fuchsia.svg - SvgGenImage get fuchsia => const SvgGenImage('assets/images/icons/fuchsia.svg'); + SvgGenImage get fuchsia => + const SvgGenImage('assets/images/icons/fuchsia.svg'); /// File path: assets/images/icons/kmm.svg SvgGenImage get kmm => const SvgGenImage('assets/images/icons/kmm.svg'); @@ -298,7 +305,8 @@ class SvgGenImage { placeholderBuilder: placeholderBuilder, semanticsLabel: semanticsLabel, excludeFromSemantics: excludeFromSemantics, - colorFilter: colorFilter ?? (color == null ? null : ColorFilter.mode(color, colorBlendMode)), + colorFilter: colorFilter ?? + (color == null ? null : ColorFilter.mode(color, colorBlendMode)), clipBehavior: clipBehavior, cacheColorFilter: cacheColorFilter, ); diff --git a/packages/core/test_resources/actual_data/build_empty.gen.dart b/packages/core/test_resources/actual_data/build_empty.gen.dart index 09e91354..482e6044 100644 --- a/packages/core/test_resources/actual_data/build_empty.gen.dart +++ b/packages/core/test_resources/actual_data/build_empty.gen.dart @@ -56,13 +56,16 @@ class $AssetsImagesGen { AssetGenImage get logo => const AssetGenImage('assets/images/logo.png'); /// File path: assets/images/profile.jpg - AssetGenImage get profileJpg => const AssetGenImage('assets/images/profile.jpg'); + AssetGenImage get profileJpg => + const AssetGenImage('assets/images/profile.jpg'); /// File path: assets/images/profile.png - AssetGenImage get profilePng => const AssetGenImage('assets/images/profile.png'); + AssetGenImage get profilePng => + const AssetGenImage('assets/images/profile.png'); /// List of all assets - List get values => [chip1, chip2, logo, profileJpg, profilePng]; + List get values => + [chip1, chip2, logo, profileJpg, profilePng]; } class $AssetsJsonGen { @@ -102,7 +105,8 @@ class $AssetsImagesChip3Gen { const $AssetsImagesChip3Gen(); /// File path: assets/images/chip3/chip3.jpg - AssetGenImage get chip3 => const AssetGenImage('assets/images/chip3/chip3.jpg'); + AssetGenImage get chip3 => + const AssetGenImage('assets/images/chip3/chip3.jpg'); /// List of all assets List get values => [chip3]; @@ -112,7 +116,8 @@ class $AssetsImagesChip4Gen { const $AssetsImagesChip4Gen(); /// File path: assets/images/chip4/chip4.jpg - AssetGenImage get chip4 => const AssetGenImage('assets/images/chip4/chip4.jpg'); + AssetGenImage get chip4 => + const AssetGenImage('assets/images/chip4/chip4.jpg'); /// List of all assets List get values => [chip4]; @@ -122,10 +127,12 @@ class $AssetsImagesIconsGen { const $AssetsImagesIconsGen(); /// File path: assets/images/icons/dart@test.svg - SvgGenImage get dartTest => const SvgGenImage('assets/images/icons/dart@test.svg'); + SvgGenImage get dartTest => + const SvgGenImage('assets/images/icons/dart@test.svg'); /// File path: assets/images/icons/fuchsia.svg - SvgGenImage get fuchsia => const SvgGenImage('assets/images/icons/fuchsia.svg'); + SvgGenImage get fuchsia => + const SvgGenImage('assets/images/icons/fuchsia.svg'); /// File path: assets/images/icons/kmm.svg SvgGenImage get kmm => const SvgGenImage('assets/images/icons/kmm.svg'); @@ -298,7 +305,8 @@ class SvgGenImage { placeholderBuilder: placeholderBuilder, semanticsLabel: semanticsLabel, excludeFromSemantics: excludeFromSemantics, - colorFilter: colorFilter ?? (color == null ? null : ColorFilter.mode(color, colorBlendMode)), + colorFilter: colorFilter ?? + (color == null ? null : ColorFilter.mode(color, colorBlendMode)), clipBehavior: clipBehavior, cacheColorFilter: cacheColorFilter, ); diff --git a/packages/core/test_resources/actual_data/build_runner_assets.gen.dart b/packages/core/test_resources/actual_data/build_runner_assets.gen.dart index ce52a218..50bf442f 100644 --- a/packages/core/test_resources/actual_data/build_runner_assets.gen.dart +++ b/packages/core/test_resources/actual_data/build_runner_assets.gen.dart @@ -56,13 +56,16 @@ class $AssetsImagesGen { AssetGenImage get logo => const AssetGenImage('assets/images/logo.png'); /// File path: assets/images/profile.jpg - AssetGenImage get profileJpg => const AssetGenImage('assets/images/profile.jpg'); + AssetGenImage get profileJpg => + const AssetGenImage('assets/images/profile.jpg'); /// File path: assets/images/profile.png - AssetGenImage get profilePng => const AssetGenImage('assets/images/profile.png'); + AssetGenImage get profilePng => + const AssetGenImage('assets/images/profile.png'); /// List of all assets - List get values => [chip1, chip2, logo, profileJpg, profilePng]; + List get values => + [chip1, chip2, logo, profileJpg, profilePng]; } class $AssetsJsonGen { @@ -102,7 +105,8 @@ class $AssetsImagesChip3Gen { const $AssetsImagesChip3Gen(); /// File path: assets/images/chip3/chip3.jpg - AssetGenImage get chip3 => const AssetGenImage('assets/images/chip3/chip3.jpg'); + AssetGenImage get chip3 => + const AssetGenImage('assets/images/chip3/chip3.jpg'); /// List of all assets List get values => [chip3]; @@ -112,7 +116,8 @@ class $AssetsImagesChip4Gen { const $AssetsImagesChip4Gen(); /// File path: assets/images/chip4/chip4.jpg - AssetGenImage get chip4 => const AssetGenImage('assets/images/chip4/chip4.jpg'); + AssetGenImage get chip4 => + const AssetGenImage('assets/images/chip4/chip4.jpg'); /// List of all assets List get values => [chip4]; @@ -122,10 +127,12 @@ class $AssetsImagesIconsGen { const $AssetsImagesIconsGen(); /// File path: assets/images/icons/dart@test.svg - SvgGenImage get dartTest => const SvgGenImage('assets/images/icons/dart@test.svg'); + SvgGenImage get dartTest => + const SvgGenImage('assets/images/icons/dart@test.svg'); /// File path: assets/images/icons/fuchsia.svg - SvgGenImage get fuchsia => const SvgGenImage('assets/images/icons/fuchsia.svg'); + SvgGenImage get fuchsia => + const SvgGenImage('assets/images/icons/fuchsia.svg'); /// File path: assets/images/icons/kmm.svg SvgGenImage get kmm => const SvgGenImage('assets/images/icons/kmm.svg'); @@ -298,7 +305,8 @@ class SvgGenImage { placeholderBuilder: placeholderBuilder, semanticsLabel: semanticsLabel, excludeFromSemantics: excludeFromSemantics, - colorFilter: colorFilter ?? (color == null ? null : ColorFilter.mode(color, colorBlendMode)), + colorFilter: colorFilter ?? + (color == null ? null : ColorFilter.mode(color, colorBlendMode)), clipBehavior: clipBehavior, cacheColorFilter: cacheColorFilter, ); diff --git a/packages/core/test_resources/actual_data/shaders/build_empty.gen.dart b/packages/core/test_resources/actual_data/shaders/build_empty.gen.dart new file mode 100644 index 00000000..f05610f8 --- /dev/null +++ b/packages/core/test_resources/actual_data/shaders/build_empty.gen.dart @@ -0,0 +1,84 @@ +/// GENERATED CODE - DO NOT MODIFY BY HAND +/// ***************************************************** +/// FlutterGen +/// ***************************************************** + +// coverage:ignore-file +// ignore_for_file: type=lint +// ignore_for_file: directives_ordering,unnecessary_import,implicit_dynamic_list_literal,deprecated_member_use + +class $AssetsGen { + const $AssetsGen(); + + /// Directory path: assets/shaders + $AssetsShadersGen get shaders => const $AssetsShadersGen(); +} + +class $AssetsShadersGen { + const $AssetsShadersGen(); + + /// File path: assets/shaders/shader1.frag + String get shader1 => 'assets/shaders/shader1.frag'; + + /// Directory path: assets/shaders/summer_shaders + $AssetsShadersSummerShadersGen get summerShaders => + const $AssetsShadersSummerShadersGen(); + + /// Directory path: assets/shaders/winter_shaders + $AssetsShadersWinterShadersGen get winterShaders => + const $AssetsShadersWinterShadersGen(); + + /// List of all shaders + List get values => [shader1]; +} + +class $AssetsShadersSummerShadersGen { + const $AssetsShadersSummerShadersGen(); + + /// File path: assets/shaders/summer_shaders/shader1.frag + String get shader1 => 'assets/shaders/summer_shaders/shader1.frag'; + + /// File path: assets/shaders/summer_shaders/summer.frag + String get summer => 'assets/shaders/summer_shaders/summer.frag'; + + /// List of all shaders + List get values => [shader1, summer]; +} + +class $AssetsShadersWinterShadersGen { + const $AssetsShadersWinterShadersGen(); + + /// Directory path: assets/shaders/winter_shaders/holiday_shaders + $AssetsShadersWinterShadersHolidayShadersGen get holidayShaders => + const $AssetsShadersWinterShadersHolidayShadersGen(); + + /// File path: assets/shaders/winter_shaders/shader1.frag + String get shader1 => 'assets/shaders/winter_shaders/shader1.frag'; + + /// File path: assets/shaders/winter_shaders/winter.frag + String get winter => 'assets/shaders/winter_shaders/winter.frag'; + + /// List of all shaders + List get values => [shader1, winter]; +} + +class $AssetsShadersWinterShadersHolidayShadersGen { + const $AssetsShadersWinterShadersHolidayShadersGen(); + + /// File path: assets/shaders/winter_shaders/holiday_shaders/holiday.frag + String get holiday => + 'assets/shaders/winter_shaders/holiday_shaders/holiday.frag'; + + /// File path: assets/shaders/winter_shaders/holiday_shaders/shader1.frag + String get shader1 => + 'assets/shaders/winter_shaders/holiday_shaders/shader1.frag'; + + /// List of all shaders + List get values => [holiday, shader1]; +} + +class Shaders { + Shaders._(); + + static const $AssetsGen assets = $AssetsGen(); +} diff --git a/packages/core/test_resources/actual_data/shaders/build_runner_shaders.gen.dart b/packages/core/test_resources/actual_data/shaders/build_runner_shaders.gen.dart new file mode 100644 index 00000000..f05610f8 --- /dev/null +++ b/packages/core/test_resources/actual_data/shaders/build_runner_shaders.gen.dart @@ -0,0 +1,84 @@ +/// GENERATED CODE - DO NOT MODIFY BY HAND +/// ***************************************************** +/// FlutterGen +/// ***************************************************** + +// coverage:ignore-file +// ignore_for_file: type=lint +// ignore_for_file: directives_ordering,unnecessary_import,implicit_dynamic_list_literal,deprecated_member_use + +class $AssetsGen { + const $AssetsGen(); + + /// Directory path: assets/shaders + $AssetsShadersGen get shaders => const $AssetsShadersGen(); +} + +class $AssetsShadersGen { + const $AssetsShadersGen(); + + /// File path: assets/shaders/shader1.frag + String get shader1 => 'assets/shaders/shader1.frag'; + + /// Directory path: assets/shaders/summer_shaders + $AssetsShadersSummerShadersGen get summerShaders => + const $AssetsShadersSummerShadersGen(); + + /// Directory path: assets/shaders/winter_shaders + $AssetsShadersWinterShadersGen get winterShaders => + const $AssetsShadersWinterShadersGen(); + + /// List of all shaders + List get values => [shader1]; +} + +class $AssetsShadersSummerShadersGen { + const $AssetsShadersSummerShadersGen(); + + /// File path: assets/shaders/summer_shaders/shader1.frag + String get shader1 => 'assets/shaders/summer_shaders/shader1.frag'; + + /// File path: assets/shaders/summer_shaders/summer.frag + String get summer => 'assets/shaders/summer_shaders/summer.frag'; + + /// List of all shaders + List get values => [shader1, summer]; +} + +class $AssetsShadersWinterShadersGen { + const $AssetsShadersWinterShadersGen(); + + /// Directory path: assets/shaders/winter_shaders/holiday_shaders + $AssetsShadersWinterShadersHolidayShadersGen get holidayShaders => + const $AssetsShadersWinterShadersHolidayShadersGen(); + + /// File path: assets/shaders/winter_shaders/shader1.frag + String get shader1 => 'assets/shaders/winter_shaders/shader1.frag'; + + /// File path: assets/shaders/winter_shaders/winter.frag + String get winter => 'assets/shaders/winter_shaders/winter.frag'; + + /// List of all shaders + List get values => [shader1, winter]; +} + +class $AssetsShadersWinterShadersHolidayShadersGen { + const $AssetsShadersWinterShadersHolidayShadersGen(); + + /// File path: assets/shaders/winter_shaders/holiday_shaders/holiday.frag + String get holiday => + 'assets/shaders/winter_shaders/holiday_shaders/holiday.frag'; + + /// File path: assets/shaders/winter_shaders/holiday_shaders/shader1.frag + String get shader1 => + 'assets/shaders/winter_shaders/holiday_shaders/shader1.frag'; + + /// List of all shaders + List get values => [holiday, shader1]; +} + +class Shaders { + Shaders._(); + + static const $AssetsGen assets = $AssetsGen(); +} diff --git a/packages/core/test_resources/actual_data/shaders/build_shaders.gen.dart b/packages/core/test_resources/actual_data/shaders/build_shaders.gen.dart new file mode 100644 index 00000000..f05610f8 --- /dev/null +++ b/packages/core/test_resources/actual_data/shaders/build_shaders.gen.dart @@ -0,0 +1,84 @@ +/// GENERATED CODE - DO NOT MODIFY BY HAND +/// ***************************************************** +/// FlutterGen +/// ***************************************************** + +// coverage:ignore-file +// ignore_for_file: type=lint +// ignore_for_file: directives_ordering,unnecessary_import,implicit_dynamic_list_literal,deprecated_member_use + +class $AssetsGen { + const $AssetsGen(); + + /// Directory path: assets/shaders + $AssetsShadersGen get shaders => const $AssetsShadersGen(); +} + +class $AssetsShadersGen { + const $AssetsShadersGen(); + + /// File path: assets/shaders/shader1.frag + String get shader1 => 'assets/shaders/shader1.frag'; + + /// Directory path: assets/shaders/summer_shaders + $AssetsShadersSummerShadersGen get summerShaders => + const $AssetsShadersSummerShadersGen(); + + /// Directory path: assets/shaders/winter_shaders + $AssetsShadersWinterShadersGen get winterShaders => + const $AssetsShadersWinterShadersGen(); + + /// List of all shaders + List get values => [shader1]; +} + +class $AssetsShadersSummerShadersGen { + const $AssetsShadersSummerShadersGen(); + + /// File path: assets/shaders/summer_shaders/shader1.frag + String get shader1 => 'assets/shaders/summer_shaders/shader1.frag'; + + /// File path: assets/shaders/summer_shaders/summer.frag + String get summer => 'assets/shaders/summer_shaders/summer.frag'; + + /// List of all shaders + List get values => [shader1, summer]; +} + +class $AssetsShadersWinterShadersGen { + const $AssetsShadersWinterShadersGen(); + + /// Directory path: assets/shaders/winter_shaders/holiday_shaders + $AssetsShadersWinterShadersHolidayShadersGen get holidayShaders => + const $AssetsShadersWinterShadersHolidayShadersGen(); + + /// File path: assets/shaders/winter_shaders/shader1.frag + String get shader1 => 'assets/shaders/winter_shaders/shader1.frag'; + + /// File path: assets/shaders/winter_shaders/winter.frag + String get winter => 'assets/shaders/winter_shaders/winter.frag'; + + /// List of all shaders + List get values => [shader1, winter]; +} + +class $AssetsShadersWinterShadersHolidayShadersGen { + const $AssetsShadersWinterShadersHolidayShadersGen(); + + /// File path: assets/shaders/winter_shaders/holiday_shaders/holiday.frag + String get holiday => + 'assets/shaders/winter_shaders/holiday_shaders/holiday.frag'; + + /// File path: assets/shaders/winter_shaders/holiday_shaders/shader1.frag + String get shader1 => + 'assets/shaders/winter_shaders/holiday_shaders/shader1.frag'; + + /// List of all shaders + List get values => [holiday, shader1]; +} + +class Shaders { + Shaders._(); + + static const $AssetsGen assets = $AssetsGen(); +} diff --git a/packages/core/test_resources/actual_data/shaders/shaders.gen.dart b/packages/core/test_resources/actual_data/shaders/shaders.gen.dart new file mode 100644 index 00000000..f05610f8 --- /dev/null +++ b/packages/core/test_resources/actual_data/shaders/shaders.gen.dart @@ -0,0 +1,84 @@ +/// GENERATED CODE - DO NOT MODIFY BY HAND +/// ***************************************************** +/// FlutterGen +/// ***************************************************** + +// coverage:ignore-file +// ignore_for_file: type=lint +// ignore_for_file: directives_ordering,unnecessary_import,implicit_dynamic_list_literal,deprecated_member_use + +class $AssetsGen { + const $AssetsGen(); + + /// Directory path: assets/shaders + $AssetsShadersGen get shaders => const $AssetsShadersGen(); +} + +class $AssetsShadersGen { + const $AssetsShadersGen(); + + /// File path: assets/shaders/shader1.frag + String get shader1 => 'assets/shaders/shader1.frag'; + + /// Directory path: assets/shaders/summer_shaders + $AssetsShadersSummerShadersGen get summerShaders => + const $AssetsShadersSummerShadersGen(); + + /// Directory path: assets/shaders/winter_shaders + $AssetsShadersWinterShadersGen get winterShaders => + const $AssetsShadersWinterShadersGen(); + + /// List of all shaders + List get values => [shader1]; +} + +class $AssetsShadersSummerShadersGen { + const $AssetsShadersSummerShadersGen(); + + /// File path: assets/shaders/summer_shaders/shader1.frag + String get shader1 => 'assets/shaders/summer_shaders/shader1.frag'; + + /// File path: assets/shaders/summer_shaders/summer.frag + String get summer => 'assets/shaders/summer_shaders/summer.frag'; + + /// List of all shaders + List get values => [shader1, summer]; +} + +class $AssetsShadersWinterShadersGen { + const $AssetsShadersWinterShadersGen(); + + /// Directory path: assets/shaders/winter_shaders/holiday_shaders + $AssetsShadersWinterShadersHolidayShadersGen get holidayShaders => + const $AssetsShadersWinterShadersHolidayShadersGen(); + + /// File path: assets/shaders/winter_shaders/shader1.frag + String get shader1 => 'assets/shaders/winter_shaders/shader1.frag'; + + /// File path: assets/shaders/winter_shaders/winter.frag + String get winter => 'assets/shaders/winter_shaders/winter.frag'; + + /// List of all shaders + List get values => [shader1, winter]; +} + +class $AssetsShadersWinterShadersHolidayShadersGen { + const $AssetsShadersWinterShadersHolidayShadersGen(); + + /// File path: assets/shaders/winter_shaders/holiday_shaders/holiday.frag + String get holiday => + 'assets/shaders/winter_shaders/holiday_shaders/holiday.frag'; + + /// File path: assets/shaders/winter_shaders/holiday_shaders/shader1.frag + String get shader1 => + 'assets/shaders/winter_shaders/holiday_shaders/shader1.frag'; + + /// List of all shaders + List get values => [holiday, shader1]; +} + +class Shaders { + Shaders._(); + + static const $AssetsGen assets = $AssetsGen(); +} diff --git a/packages/core/test_resources/actual_data/shaders/shaders_camel_case.gen.dart b/packages/core/test_resources/actual_data/shaders/shaders_camel_case.gen.dart new file mode 100644 index 00000000..ad90f05f --- /dev/null +++ b/packages/core/test_resources/actual_data/shaders/shaders_camel_case.gen.dart @@ -0,0 +1,50 @@ +/// GENERATED CODE - DO NOT MODIFY BY HAND +/// ***************************************************** +/// FlutterGen +/// ***************************************************** + +// coverage:ignore-file +// ignore_for_file: type=lint +// ignore_for_file: directives_ordering,unnecessary_import,implicit_dynamic_list_literal,deprecated_member_use + +class Shaders { + Shaders._(); + + /// File path: assets/shaders/shader1.frag + static const String assetsShadersShader1 = 'assets/shaders/shader1.frag'; + + /// File path: assets/shaders/summer_shaders/shader1.frag + static const String assetsShadersSummerShadersShader1 = + 'assets/shaders/summer_shaders/shader1.frag'; + + /// File path: assets/shaders/summer_shaders/summer.frag + static const String assetsShadersSummerShadersSummer = + 'assets/shaders/summer_shaders/summer.frag'; + + /// File path: assets/shaders/winter_shaders/holiday_shaders/holiday.frag + static const String assetsShadersWinterShadersHolidayShadersHoliday = + 'assets/shaders/winter_shaders/holiday_shaders/holiday.frag'; + + /// File path: assets/shaders/winter_shaders/holiday_shaders/shader1.frag + static const String assetsShadersWinterShadersHolidayShadersShader1 = + 'assets/shaders/winter_shaders/holiday_shaders/shader1.frag'; + + /// File path: assets/shaders/winter_shaders/shader1.frag + static const String assetsShadersWinterShadersShader1 = + 'assets/shaders/winter_shaders/shader1.frag'; + + /// File path: assets/shaders/winter_shaders/winter.frag + static const String assetsShadersWinterShadersWinter = + 'assets/shaders/winter_shaders/winter.frag'; + + /// List of all shaders + static List get values => [ + assetsShadersShader1, + assetsShadersSummerShadersShader1, + assetsShadersSummerShadersSummer, + assetsShadersWinterShadersHolidayShadersHoliday, + assetsShadersWinterShadersHolidayShadersShader1, + assetsShadersWinterShadersShader1, + assetsShadersWinterShadersWinter + ]; +} diff --git a/packages/core/test_resources/actual_data/shaders/shaders_change_class_name.gen.dart b/packages/core/test_resources/actual_data/shaders/shaders_change_class_name.gen.dart new file mode 100644 index 00000000..f05610f8 --- /dev/null +++ b/packages/core/test_resources/actual_data/shaders/shaders_change_class_name.gen.dart @@ -0,0 +1,84 @@ +/// GENERATED CODE - DO NOT MODIFY BY HAND +/// ***************************************************** +/// FlutterGen +/// ***************************************************** + +// coverage:ignore-file +// ignore_for_file: type=lint +// ignore_for_file: directives_ordering,unnecessary_import,implicit_dynamic_list_literal,deprecated_member_use + +class $AssetsGen { + const $AssetsGen(); + + /// Directory path: assets/shaders + $AssetsShadersGen get shaders => const $AssetsShadersGen(); +} + +class $AssetsShadersGen { + const $AssetsShadersGen(); + + /// File path: assets/shaders/shader1.frag + String get shader1 => 'assets/shaders/shader1.frag'; + + /// Directory path: assets/shaders/summer_shaders + $AssetsShadersSummerShadersGen get summerShaders => + const $AssetsShadersSummerShadersGen(); + + /// Directory path: assets/shaders/winter_shaders + $AssetsShadersWinterShadersGen get winterShaders => + const $AssetsShadersWinterShadersGen(); + + /// List of all shaders + List get values => [shader1]; +} + +class $AssetsShadersSummerShadersGen { + const $AssetsShadersSummerShadersGen(); + + /// File path: assets/shaders/summer_shaders/shader1.frag + String get shader1 => 'assets/shaders/summer_shaders/shader1.frag'; + + /// File path: assets/shaders/summer_shaders/summer.frag + String get summer => 'assets/shaders/summer_shaders/summer.frag'; + + /// List of all shaders + List get values => [shader1, summer]; +} + +class $AssetsShadersWinterShadersGen { + const $AssetsShadersWinterShadersGen(); + + /// Directory path: assets/shaders/winter_shaders/holiday_shaders + $AssetsShadersWinterShadersHolidayShadersGen get holidayShaders => + const $AssetsShadersWinterShadersHolidayShadersGen(); + + /// File path: assets/shaders/winter_shaders/shader1.frag + String get shader1 => 'assets/shaders/winter_shaders/shader1.frag'; + + /// File path: assets/shaders/winter_shaders/winter.frag + String get winter => 'assets/shaders/winter_shaders/winter.frag'; + + /// List of all shaders + List get values => [shader1, winter]; +} + +class $AssetsShadersWinterShadersHolidayShadersGen { + const $AssetsShadersWinterShadersHolidayShadersGen(); + + /// File path: assets/shaders/winter_shaders/holiday_shaders/holiday.frag + String get holiday => + 'assets/shaders/winter_shaders/holiday_shaders/holiday.frag'; + + /// File path: assets/shaders/winter_shaders/holiday_shaders/shader1.frag + String get shader1 => + 'assets/shaders/winter_shaders/holiday_shaders/shader1.frag'; + + /// List of all shaders + List get values => [holiday, shader1]; +} + +class Shaders { + Shaders._(); + + static const $AssetsGen assets = $AssetsGen(); +} diff --git a/packages/core/test_resources/actual_data/shaders/shaders_directory_path.gen.dart b/packages/core/test_resources/actual_data/shaders/shaders_directory_path.gen.dart new file mode 100644 index 00000000..c94b949d --- /dev/null +++ b/packages/core/test_resources/actual_data/shaders/shaders_directory_path.gen.dart @@ -0,0 +1,99 @@ +/// GENERATED CODE - DO NOT MODIFY BY HAND +/// ***************************************************** +/// FlutterGen +/// ***************************************************** + +// coverage:ignore-file +// ignore_for_file: type=lint +// ignore_for_file: directives_ordering,unnecessary_import,implicit_dynamic_list_literal,deprecated_member_use + +class $AssetsGen { + const $AssetsGen(); + + /// Directory path: assets/shaders + $AssetsShadersGen get shaders => const $AssetsShadersGen(); + + /// Directory path: assets + String get path => 'assets'; +} + +class $AssetsShadersGen { + const $AssetsShadersGen(); + + /// File path: assets/shaders/shader1.frag + String get shader1 => 'assets/shaders/shader1.frag'; + + /// Directory path: assets/shaders/summer_shaders + $AssetsShadersSummerShadersGen get summerShaders => + const $AssetsShadersSummerShadersGen(); + + /// Directory path: assets/shaders/winter_shaders + $AssetsShadersWinterShadersGen get winterShaders => + const $AssetsShadersWinterShadersGen(); + + /// Directory path: assets/shaders + String get path => 'assets/shaders'; + + /// List of all shaders + List get values => [shader1]; +} + +class $AssetsShadersSummerShadersGen { + const $AssetsShadersSummerShadersGen(); + + /// File path: assets/shaders/summer_shaders/shader1.frag + String get shader1 => 'assets/shaders/summer_shaders/shader1.frag'; + + /// File path: assets/shaders/summer_shaders/summer.frag + String get summer => 'assets/shaders/summer_shaders/summer.frag'; + + /// Directory path: assets/shaders/summer_shaders + String get path => 'assets/shaders/summer_shaders'; + + /// List of all shaders + List get values => [shader1, summer]; +} + +class $AssetsShadersWinterShadersGen { + const $AssetsShadersWinterShadersGen(); + + /// Directory path: assets/shaders/winter_shaders/holiday_shaders + $AssetsShadersWinterShadersHolidayShadersGen get holidayShaders => + const $AssetsShadersWinterShadersHolidayShadersGen(); + + /// File path: assets/shaders/winter_shaders/shader1.frag + String get shader1 => 'assets/shaders/winter_shaders/shader1.frag'; + + /// File path: assets/shaders/winter_shaders/winter.frag + String get winter => 'assets/shaders/winter_shaders/winter.frag'; + + /// Directory path: assets/shaders/winter_shaders + String get path => 'assets/shaders/winter_shaders'; + + /// List of all shaders + List get values => [shader1, winter]; +} + +class $AssetsShadersWinterShadersHolidayShadersGen { + const $AssetsShadersWinterShadersHolidayShadersGen(); + + /// File path: assets/shaders/winter_shaders/holiday_shaders/holiday.frag + String get holiday => + 'assets/shaders/winter_shaders/holiday_shaders/holiday.frag'; + + /// File path: assets/shaders/winter_shaders/holiday_shaders/shader1.frag + String get shader1 => + 'assets/shaders/winter_shaders/holiday_shaders/shader1.frag'; + + /// Directory path: assets/shaders/winter_shaders/holiday_shaders + String get path => 'assets/shaders/winter_shaders/holiday_shaders'; + + /// List of all shaders + List get values => [holiday, shader1]; +} + +class Shaders { + Shaders._(); + + static const $AssetsGen assets = $AssetsGen(); +} diff --git a/packages/core/test_resources/actual_data/shaders/shaders_flavored.gen.dart b/packages/core/test_resources/actual_data/shaders/shaders_flavored.gen.dart new file mode 100644 index 00000000..f05610f8 --- /dev/null +++ b/packages/core/test_resources/actual_data/shaders/shaders_flavored.gen.dart @@ -0,0 +1,84 @@ +/// GENERATED CODE - DO NOT MODIFY BY HAND +/// ***************************************************** +/// FlutterGen +/// ***************************************************** + +// coverage:ignore-file +// ignore_for_file: type=lint +// ignore_for_file: directives_ordering,unnecessary_import,implicit_dynamic_list_literal,deprecated_member_use + +class $AssetsGen { + const $AssetsGen(); + + /// Directory path: assets/shaders + $AssetsShadersGen get shaders => const $AssetsShadersGen(); +} + +class $AssetsShadersGen { + const $AssetsShadersGen(); + + /// File path: assets/shaders/shader1.frag + String get shader1 => 'assets/shaders/shader1.frag'; + + /// Directory path: assets/shaders/summer_shaders + $AssetsShadersSummerShadersGen get summerShaders => + const $AssetsShadersSummerShadersGen(); + + /// Directory path: assets/shaders/winter_shaders + $AssetsShadersWinterShadersGen get winterShaders => + const $AssetsShadersWinterShadersGen(); + + /// List of all shaders + List get values => [shader1]; +} + +class $AssetsShadersSummerShadersGen { + const $AssetsShadersSummerShadersGen(); + + /// File path: assets/shaders/summer_shaders/shader1.frag + String get shader1 => 'assets/shaders/summer_shaders/shader1.frag'; + + /// File path: assets/shaders/summer_shaders/summer.frag + String get summer => 'assets/shaders/summer_shaders/summer.frag'; + + /// List of all shaders + List get values => [shader1, summer]; +} + +class $AssetsShadersWinterShadersGen { + const $AssetsShadersWinterShadersGen(); + + /// Directory path: assets/shaders/winter_shaders/holiday_shaders + $AssetsShadersWinterShadersHolidayShadersGen get holidayShaders => + const $AssetsShadersWinterShadersHolidayShadersGen(); + + /// File path: assets/shaders/winter_shaders/shader1.frag + String get shader1 => 'assets/shaders/winter_shaders/shader1.frag'; + + /// File path: assets/shaders/winter_shaders/winter.frag + String get winter => 'assets/shaders/winter_shaders/winter.frag'; + + /// List of all shaders + List get values => [shader1, winter]; +} + +class $AssetsShadersWinterShadersHolidayShadersGen { + const $AssetsShadersWinterShadersHolidayShadersGen(); + + /// File path: assets/shaders/winter_shaders/holiday_shaders/holiday.frag + String get holiday => + 'assets/shaders/winter_shaders/holiday_shaders/holiday.frag'; + + /// File path: assets/shaders/winter_shaders/holiday_shaders/shader1.frag + String get shader1 => + 'assets/shaders/winter_shaders/holiday_shaders/shader1.frag'; + + /// List of all shaders + List get values => [holiday, shader1]; +} + +class Shaders { + Shaders._(); + + static const $AssetsGen assets = $AssetsGen(); +} diff --git a/packages/core/test_resources/actual_data/shaders/shaders_package_exclude_files.gen.dart b/packages/core/test_resources/actual_data/shaders/shaders_package_exclude_files.gen.dart new file mode 100644 index 00000000..f05610f8 --- /dev/null +++ b/packages/core/test_resources/actual_data/shaders/shaders_package_exclude_files.gen.dart @@ -0,0 +1,84 @@ +/// GENERATED CODE - DO NOT MODIFY BY HAND +/// ***************************************************** +/// FlutterGen +/// ***************************************************** + +// coverage:ignore-file +// ignore_for_file: type=lint +// ignore_for_file: directives_ordering,unnecessary_import,implicit_dynamic_list_literal,deprecated_member_use + +class $AssetsGen { + const $AssetsGen(); + + /// Directory path: assets/shaders + $AssetsShadersGen get shaders => const $AssetsShadersGen(); +} + +class $AssetsShadersGen { + const $AssetsShadersGen(); + + /// File path: assets/shaders/shader1.frag + String get shader1 => 'assets/shaders/shader1.frag'; + + /// Directory path: assets/shaders/summer_shaders + $AssetsShadersSummerShadersGen get summerShaders => + const $AssetsShadersSummerShadersGen(); + + /// Directory path: assets/shaders/winter_shaders + $AssetsShadersWinterShadersGen get winterShaders => + const $AssetsShadersWinterShadersGen(); + + /// List of all shaders + List get values => [shader1]; +} + +class $AssetsShadersSummerShadersGen { + const $AssetsShadersSummerShadersGen(); + + /// File path: assets/shaders/summer_shaders/shader1.frag + String get shader1 => 'assets/shaders/summer_shaders/shader1.frag'; + + /// File path: assets/shaders/summer_shaders/summer.frag + String get summer => 'assets/shaders/summer_shaders/summer.frag'; + + /// List of all shaders + List get values => [shader1, summer]; +} + +class $AssetsShadersWinterShadersGen { + const $AssetsShadersWinterShadersGen(); + + /// Directory path: assets/shaders/winter_shaders/holiday_shaders + $AssetsShadersWinterShadersHolidayShadersGen get holidayShaders => + const $AssetsShadersWinterShadersHolidayShadersGen(); + + /// File path: assets/shaders/winter_shaders/shader1.frag + String get shader1 => 'assets/shaders/winter_shaders/shader1.frag'; + + /// File path: assets/shaders/winter_shaders/winter.frag + String get winter => 'assets/shaders/winter_shaders/winter.frag'; + + /// List of all shaders + List get values => [shader1, winter]; +} + +class $AssetsShadersWinterShadersHolidayShadersGen { + const $AssetsShadersWinterShadersHolidayShadersGen(); + + /// File path: assets/shaders/winter_shaders/holiday_shaders/holiday.frag + String get holiday => + 'assets/shaders/winter_shaders/holiday_shaders/holiday.frag'; + + /// File path: assets/shaders/winter_shaders/holiday_shaders/shader1.frag + String get shader1 => + 'assets/shaders/winter_shaders/holiday_shaders/shader1.frag'; + + /// List of all shaders + List get values => [holiday, shader1]; +} + +class Shaders { + Shaders._(); + + static const $AssetsGen assets = $AssetsGen(); +} diff --git a/packages/core/test_resources/actual_data/shaders/shaders_package_parameter.gen.dart b/packages/core/test_resources/actual_data/shaders/shaders_package_parameter.gen.dart new file mode 100644 index 00000000..e0339651 --- /dev/null +++ b/packages/core/test_resources/actual_data/shaders/shaders_package_parameter.gen.dart @@ -0,0 +1,90 @@ +/// GENERATED CODE - DO NOT MODIFY BY HAND +/// ***************************************************** +/// FlutterGen +/// ***************************************************** + +// coverage:ignore-file +// ignore_for_file: type=lint +// ignore_for_file: directives_ordering,unnecessary_import,implicit_dynamic_list_literal,deprecated_member_use + +class $AssetsGen { + const $AssetsGen(); + + /// Directory path: assets/shaders + $AssetsShadersGen get shaders => const $AssetsShadersGen(); +} + +class $AssetsShadersGen { + const $AssetsShadersGen(); + + /// File path: assets/shaders/shader1.frag + String get shader1 => 'packages/test/assets/shaders/shader1.frag'; + + /// Directory path: assets/shaders/summer_shaders + $AssetsShadersSummerShadersGen get summerShaders => + const $AssetsShadersSummerShadersGen(); + + /// Directory path: assets/shaders/winter_shaders + $AssetsShadersWinterShadersGen get winterShaders => + const $AssetsShadersWinterShadersGen(); + + /// List of all shaders + List get values => [shader1]; +} + +class $AssetsShadersSummerShadersGen { + const $AssetsShadersSummerShadersGen(); + + /// File path: assets/shaders/summer_shaders/shader1.frag + String get shader1 => + 'packages/test/assets/shaders/summer_shaders/shader1.frag'; + + /// File path: assets/shaders/summer_shaders/summer.frag + String get summer => + 'packages/test/assets/shaders/summer_shaders/summer.frag'; + + /// List of all shaders + List get values => [shader1, summer]; +} + +class $AssetsShadersWinterShadersGen { + const $AssetsShadersWinterShadersGen(); + + /// Directory path: assets/shaders/winter_shaders/holiday_shaders + $AssetsShadersWinterShadersHolidayShadersGen get holidayShaders => + const $AssetsShadersWinterShadersHolidayShadersGen(); + + /// File path: assets/shaders/winter_shaders/shader1.frag + String get shader1 => + 'packages/test/assets/shaders/winter_shaders/shader1.frag'; + + /// File path: assets/shaders/winter_shaders/winter.frag + String get winter => + 'packages/test/assets/shaders/winter_shaders/winter.frag'; + + /// List of all shaders + List get values => [shader1, winter]; +} + +class $AssetsShadersWinterShadersHolidayShadersGen { + const $AssetsShadersWinterShadersHolidayShadersGen(); + + /// File path: assets/shaders/winter_shaders/holiday_shaders/holiday.frag + String get holiday => + 'packages/test/assets/shaders/winter_shaders/holiday_shaders/holiday.frag'; + + /// File path: assets/shaders/winter_shaders/holiday_shaders/shader1.frag + String get shader1 => + 'packages/test/assets/shaders/winter_shaders/holiday_shaders/shader1.frag'; + + /// List of all shaders + List get values => [holiday, shader1]; +} + +class Shaders { + Shaders._(); + + static const String package = 'test'; + + static const $AssetsGen assets = $AssetsGen(); +} diff --git a/packages/core/test_resources/actual_data/shaders/shaders_parse_metadata.gen.dart b/packages/core/test_resources/actual_data/shaders/shaders_parse_metadata.gen.dart new file mode 100644 index 00000000..f05610f8 --- /dev/null +++ b/packages/core/test_resources/actual_data/shaders/shaders_parse_metadata.gen.dart @@ -0,0 +1,84 @@ +/// GENERATED CODE - DO NOT MODIFY BY HAND +/// ***************************************************** +/// FlutterGen +/// ***************************************************** + +// coverage:ignore-file +// ignore_for_file: type=lint +// ignore_for_file: directives_ordering,unnecessary_import,implicit_dynamic_list_literal,deprecated_member_use + +class $AssetsGen { + const $AssetsGen(); + + /// Directory path: assets/shaders + $AssetsShadersGen get shaders => const $AssetsShadersGen(); +} + +class $AssetsShadersGen { + const $AssetsShadersGen(); + + /// File path: assets/shaders/shader1.frag + String get shader1 => 'assets/shaders/shader1.frag'; + + /// Directory path: assets/shaders/summer_shaders + $AssetsShadersSummerShadersGen get summerShaders => + const $AssetsShadersSummerShadersGen(); + + /// Directory path: assets/shaders/winter_shaders + $AssetsShadersWinterShadersGen get winterShaders => + const $AssetsShadersWinterShadersGen(); + + /// List of all shaders + List get values => [shader1]; +} + +class $AssetsShadersSummerShadersGen { + const $AssetsShadersSummerShadersGen(); + + /// File path: assets/shaders/summer_shaders/shader1.frag + String get shader1 => 'assets/shaders/summer_shaders/shader1.frag'; + + /// File path: assets/shaders/summer_shaders/summer.frag + String get summer => 'assets/shaders/summer_shaders/summer.frag'; + + /// List of all shaders + List get values => [shader1, summer]; +} + +class $AssetsShadersWinterShadersGen { + const $AssetsShadersWinterShadersGen(); + + /// Directory path: assets/shaders/winter_shaders/holiday_shaders + $AssetsShadersWinterShadersHolidayShadersGen get holidayShaders => + const $AssetsShadersWinterShadersHolidayShadersGen(); + + /// File path: assets/shaders/winter_shaders/shader1.frag + String get shader1 => 'assets/shaders/winter_shaders/shader1.frag'; + + /// File path: assets/shaders/winter_shaders/winter.frag + String get winter => 'assets/shaders/winter_shaders/winter.frag'; + + /// List of all shaders + List get values => [shader1, winter]; +} + +class $AssetsShadersWinterShadersHolidayShadersGen { + const $AssetsShadersWinterShadersHolidayShadersGen(); + + /// File path: assets/shaders/winter_shaders/holiday_shaders/holiday.frag + String get holiday => + 'assets/shaders/winter_shaders/holiday_shaders/holiday.frag'; + + /// File path: assets/shaders/winter_shaders/holiday_shaders/shader1.frag + String get shader1 => + 'assets/shaders/winter_shaders/holiday_shaders/shader1.frag'; + + /// List of all shaders + List get values => [holiday, shader1]; +} + +class Shaders { + Shaders._(); + + static const $AssetsGen assets = $AssetsGen(); +} diff --git a/packages/core/test_resources/actual_data/shaders/shaders_snake_case.gen.dart b/packages/core/test_resources/actual_data/shaders/shaders_snake_case.gen.dart new file mode 100644 index 00000000..43026ca5 --- /dev/null +++ b/packages/core/test_resources/actual_data/shaders/shaders_snake_case.gen.dart @@ -0,0 +1,50 @@ +/// GENERATED CODE - DO NOT MODIFY BY HAND +/// ***************************************************** +/// FlutterGen +/// ***************************************************** + +// coverage:ignore-file +// ignore_for_file: type=lint +// ignore_for_file: directives_ordering,unnecessary_import,implicit_dynamic_list_literal,deprecated_member_use + +class Shaders { + Shaders._(); + + /// File path: assets/shaders/shader1.frag + static const String assets_shaders_shader1 = 'assets/shaders/shader1.frag'; + + /// File path: assets/shaders/summer_shaders/shader1.frag + static const String assets_shaders_summer_shaders_shader1 = + 'assets/shaders/summer_shaders/shader1.frag'; + + /// File path: assets/shaders/summer_shaders/summer.frag + static const String assets_shaders_summer_shaders_summer = + 'assets/shaders/summer_shaders/summer.frag'; + + /// File path: assets/shaders/winter_shaders/holiday_shaders/holiday.frag + static const String assets_shaders_winter_shaders_holiday_shaders_holiday = + 'assets/shaders/winter_shaders/holiday_shaders/holiday.frag'; + + /// File path: assets/shaders/winter_shaders/holiday_shaders/shader1.frag + static const String assets_shaders_winter_shaders_holiday_shaders_shader1 = + 'assets/shaders/winter_shaders/holiday_shaders/shader1.frag'; + + /// File path: assets/shaders/winter_shaders/shader1.frag + static const String assets_shaders_winter_shaders_shader1 = + 'assets/shaders/winter_shaders/shader1.frag'; + + /// File path: assets/shaders/winter_shaders/winter.frag + static const String assets_shaders_winter_shaders_winter = + 'assets/shaders/winter_shaders/winter.frag'; + + /// List of all shaders + static List get values => [ + assets_shaders_shader1, + assets_shaders_summer_shaders_shader1, + assets_shaders_summer_shaders_summer, + assets_shaders_winter_shaders_holiday_shaders_holiday, + assets_shaders_winter_shaders_holiday_shaders_shader1, + assets_shaders_winter_shaders_shader1, + assets_shaders_winter_shaders_winter + ]; +} diff --git a/packages/core/test_resources/assets/shaders/shader1.frag b/packages/core/test_resources/assets/shaders/shader1.frag new file mode 100644 index 00000000..0294c2aa --- /dev/null +++ b/packages/core/test_resources/assets/shaders/shader1.frag @@ -0,0 +1,5 @@ +#version 100 + +void main() { + +} \ No newline at end of file diff --git a/packages/core/test_resources/assets/shaders/summer_shaders/shader1.frag b/packages/core/test_resources/assets/shaders/summer_shaders/shader1.frag new file mode 100644 index 00000000..0294c2aa --- /dev/null +++ b/packages/core/test_resources/assets/shaders/summer_shaders/shader1.frag @@ -0,0 +1,5 @@ +#version 100 + +void main() { + +} \ No newline at end of file diff --git a/packages/core/test_resources/assets/shaders/summer_shaders/summer.frag b/packages/core/test_resources/assets/shaders/summer_shaders/summer.frag new file mode 100644 index 00000000..0294c2aa --- /dev/null +++ b/packages/core/test_resources/assets/shaders/summer_shaders/summer.frag @@ -0,0 +1,5 @@ +#version 100 + +void main() { + +} \ No newline at end of file diff --git a/packages/core/test_resources/assets/shaders/winter_shaders/holiday_shaders/holiday.frag b/packages/core/test_resources/assets/shaders/winter_shaders/holiday_shaders/holiday.frag new file mode 100644 index 00000000..0294c2aa --- /dev/null +++ b/packages/core/test_resources/assets/shaders/winter_shaders/holiday_shaders/holiday.frag @@ -0,0 +1,5 @@ +#version 100 + +void main() { + +} \ No newline at end of file diff --git a/packages/core/test_resources/assets/shaders/winter_shaders/holiday_shaders/shader1.frag b/packages/core/test_resources/assets/shaders/winter_shaders/holiday_shaders/shader1.frag new file mode 100644 index 00000000..0294c2aa --- /dev/null +++ b/packages/core/test_resources/assets/shaders/winter_shaders/holiday_shaders/shader1.frag @@ -0,0 +1,5 @@ +#version 100 + +void main() { + +} \ No newline at end of file diff --git a/packages/core/test_resources/assets/shaders/winter_shaders/shader1.frag b/packages/core/test_resources/assets/shaders/winter_shaders/shader1.frag new file mode 100644 index 00000000..0294c2aa --- /dev/null +++ b/packages/core/test_resources/assets/shaders/winter_shaders/shader1.frag @@ -0,0 +1,5 @@ +#version 100 + +void main() { + +} \ No newline at end of file diff --git a/packages/core/test_resources/assets/shaders/winter_shaders/winter.frag b/packages/core/test_resources/assets/shaders/winter_shaders/winter.frag new file mode 100644 index 00000000..0294c2aa --- /dev/null +++ b/packages/core/test_resources/assets/shaders/winter_shaders/winter.frag @@ -0,0 +1,5 @@ +#version 100 + +void main() { + +} \ No newline at end of file diff --git a/packages/core/test_resources/pubspec_shaders.yaml b/packages/core/test_resources/pubspec_shaders.yaml new file mode 100644 index 00000000..85e4557c --- /dev/null +++ b/packages/core/test_resources/pubspec_shaders.yaml @@ -0,0 +1,21 @@ +name: test + +flutter_gen: + output: lib/gen/ # Optional (default: lib/gen/) + line_length: 80 # Optional (default: 80) + +flutter: + shaders: + - assets/shaders/shader1.frag + + - assets/shaders/summer_shaders/shader1.frag + - assets/shaders/summer_shaders/summer.frag + + - assets/shaders/winter_shaders/shader1.frag + - assets/shaders/winter_shaders/winter.frag + + - assets/shaders/winter_shaders/holiday_shaders/shader1.frag + - assets/shaders/winter_shaders/holiday_shaders/holiday.frag + + # duplicated + - assets/shaders/winter_shaders/holiday_shaders/holiday.frag \ No newline at end of file diff --git a/packages/core/test_resources/pubspec_shaders_camel_case.yaml b/packages/core/test_resources/pubspec_shaders_camel_case.yaml new file mode 100644 index 00000000..a920d9d8 --- /dev/null +++ b/packages/core/test_resources/pubspec_shaders_camel_case.yaml @@ -0,0 +1,25 @@ +name: test + +flutter_gen: + output: lib/gen/ # Optional (default: lib/gen/) + line_length: 80 # Optional (default: 80) + + shaders: + outputs: + style: camel-case + +flutter: + shaders: + - assets/shaders/shader1.frag + + - assets/shaders/summer_shaders/shader1.frag + - assets/shaders/summer_shaders/summer.frag + + - assets/shaders/winter_shaders/shader1.frag + - assets/shaders/winter_shaders/winter.frag + + - assets/shaders/winter_shaders/holiday_shaders/shader1.frag + - assets/shaders/winter_shaders/holiday_shaders/holiday.frag + + # duplicated + - assets/shaders/winter_shaders/holiday_shaders/holiday.frag \ No newline at end of file diff --git a/packages/core/test_resources/pubspec_shaders_change_class_name.yaml b/packages/core/test_resources/pubspec_shaders_change_class_name.yaml new file mode 100644 index 00000000..46e34fa6 --- /dev/null +++ b/packages/core/test_resources/pubspec_shaders_change_class_name.yaml @@ -0,0 +1,25 @@ +name: test + +flutter_gen: + output: lib/gen/ # Optional (default: lib/gen/) + line_length: 80 # Optional (default: 80) + + assets: + outputs: + class_name: MyAssets + +flutter: + shaders: + - assets/shaders/shader1.frag + + - assets/shaders/summer_shaders/shader1.frag + - assets/shaders/summer_shaders/summer.frag + + - assets/shaders/winter_shaders/shader1.frag + - assets/shaders/winter_shaders/winter.frag + + - assets/shaders/winter_shaders/holiday_shaders/shader1.frag + - assets/shaders/winter_shaders/holiday_shaders/holiday.frag + + # duplicated + - assets/shaders/winter_shaders/holiday_shaders/holiday.frag \ No newline at end of file diff --git a/packages/core/test_resources/pubspec_shaders_directory_path.yaml b/packages/core/test_resources/pubspec_shaders_directory_path.yaml new file mode 100644 index 00000000..9e6ea133 --- /dev/null +++ b/packages/core/test_resources/pubspec_shaders_directory_path.yaml @@ -0,0 +1,24 @@ +name: test + +flutter_gen: + integrations: + flutter_svg: true + shaders: + outputs: + directory_path_enabled: true + +flutter: + shaders: + - assets/shaders/shader1.frag + + - assets/shaders/summer_shaders/shader1.frag + - assets/shaders/summer_shaders/summer.frag + + - assets/shaders/winter_shaders/shader1.frag + - assets/shaders/winter_shaders/winter.frag + + - assets/shaders/winter_shaders/holiday_shaders/shader1.frag + - assets/shaders/winter_shaders/holiday_shaders/holiday.frag + + # duplicated + - assets/shaders/winter_shaders/holiday_shaders/holiday.frag diff --git a/packages/core/test_resources/pubspec_shaders_exclude_files.yaml b/packages/core/test_resources/pubspec_shaders_exclude_files.yaml new file mode 100644 index 00000000..8902f5c2 --- /dev/null +++ b/packages/core/test_resources/pubspec_shaders_exclude_files.yaml @@ -0,0 +1,30 @@ +name: test + +flutter_gen: + output: lib/gen/ + line_length: 80 + + integrations: + flutter_svg: true + + assets: + exclude: + - assets/shaders/summer_shaders/*.frag + - assets/shaders/winter_shaders/*.frag + - assets/**/icons/* + +flutter: + shaders: + - assets/shaders/shader1.frag + + - assets/shaders/summer_shaders/shader1.frag + - assets/shaders/summer_shaders/summer.frag + + - assets/shaders/winter_shaders/shader1.frag + - assets/shaders/winter_shaders/winter.frag + + - assets/shaders/winter_shaders/holiday_shaders/shader1.frag + - assets/shaders/winter_shaders/holiday_shaders/holiday.frag + + # duplicated + - assets/shaders/winter_shaders/holiday_shaders/holiday.frag \ No newline at end of file diff --git a/packages/core/test_resources/pubspec_shaders_flavored.yaml b/packages/core/test_resources/pubspec_shaders_flavored.yaml new file mode 100644 index 00000000..72e43259 --- /dev/null +++ b/packages/core/test_resources/pubspec_shaders_flavored.yaml @@ -0,0 +1,25 @@ +name: test + +flutter_gen: + output: lib/gen/ # Optional (default: lib/gen/) + line_length: 80 # Optional (default: 80) + + integrations: + flutter_svg: true + flare_flutter: true + +flutter: + shaders: + - assets/shaders/shader1.frag + + - assets/shaders/winter_shaders/shader1.frag + - assets/shaders/winter_shaders/winter.frag + + - assets/shaders/winter_shaders/holiday_shaders/shader1.frag + - assets/shaders/winter_shaders/holiday_shaders/holiday.frag + + # duplicated + - assets/shaders/winter_shaders/holiday_shaders/holiday.frag + - path: assets/shaders/summer_shaders/ + flavors: + - test diff --git a/packages/core/test_resources/pubspec_shaders_flavored_duplicate_entry.yaml b/packages/core/test_resources/pubspec_shaders_flavored_duplicate_entry.yaml new file mode 100644 index 00000000..88b8e705 --- /dev/null +++ b/packages/core/test_resources/pubspec_shaders_flavored_duplicate_entry.yaml @@ -0,0 +1,28 @@ +name: test + +flutter_gen: + output: lib/gen/ # Optional (default: lib/gen/) + line_length: 80 # Optional (default: 80) + + integrations: + flutter_svg: true + flare_flutter: true + +flutter: + shaders: + - assets/shaders/shader1.frag + + - assets/shaders/winter_shaders/shader1.frag + - assets/shaders/winter_shaders/winter.frag + + - assets/shaders/winter_shaders/holiday_shaders/shader1.frag + - assets/shaders/winter_shaders/holiday_shaders/holiday.frag + + # duplicated + - assets/shaders/winter_shaders/holiday_shaders/holiday.frag + - path: assets/shaders/summer_shaders/ + flavors: + - test + - path: assets/shaders/summer_shaders/ + flavors: + - another_test diff --git a/packages/core/test_resources/pubspec_shaders_no_list.yaml b/packages/core/test_resources/pubspec_shaders_no_list.yaml new file mode 100644 index 00000000..bb0325be --- /dev/null +++ b/packages/core/test_resources/pubspec_shaders_no_list.yaml @@ -0,0 +1,8 @@ +name: test + +flutter_gen: + output: lib/gen/ # Optional (default: lib/gen/) + line_length: 80 # Optional (default: 80) + +flutter: + shaders: diff --git a/packages/core/test_resources/pubspec_shaders_package_parameter.yaml b/packages/core/test_resources/pubspec_shaders_package_parameter.yaml new file mode 100644 index 00000000..502d8081 --- /dev/null +++ b/packages/core/test_resources/pubspec_shaders_package_parameter.yaml @@ -0,0 +1,24 @@ +name: test + +flutter_gen: + integrations: + flutter_svg: true + shaders: + outputs: + package_parameter_enabled: true + +flutter: + shaders: + - assets/shaders/shader1.frag + + - assets/shaders/summer_shaders/shader1.frag + - assets/shaders/summer_shaders/summer.frag + + - assets/shaders/winter_shaders/shader1.frag + - assets/shaders/winter_shaders/winter.frag + + - assets/shaders/winter_shaders/holiday_shaders/shader1.frag + - assets/shaders/winter_shaders/holiday_shaders/holiday.frag + + # duplicated + - assets/shaders/winter_shaders/holiday_shaders/holiday.frag diff --git a/packages/core/test_resources/pubspec_shaders_parse_metadata.yaml b/packages/core/test_resources/pubspec_shaders_parse_metadata.yaml new file mode 100644 index 00000000..f05eb84c --- /dev/null +++ b/packages/core/test_resources/pubspec_shaders_parse_metadata.yaml @@ -0,0 +1,22 @@ +name: test + +flutter_gen: + output: lib/gen/ # Optional (default: lib/gen/) + line_length: 80 # Optional (default: 80) + parse_metadata: true # Optional (default: false) + +flutter: + shaders: + - assets/shaders/shader1.frag + + - assets/shaders/summer_shaders/shader1.frag + - assets/shaders/summer_shaders/summer.frag + + - assets/shaders/winter_shaders/shader1.frag + - assets/shaders/winter_shaders/winter.frag + + - assets/shaders/winter_shaders/holiday_shaders/shader1.frag + - assets/shaders/winter_shaders/holiday_shaders/holiday.frag + + # duplicated + - assets/shaders/winter_shaders/holiday_shaders/holiday.frag diff --git a/packages/core/test_resources/pubspec_shaders_snake_case.yaml b/packages/core/test_resources/pubspec_shaders_snake_case.yaml new file mode 100644 index 00000000..b46a5338 --- /dev/null +++ b/packages/core/test_resources/pubspec_shaders_snake_case.yaml @@ -0,0 +1,25 @@ +name: test + +flutter_gen: + output: lib/gen/ # Optional (default: lib/gen/) + line_length: 80 # Optional (default: 80) + + shaders: + outputs: + style: snake-case + +flutter: + shaders: + - assets/shaders/shader1.frag + + - assets/shaders/summer_shaders/shader1.frag + - assets/shaders/summer_shaders/summer.frag + + - assets/shaders/winter_shaders/shader1.frag + - assets/shaders/winter_shaders/winter.frag + + - assets/shaders/winter_shaders/holiday_shaders/shader1.frag + - assets/shaders/winter_shaders/holiday_shaders/holiday.frag + + # duplicated + - assets/shaders/winter_shaders/holiday_shaders/holiday.frag \ No newline at end of file diff --git a/packages/runner/lib/flutter_gen_runner.dart b/packages/runner/lib/flutter_gen_runner.dart index ace44a0c..e5b0cc3e 100644 --- a/packages/runner/lib/flutter_gen_runner.dart +++ b/packages/runner/lib/flutter_gen_runner.dart @@ -7,6 +7,7 @@ import 'package:crypto/crypto.dart'; import 'package:flutter_gen_core/flutter_generator.dart'; import 'package:flutter_gen_core/settings/config.dart'; import 'package:flutter_gen_core/settings/flavored_asset.dart'; +import 'package:flutter_gen_core/settings/flavored_shader.dart'; import 'package:glob/glob.dart'; import 'package:path/path.dart'; import 'package:yaml/yaml.dart'; @@ -56,7 +57,8 @@ class FlutterGenBuilder extends Builder { for (final name in [ generator.assetsName, generator.colorsName, - generator.fontsName + generator.fontsName, + generator.shadersName, ]) join(ouput, name), ], @@ -97,6 +99,34 @@ class FlutterGenBuilder extends Builder { } } + final HashSet shaders = HashSet(); + if (pubspec.flutterGen.shaders.enabled) { + for (final shader in pubspec.flutter.shaders) { + final FlavoredShader flavored; + String assetInput; + if (shader is YamlMap) { + flavored = FlavoredShader( + path: shader['path'], + flavors: + (shader['flavors'] as YamlList?)?.toSet().cast() ?? {}, + ); + assetInput = shader['path']; + } else { + flavored = FlavoredShader(path: shader as String); + assetInput = shader; + } + if (assetInput.isEmpty) { + continue; + } + if (assetInput.endsWith('/')) { + assetInput += '*'; + } + await for (final assetId in buildStep.findAssets(Glob(assetInput))) { + shaders.add(flavored.copyWith(path: assetId.path)); + } + } + } + final HashMap colors = HashMap(); if (pubspec.flutterGen.colors.enabled) { for (final colorInput in pubspec.flutterGen.colors.inputs) { @@ -116,6 +146,7 @@ class FlutterGenBuilder extends Builder { return _FlutterGenBuilderState( pubspecDigest: pubspecDigest, assets: assets, + shaders: shaders, colors: colors, ); } @@ -125,17 +156,20 @@ class _FlutterGenBuilderState { const _FlutterGenBuilderState({ required this.pubspecDigest, required this.assets, + required this.shaders, required this.colors, }); final Digest pubspecDigest; final HashSet assets; + final HashSet shaders; final HashMap colors; bool shouldSkipGenerate(_FlutterGenBuilderState? previous) { if (previous == null) return false; return pubspecDigest == previous.pubspecDigest && const SetEquality().equals(assets, previous.assets) && + const SetEquality().equals(shaders, previous.shaders) && const MapEquality().equals(colors, previous.colors); } }