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 {
  /// Проверяем, установлен ли на машине Flutter и можем ли мы до него добраться
  final isFlutterAvailable = await CLI.checkIfFlutterAvailable();
  if (!isFlutterAvailable) {
    throw FlutterNotInstalledException();
  } else {
    printSuccess("Flutter SDK найден в системе\n");
  }

  /// Получаем пользовательский инпут
  final projectPath = getUserInput<String>(
    helpPhrase: "Путь для проекта",
    defaultValue: './a2soft_project',
  );
  final projectName = getUserInput<String>(
    helpPhrase: "Название для проекта",
    defaultValue: 'a2soft_project',
  );
  final database = getUserInput<bool>(
    helpPhrase: "Подключить к проекту базу данных?",
    defaultValue: false,
  );
  final localization = getUserInput<bool>(
    helpPhrase: "Подключить к проекту локализацию?",
    defaultValue: false,
  );
  final cookieManager = getUserInput<bool>(
    helpPhrase: "Подключить к проекту менеджер куков?",
    defaultValue: false,
  );
  final loaderKit = getUserInput<bool>(
    helpPhrase: "Подключить к проекту библиотеку лоадеров?",
    defaultValue: false,
  );
  final globalLoader = getUserInput<bool>(
    helpPhrase: "Подключить к проекту глобальный лоадер?",
    defaultValue: false,
  );
  final nativeDialog = getUserInput<bool>(
    helpPhrase: "Подключить к проекту нативные диалоги?",
    defaultValue: false,
  );
  final cacheInterceptor = getUserInput<bool>(
    helpPhrase: "Подключить к проекту кеширующий обработчик?",
    defaultValue: false,
  );

  /// Создаем проект командой [flutter create <DESTINATION>]
  final isCreated = await CLI.createNewProject(projectPath, projectName);
  if (isCreated) {
    printSuccess("Проект успешно создан по пути: $projectPath \n");
  } else {
    throw CreateProjectException();
  }

  /// Находим pubspec в проекте
  final pubspec = File("$projectPath/pubspec.yaml");
  if (!(pubspec.existsSync() && _isPubspec(pubspec))) {
    throw PubspecNotFoundException();
  } else {
    printSuccess("pubspec.yaml найден в созданном проекте\n");
  }

  /// Устанавливаем  пакеты
  installBasePackages(pubspec);
  if (database) {
    installDatabase(pubspec);
  }
  if (cacheInterceptor) {
    installDioCacheInterceptor(pubspec);
  }
  if (localization) {
    installLocalization(pubspec);
  }
  if (nativeDialog) {
    installAdaptiveDialog(pubspec);
  }
  if (globalLoader) {
    installGlobalLoader(pubspec);
  }
  if (loaderKit) {
    installLoaderKit(pubspec);
  }
  if (cookieManager) {
    installCookieManager(pubspec);
  }

  print("Вставляем code samples...");
  await generateBundle(
    path: projectPath + '/lib',
    bundle: projectCodeSamplesBundle,
    params: {
      "project_name": projectName,
      "is_localization": localization,
      "is_database": database,
    },
  );
  printSuccess("Готово!");

  await Future.delayed(Duration(seconds: 2));

  print("Получение пакетов...");
  await CLI.getPackages();
  printSuccess("Готово!");

  await Future.delayed(Duration(seconds: 2));

  print("Генерация файлов...");
  await CLI.runDartGenerator(projectPath);
  await CLI.runFormatter(projectPath);
  printSuccess("Готово!");
}