exec method
Run command.
The contents of katana.yaml and the arguments of the command are passed to context.
コマンドを実行します。
contextにkatana.yamlの内容やコマンドの引数が渡されます。
Implementation
@override
Future<void> exec(ExecContext context) async {
final bin = context.yaml.getAsMap("bin");
final flutter = bin.get("flutter", "flutter");
final melos = bin.get("melos", "melos");
final builderArguments = _tidbSchemaBuilderArguments(context);
final builderShellArguments = _shellArguments(builderArguments);
final builderShellSuffix =
builderShellArguments.isEmpty ? "" : " $builderShellArguments";
var output = "";
void onOutput(Process process, String chunk) {
output += chunk;
if (output.contains("Built with build_runner")) {
_finalizeTidbSchemas(context);
output = "";
} else if (output.length > 4096) {
output = output.substring(output.length - 2048);
}
}
if (File("melos.yaml").existsSync()) {
await command(
"Watch build_runner for all packages to generate code.",
[
melos,
"exec",
"--",
"$flutter packages pub run build_runner watch "
"--delete-conflicting-outputs$builderShellSuffix",
],
action: onOutput,
catchError: true,
failOnStderr: false,
);
} else {
await command(
"Watch the project's build_runner to generate code.",
[
flutter,
"packages",
"pub",
"run",
"build_runner",
"watch",
"--delete-conflicting-outputs",
...builderArguments,
],
action: onOutput,
catchError: true,
failOnStderr: false,
);
}
}