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 path = context.args.get(3, "");
if (path.isEmpty) {
error(
"[path] is not specified. Please enter [path] according to the following command.\r\nkatana code cache [path]\r\n",
);
return;
}
label("Retrieve firebase project ID");
final firebasercFile = File("firebase/.firebaserc");
if (!firebasercFile.existsSync()) {
error("Firebase project ID is not found.");
return;
}
final firebaserc = await firebasercFile.readAsString();
final json = jsonDecodeAsMap(firebaserc);
final projectId = json.getAsMap("projects").get("default", "");
label("Create a server code for the scheduler in `$directory/$path.ts`.");
final parentPath = path.parentPath();
if (parentPath.isNotEmpty) {
final parentDir = Directory("$directory/$parentPath");
if (!parentDir.existsSync()) {
await parentDir.create(recursive: true);
}
}
await generateDartCode("$directory/$path", path, ext: "ts");
await generateDartTestCode(
"$testDirectory/$path",
path,
ext: "test.ts",
filter: (text) {
return text.replaceAll(r"${testProjectId}", projectId);
},
);
}