runAssetGen function

Future<void> runAssetGen(
  1. List<String> args
)

Implementation

Future<void> runAssetGen(List<String> args) async {
  final config = AssetConfig.fromArgs(args);

  print("📂 Parsing pubspec.yaml...");
  final allAssets = await AssetGeneratorHelper.parseAssetsFromPubspec();

  // Filter by includePaths if set
  final assets = config.includePaths.isNotEmpty
      ? allAssets
          .where((a) => config.includePaths.any((p) => a.startsWith(p)))
          .toList()
      : allAssets;

  if (assets.isEmpty) {
    print("⚠️ No assets found.");
    return;
  }

  // Ensure output dir exists
  if (!config.outputDirectory.existsSync()) {
    config.outputDirectory.createSync(recursive: true);
  }

  if (config.allInOne) {
    print("📝 Generating all-in-one assets file...");
    await AssetGeneratorHelper.generateAllInOne(assets, config);
  } else {
    print("📝 Generating separate assets files...");
    await AssetGeneratorHelper.generateSeparate(assets, config);
  }

  print("✅ Asset generation completed!");
}