addNewFeatureInLocator method

void addNewFeatureInLocator(
  1. String pathFeature,
  2. String featureName,
  3. String appsName
)

Implementation

void addNewFeatureInLocator(
    String pathFeature, String featureName, String appsName) {
  String pathLocator = join(current, 'lib', 'locator.dart');
  if (appsName.isNotEmpty) {
    pathLocator = join(current, 'apps', appsName, 'lib', 'locator.dart');
  }

  if (!exists(pathLocator)) {
    return;
  }

  String locator = File(pathLocator).readAsStringSync();

  if (RegExp(r'(^(\s+)?void setup)', multiLine: true).hasMatch(locator)) {
    locator = locator.replaceAll(
      RegExp(r'(^(\s+)?void setup)', multiLine: true),
      '''import 'package:$featureName/locator.dart';

void setup''',
    );
  } else if (RegExp(r'(^(\s+)?Future<void> setup)', multiLine: true)
      .hasMatch(locator)) {
    locator = locator.replaceAll(
      RegExp(r'(^(\s+)?Future<void> setup)', multiLine: true),
      '''import 'package:$featureName/locator.dart';

Future<void> setup''',
    );
  }

  locator = locator.replaceAll(
    '}',
    '''  setupLocatorFeature${featureName.pascalCase}();
}''',
  );
  pathLocator.write(locator);

  StatusHelper.generated(pathLocator);
}