uploadToAppCenter method

Future<void> uploadToAppCenter({
  1. required String appName,
  2. required File file,
  3. String? ownerName,
  4. Secret? apiToken,
  5. List<String> distributionGroups = defaultDistributionGroups,
  6. bool notifyListeners = true,
})

Implementation

Future<void> uploadToAppCenter({
  required String appName,
  required File file,
  String? ownerName,
  Secret? apiToken,
  List<String> distributionGroups = defaultDistributionGroups,
  bool notifyListeners = true,
}) async {
  ImpaktfullCliLogger.setSpinnerPrefix('AppCenter upload');
  ImpaktfullCliLogger.startSpinner('Initializing');
  final ownerNameValue =
      ownerName ?? ImpaktfullCliEnvironmentVariables.getAppCenterOwnerName();
  final apiTokenSecret =
      apiToken ?? ImpaktfullCliEnvironmentVariables.getAppCenterToken();

  ImpaktfullCliLogger.startSpinner('Create new release');
  final createNewReleaseUploadResponse = await _createNewRelease(
    appName: appName,
    ownerName: ownerNameValue,
    apiToken: apiTokenSecret,
  );
  final id = createNewReleaseUploadResponse['id'] as String;
  final packageAssetId =
      createNewReleaseUploadResponse['package_asset_id'] as String;
  final urlEncodedToken =
      createNewReleaseUploadResponse['url_encoded_token'] as String;

  final fileSizeBytes = await file.length();
  final appType = _getAppTypeFor(file);
  ImpaktfullCliLogger.verbose('Detected: $appType meme type fo ${file.path}');

  ImpaktfullCliLogger.startSpinner('Upload to get chunk size');
  final chunkSize = await _uploadMetadata(
    packageAssetId: packageAssetId,
    file: file,
    fileSize: fileSizeBytes,
    urlEncodedToken: urlEncodedToken,
    appType: appType,
    apiToken: apiTokenSecret,
  );

  ImpaktfullCliLogger.startSpinner('Splitting file into chunks');
  // =========CREATE FOLDER TEMP/SPLIT TO STORAGE LIST CHUNK FILE AFTER SPLIT==========
  final tempDirectory = Directory(join(_tempDirectoryPath, 'split'));
  if (!tempDirectory.existsSync()) {
    tempDirectory.createSync(recursive: true);
  }

  // =========SPLIT FILE==========
  await _splitFile(
    inputFile: file,
    outputDirectory: tempDirectory,
    chunkSize: chunkSize,
  );

  // =========UPLOAD CHUNK==========
  await _uploadChunks(
    packageAssetId: packageAssetId,
    urlEncodedToken: urlEncodedToken,
    tempDirectory: tempDirectory,
    appType: appType,
  );

  ImpaktfullCliLogger.startSpinner('Confirming upload');
  // =========FINISHED==========
  await _finishUpload(
    packageAssetId: packageAssetId,
    urlEncodedToken: urlEncodedToken,
    apiToken: apiTokenSecret,
  );

  ImpaktfullCliLogger.startSpinner('Committing release');
  // =========COMMIT==========
  await _commitRelease(
    id: id,
    appName: appName,
    ownerName: ownerNameValue,
    apiToken: apiTokenSecret,
  );

  ImpaktfullCliLogger.startSpinner('Checking if release is ready');
  // =========POLL RESULT==========
  final releaseId = await _validateRelease(
    id: id,
    appName: appName,
    ownerName: ownerNameValue,
    apiToken: apiTokenSecret,
  );

  ImpaktfullCliLogger.startSpinner('Distribute release to correct groups');
  // =========DISTRIBUTE==========
  final distributionUrl = await _distributeRelease(
    appName: appName,
    ownerName: ownerNameValue,
    releaseId: releaseId,
    distributionGroups: distributionGroups,
    notifyListeners: notifyListeners,
    apiToken: apiTokenSecret,
  );
  ImpaktfullCliLogger.clearSpinnerPrefix();
  ImpaktfullCliLogger.logSeperator();
  ImpaktfullCliLogger.log('Release $releaseId is ready!!! 🎉🎉🎉');
  ImpaktfullCliLogger.log(distributionUrl);
  ImpaktfullCliLogger.logSeperator();
  await cleanup();
}