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(
        'Page name is empty, add a new page with "morpheme page <page-name> -f <feature-name>"');
  }

  final appsName = (argResults?['apps-name'] as String? ?? '').snakeCase;
  final pathApps = join(current, 'apps', appsName);
  String featureName =
      (argResults?['feature-name'] as String? ?? '').snakeCase;
  final pageName = (argResults?.rest.first ?? '').snakeCase;
  if (appsName.isNotEmpty && !RegExp('^${appsName}_').hasMatch(featureName)) {
    featureName = '${appsName}_$featureName';
  }

  if (appsName.isNotEmpty && !exists(pathApps)) {
    StatusHelper.failed(
        'Apps with "$appsName" does not exists, create a new apps with "morpheme apps <apps-name>"');
  }

  String pathFeature = join(current, 'features', featureName);
  if (appsName.isNotEmpty) {
    pathFeature = join(pathApps, 'features', featureName);
  }

  if (!exists(pathFeature)) {
    StatusHelper.failed(
        'Feature with "$featureName" does not exists, create a new feature with "morpheme feature <feature-name>"');
  }

  String pathPage = join(pathFeature, 'lib', pageName);
  if (exists(pathPage)) {
    StatusHelper.failed('Page already exists.');
  }

  final className = pageName.pascalCase;
  final methodName = pageName.camelCase;

  createDataDataSource(pathPage, pageName, className, methodName);
  createDataModelBody(pathPage, pageName, className, methodName);
  createDataModelResponse(pathPage, pageName, className, methodName);
  createDataRepository(pathPage, pageName, className, methodName);

  createDomainEntity(pathPage, pageName, className, methodName);
  createDomainRepository(pathPage, pageName, className, methodName);
  createDomainUseCase(pathPage, pageName, className, methodName);

  createPresentationBloc(pathPage, pageName, className, methodName);
  createPresentationCubit(pathPage, pageName, className, methodName);
  createPresentationPage(pathPage, pageName, className, methodName);
  createPresentationWidget(pathPage, pageName, className, methodName);

  createLocator(pathPage, pageName, className, methodName);
  appendLocatorFeature(
      pathFeature, featureName, pageName, className, methodName);

  await ModularHelper.format([pathFeature]);

  StatusHelper.success('generate page $pageName in feature $featureName');
}