exec method

  1. @override
Future<void> exec(
  1. ExecContext context
)
override

Run command.

The contents of katana.yaml and the arguments of the command are passed to context.

コマンドを実行します。

contextkatana.yamlの内容やコマンドの引数が渡されます。

Implementation

@override
Future<void> exec(ExecContext context) async {
  final bin = context.yaml.getAsMap("bin");
  final firebaseCommand = bin.get("firebase", "firebase");
  final firebase = context.yaml.getAsMap("firebase");
  final projectId = firebase.get("project_id", "");
  if (projectId.isEmpty) {
    error(
      "The item [firebase]->[project_id] is missing. Please provide the Firebase project ID for the configuration.",
    );
    return;
  }
  label("Check firebase directory");
  final firebaseDir = Directory("firebase");
  if (!firebaseDir.existsSync()) {
    error(
      "Firebase directory is not created, please initialize Firebase with katana apply.",
    );
    return;
  }
  label("Import firestore.indexes.json");
  final firestoreIndexes = File("${firebaseDir.path}/firestore.indexes.json");
  final indexData = await command(
    "Import indexes.",
    [
      firebaseCommand,
      "firestore:indexes",
    ],
    workingDirectory: firebaseDir.path,
  );
  await firestoreIndexes.writeAsString(indexData);
  context.requestFirebaseDeploy(FirebaseDeployPostActionType.functions);
  // await command(
  //   "Run firebase deploy",
  //   [
  //     firebaseCommand,
  //     "deploy",
  //   ],
  //   workingDirectory: firebaseDir.path,
  // );
}