run method

  1. @override
void run()
override

Runs this command.

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

Implementation

@override
void run() async {
  final rest = argResults?.rest ?? [];
  if (rest.isEmpty) {
    StatusHelper.failed(
        'App name is empty, you can create flutter apps with "morpheme create <app-name>"');
  }

  final appName = rest.first;
  final workingDirectory = join(current, appName);

  if (exists(workingDirectory)) {
    StatusHelper.failed('Directory with $appName is already exists');
  }

  final bool refactor = argResults?['refactor'] ?? false;
  final tag =
      argResults?['tag'] != null ? '-b ${argResults?['tag']} --depth 1' : '';
  final applicationId = argResults?['application-id'] != null
      ? '--application-id "${argResults?['application-id']}"'
      : '';

  await 'git clone https://github.com/morphemedesign/morpheme-flutter.git $appName $tag'
      .run;

  deleteDir(join(workingDirectory, '.git'));
  await 'morpheme init --app-name "$appName" $applicationId'
      .start(workingDirectory: workingDirectory);
  if (refactor) {
    final includeLibrary =
        (argResults?['include-library'] ?? false) ? '--include-library' : '';
    await 'morpheme refactor --old-name="morpheme" --new-name="$appName" $includeLibrary'
        .start(workingDirectory: workingDirectory);
  } else {
    await 'morpheme get'.start(workingDirectory: workingDirectory);
  }
  await 'morpheme config'.start(workingDirectory: workingDirectory);

  StatusHelper.generated(workingDirectory);
}