run function

FutureOr run(
  1. List<String> args
)

Implementation

FutureOr run(List<String> args) async {
  String directory = absolute('');
  String dir = basename(directory);
  String file = '';

  if (args.length > 1) {
    String f = args[1];

    if (File(f).existsSync()) {
      file = f;
    }
  } else {
    List files = [
      'bin/main.dart',
      'bin/$dir.dart',
    ];

    for (var f in files) {
      if (File(f).existsSync()) {
        file = f;
        break;
      }
    }
  }

  if (!file.contains('.dart')) {
    print('Could not find the target file to run...');
    return;
  }

  Process process = await _createProcess(file);
  bool isLoading = false;

  print('Starting...');
  print('');

  ProcessSignal.sigint.watch().listen((event) {
    process.exitCode.then((_) => exit(0));
    process.kill();
  });

  DirectoryWatcher(directory).events.listen((event) {
    process.exitCode.then((code) async {
      if (!isLoading) {
        print('Reloading...');
        print('');
        isLoading = true;
        process = await _createProcess(file);
        isLoading = false;
      }
    });
    process.kill();
  });
}