blob: 384d0df63752e1e43980ec7bcf9ab6cd456f1a80 [file]
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:io';
import 'package:data_assets/data_assets.dart';
import 'package:hooks/hooks.dart';
void main(List<String> args) async {
await build(args, (input, output) async {
final packageName = input.packageName;
final assetDirectory = Directory.fromUri(
input.packageRoot.resolve('assets/'),
);
// If assets are added, rerun hook.
output.dependencies.add(assetDirectory.uri);
await for (final dataAsset in assetDirectory.list()) {
if (dataAsset is! File) {
continue;
}
// The file path relative to the package root, with forward slashes.
final name = dataAsset.uri
.toFilePath(windows: false)
.substring(input.packageRoot.toFilePath(windows: false).length);
final forLinking = name.contains('2') || name.contains('3');
output.assets.data.add(
DataAsset(package: packageName, name: name, file: dataAsset.uri),
routing: forLinking && input.config.linkingEnabled
? const ToLinkHook('complex_link')
: const ToAppBundle(),
);
output.dependencies.add(dataAsset.uri);
}
});
}