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 {
  Logger.success(
      'When making changes to the flutter app, run this command to rebuild the project.\n');

  // flutter build web --csp --no-web-resources-cdn
  // --csp                   : no dynamically generated (eval'd) code, required by the extension CSP.
  // --no-web-resources-cdn  : bundle CanvasKit locally instead of loading it from the gstatic CDN,
  //                           which an extension's Content-Security-Policy would otherwise block.
  // NOTE: the old `--web-renderer html` flag was removed in Flutter 3.29, so it is no longer passed.
  final process = await Process.start(
    'flutter',
    ["build", "web", "--csp", "--no-web-resources-cdn"],
    runInShell: true,
    // STREAM flutter's own stdout/stderr straight to the terminal so build
    // progress AND errors are visible.
    mode: ProcessStartMode.inheritStdio,
  );

  // WAIT for the build to actually finish and propagate its exit code,
  // so failures surface (and break CI) instead of being silently swallowed.
  final exitCode = await process.exitCode;
  if (exitCode != 0) {
    Logger.error('\n❌ flutter build failed (exit code: $exitCode)\n');
    exit(exitCode);
  }

  Logger.success('\n✅ Build complete. Output is in build/web\n');
}