execute method
Implementation
@override
void execute(List<String> arguments) async {
DirectoryWatcher watcher = DirectoryWatcher(Directory.current.path);
Timer? timer;
String? vmService;
if (arguments.isNotEmpty && arguments[0].toLowerCase() == '--vm') {
vmService = '--enable-vm-service';
}
Process? process = await _serve(vmService);
/// save process info on `.dartTool` folder for upcoming serve features
/// like down, up, etc
_updateDartToolVaniaConfig(process);
watcher.events.listen((event) async {
if (path.extension(event.path) == '.dart') {
print("\x1B[32m File changed: ${path.basename(event.path)} \x1B[0m");
print("Restarting the server....");
if (timer != null) {
timer?.cancel();
}
timer = Timer(Duration(milliseconds: 100), () async {
process?.kill();
int? exitCode = await process?.exitCode;
if (exitCode.toString().isNotEmpty) {
process = await _serve(vmService);
}
});
}
});
ProcessSignal.sigint.watch().listen((signal) {
print('Stopping the server...');
Timer(Duration(milliseconds: 100), () {
if (timer != null) {
timer?.cancel();
}
process?.kill();
print('Server down');
exit(0);
});
});
}