Reland "Migration: fix generate_resources.dart to use `dart compile js`."

This is a reland of commit 6abea1381bdc8d5dd5ea6784b59a5c639fb249de

Original change's description:
> Migration: fix generate_resources.dart to use `dart compile js`.
>
> This is necessary because the command `dart2js` is no longer present
> in the SDK.
>
> Change-Id: Iea3cf3092bcda6c889c55a51d1b5601773404fb9
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/253862
> Reviewed-by: Samuel Rawlins <srawlins@google.com>
> Commit-Queue: Paul Berry <paulberry@google.com>

Change-Id: Ibc25641aca165b578b2c4348ef0b841263298e3c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/255740
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
diff --git a/pkg/nnbd_migration/tool/codegen/generate_resources.dart b/pkg/nnbd_migration/tool/codegen/generate_resources.dart
index 2ba2ae73..f76ff0e 100644
--- a/pkg/nnbd_migration/tool/codegen/generate_resources.dart
+++ b/pkg/nnbd_migration/tool/codegen/generate_resources.dart
@@ -18,7 +18,7 @@
   var argParser = ArgParser()
     ..addFlag('verify', negatable: false)
     ..addFlag('dev', negatable: false)
-    ..addOption('dart2js_path')
+    ..addOption('dart_path')
     ..addFlag('help', negatable: false);
   var argResults = argParser.parse(args);
   if (argResults['help'] == true) {
@@ -45,8 +45,7 @@
   if (verify) {
     verifyResourcesGDartGenerated();
   } else {
-    await compileWebFrontEnd(
-        devMode: dev!, dart2jsPath: dart2jsPath(argResults)!);
+    await compileWebFrontEnd(devMode: dev!, dartPath: dartPath(argResults)!);
 
     print('');
 
@@ -91,9 +90,11 @@
 }
 
 Future<void> compileWebFrontEnd(
-    {required bool devMode, required String dart2jsPath}) async {
-  // dart2js -m -o output source
-  var process = await Process.start(dart2jsPath, [
+    {required bool devMode, required String dartPath}) async {
+  // dart compile js -m -o output source
+  var process = await Process.start(dartPath, [
+    'compile',
+    'js',
     devMode ? '-O1' : '-m',
     '--no-frequency-based-minification',
     '-o',
@@ -121,14 +122,12 @@
   resourcesFile.writeAsStringSync(content);
 }
 
-/// Returns the dart2jsPath, either from [argResults] or the Platform.
-String? dart2jsPath(ArgResults argResults) {
-  if (argResults.wasParsed('dart2js_path')) {
-    return argResults['dart2js_path'] as String?;
+/// Returns the dartPath, either from [argResults] or the Platform.
+String? dartPath(ArgResults argResults) {
+  if (argResults.wasParsed('dart_path')) {
+    return argResults['dart_path'] as String?;
   } else {
-    var sdkBinDir = path.dirname(Platform.resolvedExecutable);
-    var dart2jsBinary = Platform.isWindows ? 'dart2js.bat' : 'dart2js';
-    return path.join(sdkBinDir, dart2jsBinary);
+    return Platform.resolvedExecutable;
   }
 }