build method
Generates the outputs for a given BuildStep
.
Implementation
@override
FutureOr<void> build(BuildStep buildStep) async {
final scope = (config.scopes).whereType<String?>().firstWhere(
(element) =>
element != null && Glob(element).matches(buildStep.inputId.path),
orElse: () => null,
);
if (scope == null) {
return;
}
final assets = buildStep.findAssets(Glob(scope));
final assetsPathGlob = Glob(config.assetsPath);
final parseResource = await buildStep.fetchResource(_graphqlParserResource);
final entries = await assets
.where((asset) => assetsPathGlob.matches(asset.path))
.asyncMap(
(event) async => MapEntry(
event,
await parseResource.readFile(buildStep, event),
),
)
.map(
(event) => MapEntry(
event.key,
transform.transform(
config,
event.value,
),
),
)
.toList();
final result = generate<AssetId>(
buildStep.inputId,
SchemaConfig<AssetId>(
entries: BuiltMap.of(Map.fromEntries(entries)),
lookupPath: (id) => _resolveOutputDir(
p.dirname(id.path),
p.basename(id.path) + ".dart",
),
),
config,
);
final targetAsset = buildStep.inputId.addExtension('.dart');
_writeProgram(
config,
buildStep,
AssetId(
targetAsset.package,
_resolveOutputDir(
p.dirname(targetAsset.path),
p.basename(targetAsset.path),
),
),
result,
);
}