findArtifact method
Searches for a compiled artifact matching format within the build directory of projectPath.
Returns the normalized absolute or relative path to the artifact, or null if not found.
Implementation
Future<String?> findArtifact({
required String projectPath,
required BuildFormat format,
}) async {
final buildDir = Directory(p.join(projectPath, 'build'));
if (!await buildDir.exists()) {
return null;
}
// Platform-standard output directory candidates
final List<String> candidateSubDirs;
switch (format) {
case BuildFormat.appbundle:
candidateSubDirs = [
p.join(buildDir.path, 'app', 'outputs', 'bundle', 'release'),
p.join(buildDir.path, 'app', 'outputs', 'bundle'),
];
break;
case BuildFormat.apk:
candidateSubDirs = [
p.join(buildDir.path, 'app', 'outputs', 'flutter-apk'),
p.join(buildDir.path, 'app', 'outputs', 'apk', 'release'),
];
break;
case BuildFormat.ipa:
candidateSubDirs = [
p.join(buildDir.path, 'ios', 'ipa'),
p.join(buildDir.path, 'ios', 'archive'),
];
break;
}
final ext = format.extension;
// Check high-probability candidate directories first
for (final candidate in candidateSubDirs) {
final dir = Directory(candidate);
if (await dir.exists()) {
final match = await _findLatestFileWithExtension(dir, ext);
if (match != null) return match;
}
}
// Fallback: search entire build/ directory
return await _findLatestFileWithExtension(buildDir, ext, recursive: true);
}