run method

  1. @override
Future<void> run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
Future<void> run() async {
  try {
    // Start the build process on the current directory.
    log(
      "Starting ${builder.name.toLowerCase()} build in watch mode...",
      color: yellow,
    );

    // Watch for changes.
    await for (final event in directory.watch(recursive: true)) {
      if (!observedEvents.contains(event.type)) continue;

      final entity = FileSystemEntity.typeSync(event.path);

      if (entity == FileSystemEntityType.file) {
        // Skip if a build is already running.
        PrepareQueue.tryBuild(File(event.path), builder);
      }
    }
  } catch (error) {
    log("${builder.name} Error: $error", color: red);
  }
}