run method

  1. @override
Future<void> run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
Future<void> run() async {
  if (argResults!['workspaces'] as bool) {
    final workspaces = WorkspaceManager(projectDir);
    final path = workspaces.root.path;
    if (await workspaces.removeAll()) {
      Logger.success('Deleted parallel build workspaces at $path');
    } else {
      Logger.info('No parallel build workspaces for this project.');
    }
    return;
  }

  final config = ConfigService(projectDir);
  final cleanup = CleanupService(projectDir: projectDir, config: config);

  Logger.phase('Restoring Project State');
  final hadBackups = Directory(p.join(projectDir, '.udara')).existsSync();
  final kept = config.keptClient();
  if (kept != null) {
    Logger.info('Undoing "whitelabel --keep" for "$kept"...');
  }
  await cleanup.performFullCleanup();

  // Projects branded with --keep before udara_cli 1.3.1 have no backups
  // to restore from; repair the sections udara_cli manages from the last
  // commit instead.
  if (!hadBackups) _repairManagedSectionsFromLastCommit();

  final appConfig = AppConfigService(projectDir, config);
  // A root .env left by an earlier run (e.g. before this project moved to
  // generated config) is only udara_cli's staging: remove it.
  if (appConfig.settings.isGenerated && appConfig.isStagedRootEnv()) {
    await File('$projectDir/.env').delete();
    Logger.info(
        'Removed the root .env udara_cli had staged (not needed in generated mode).');
  }
  final defaultEnv =
      File('${clientsDir.path}/${WhiteLabelService.defaultClientName}/.env');
  if (appConfig.settings.isGenerated && defaultEnv.existsSync()) {
    await appConfig.write(
        client: WhiteLabelService.defaultClientName,
        envFile: defaultEnv,
        isTest: false,
        trackForCleanup: false);
    Logger.info(
        'Regenerated ${appConfig.settings.output} for the default client.');
  }

  Logger.phase('Flutter Clean');
  await runShell('flutter clean');
  Logger.success('Project cleaned successfully.');
}