processFilesArgs method

Future<void> processFilesArgs()

Processes and validates file arguments before publishing.

Handles file path resolution, validation, and binary file location. Supports both direct file paths and directory scanning for matching binary types. Automatically copies files from build outputs when needed.

File processing logic:

  • Validates file path is not empty
  • If directory path: scans for files matching binaryType
  • For Android (apk/aab): copies from build output directories
  • For iOS (ipa): copies from iOS build output directory
  • Updates filePath to point to the resolved binary file

Throws errors for:

  • Empty file paths
  • Invalid binary types
  • Missing binary files in specified directories

Implementation

Future<void> processFilesArgs() async {
  if (filePath.isEmpty) {
    logger.logErrorVerbose.call("File path is empty");
  }

  // Check if the file path is a directory
  if (await FileSystemEntity.isDirectory(filePath)) {
    final binaryType = this.binaryType;
    final dir = Directory(filePath);

    // If directory exists but doesn't contain binary files of the specified type
    if (dir.existsSync() &&
        dir
            .listSync()
            .where((item) => item.path.endsWith(binaryType))
            .isEmpty) {
      // Handle Android binary types (APK and AAB)
      if ((binaryType == "apk" || binaryType == "aab")) {
        filePath = await _copyFromCandidateSources(
              targetDir: filePath,
              binaryType: binaryType,
              sources: _androidSourceCandidates,
            ) ??
            "";
      }
      // Handle iOS binary type (IPA)
      else if (binaryType == "ipa") {
        filePath = await _copyFromCandidateSources(
              targetDir: filePath,
              binaryType: binaryType,
              sources: _iosSourceCandidates,
            ) ??
            "";
      } else {
        logger.logErrorVerbose.call("Invalid binary type: $binaryType");
      }
    } else {
      // Find the first file matching the binary type in the directory
      filePath = Directory(filePath)
          .listSync()
          .firstWhere(
            (element) =>
                element is File && element.path.endsWith(this.binaryType),
          )
          .path;
    }
  }

  // Final validation that file path is not empty
  if (filePath.isEmpty) {
    logger.logErrorVerbose.call("File path is empty");
  }
}