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 {
  if (argResults?.rest.isEmpty ?? true) {
    StatusHelper.failed(
        'Apps name is empty, add a new apps with "morpheme apps <apps-name>"');
  }

  final appsName = (argResults?.rest.first ?? '').snakeCase;

  if (exists(join(current, 'apps', appsName))) {
    StatusHelper.failed('Apps already exists.');
  }

  final pathApp = join(current, 'apps', appsName);

  await addNewApps(pathApp, appsName);
  addNewAppsInLocator(pathApp, appsName);
  addNewAppsInPubspec(pathApp, appsName);
  addNewGitIgnore(pathApp, appsName);
  addNewAnalysisOption(pathApp, appsName);

  removeUnusedDir(pathApp, appsName);

  await ModularHelper.format([pathApp, '.']);

  await FlutterHelper.start('pub get', workingDirectory: pathApp);
  await FlutterHelper.run('pub get');

  StatusHelper.success('generate apps $appsName');
}