run method
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');
}
final appsName = (argResults?.rest.first ?? '').snakeCase;
final pathApps = join(current, 'apps', appsName);
if (!exists(pathApps)) {
StatusHelper.failed('Apps with "$appsName" does not exists"');
}
if (exists(pathApps)) {
deleteDir(pathApps);
}
final pathLibLocator = join(current, 'lib', 'locator.dart');
String data = File(pathLibLocator).readAsStringSync();
data = data.replaceAll(
"import 'package:${appsName.snakeCase}/locator.dart';", '');
data = data.replaceAll("setupLocatorApps${appsName.pascalCase}();", '');
pathLibLocator.write(data);
final pathPubspec = join(current, 'pubspec.yaml');
String pubspec = File(pathPubspec).readAsStringSync();
pubspec = pubspec.replaceAll(
RegExp(
"\\s+${appsName.snakeCase}:\\s+path: ./apps/${appsName.snakeCase}"),
'',
);
pathPubspec.write(pubspec);
await '${FlutterHelper.getCommandDart()} format .'.run;
StatusHelper.success('removed apps $appsName');
}