buildExtensions property
Mapping from input file extension to output file extensions.
All input sources matching any key in this map will be passed as build step to this builder. Only files with the same basename and an extension from the values in this map are expected as outputs.
- If an empty key exists, all inputs are considered matching.
- An instance of a builder must always return the same configuration.
Typically, a builder will return a
constmap. Builders may also choose extensions based onBuilderOptions. - Most builders will use a single input extension and one or more output extensions.
- For more information on build extensions, see https://github.com/dart-lang/build/blob/master/docs/writing_a_builder.md#configuring-outputs
Implementation
@override
Map<String, List<String>> get buildExtensions {
final outputFileName =
options.config['output_file_name'] as String? ?? 'json_factory';
final outputPath = options.config['output_path'] as String? ?? 'lib';
// Calculate relative path from lib/
String relativePath;
if (outputPath == 'lib') {
relativePath = '$outputFileName.dart';
} else if (outputPath.startsWith('lib/')) {
relativePath = '${outputPath.substring(4)}/$outputFileName.dart';
} else {
relativePath = '$outputPath/$outputFileName.dart';
}
return {
r'$lib$': [relativePath]
};
}