configureApp function

Future<Map<String, dynamic>?> configureApp(
  1. ConfigureCommandModel callModel
)

Configures an application clone based on a provided ConfigureCommandModel.

This function orchestrates the entire configuration process for a specific client ID, including:

  • Saving the last used client ID.
  • Parsing the client's configuration file.
  • Performing initial setup steps (package renaming, Firebase integration, asset replacement).
  • Managing and updating application versions.
  • Running necessary build commands for launcher icons and splash screens.

It provides robust error handling and ensures that the process can be controlled by various flags within the callModel.

callModel A ConfigureCommandModel containing the client ID and various configuration flags.

Returns a Future<Map<String, dynamic>?> representing the final configuration JSON if successful, or null if the process is cancelled or fails at any stage.

Throws an Exception if an unhandled error occurs during the configuration process.

Implementation

Future<Map<String, dynamic>?> configureApp(
  ConfigureCommandModel callModel,
) async {
  saveLastClientId(callModel.clientId!);
  logger.i('🚀 Starting cloning process for client: ${callModel.clientId}');

  try {
    // Parse configuration file
    final Map<String, dynamic> configJson = await parseConfigFile(
      callModel.clientId!,
    );

    // Step 1: Perform initial setup (rename, Firebase, assets)
    if (!await _performInitialSetup(callModel, configJson)) {
      return null;
    }

    // Step 2: Handle version management
    final finalVersion = await _handleVersionManagement(callModel, configJson);
    if (finalVersion == null) {
      return null;
    }

    // Step 3: Run build commands
    if (!await _configureLauncherIconsAndSplashScreen(configJson)) {
      return null;
    }

    logger.i('✅ Successfully cloned app for ${callModel.clientId}!');
    return configJson;
  } catch (e) {
    logger.e('❌ Error during cloning: $e');
    rethrow;
  }
}