addNewFeatureInLocator method
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);
}