execute method

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

execute command

Implementation

@override
Future<void> execute() async {
  final menu = Menu([
    'Flutter Project',
    'Get Server',
  ], title: 'Select which type of project you want to create ?');
  final result = menu.choose();
  String? nameProject = name;
  if (name == '.') {
    // final dialog = CLI_Dialog(questions: [
    //   [LocaleKeys.ask_name_to_project.tr, 'name']
    // ]);
    nameProject = ask(LocaleKeys.ask_name_to_project.tr);
  }

  var path = Structure.replaceAsExpected(
      path: Directory.current.path + p.separator + nameProject.snakeCase);
  await Directory(path).create(recursive: true);

  Directory.current = path;

  if (result.index == 0) {
    // final dialog = CLI_Dialog(questions: [
    //   [
    //     '${LocaleKeys.ask_company_domain.tr} \x1B[33m '
    //         '${LocaleKeys.example.tr} com.yourcompany \x1B[0m',
    //     'org'
    //   ]
    // ]);

    var org = ask(
      '${LocaleKeys.ask_company_domain.tr} \x1B[33m '
      '${LocaleKeys.example.tr} com.yourcompany \x1B[0m',
    );

    final iosLangMenu =
        Menu(['Swift', 'Objective-C'], title: LocaleKeys.ask_ios_lang.tr);
    final iosResult = iosLangMenu.choose();

    var iosLang = iosResult.index == 0 ? 'swift' : 'objc';

    final androidLangMenu =
        Menu(['Kotlin', 'Java'], title: LocaleKeys.ask_android_lang.tr);
    final androidResult = androidLangMenu.choose();

    var androidLang = androidResult.index == 0 ? 'kotlin' : 'java';

    final linterMenu = Menu([
      'Yes',
      'No',
    ], title: LocaleKeys.ask_use_linter.tr);
    final linterResult = linterMenu.choose();

    await ShellUtils.flutterCreate(path, org, iosLang, androidLang);

    File('test/widget_test.dart').writeAsStringSync('');

    switch (linterResult.index) {
      case 0:
        if (PubspecUtils.isServerProject) {
          await PubspecUtils.addDependencies('lints',
              isDev: true, runPubGet: true);
          AnalysisOptionsSample(
                  include: 'include: package:lints/recommended.yaml')
              .create();
        } else {
          await PubspecUtils.addDependencies('flutter_lints',
              isDev: true, runPubGet: true);
          AnalysisOptionsSample(
                  include: 'include: package:flutter_lints/flutter.yaml')
              .create();
        }
        break;

      default:
        AnalysisOptionsSample().create();
    }
    await InitCommand().execute();
  } else {
    await InitGetServer().execute();
  }
}