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", "");
  final firestore = firebase.getAsMap("firestore");
  final enableFirestore = firestore.get("enable", false);
  final firestorePrimaryRemoteIndex =
      firestore.get("primary_remote_index", false);
  final enableFunctions = firebase.getAsMap("functions").get("enable", false);
  final enableDataConnect =
      firebase.getAsMap("dataconnect").get("enable", false);
  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;
  }
  if (enableFirestore) {
    if (firestorePrimaryRemoteIndex) {
      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.firestore);
  }
  if (enableFunctions) {
    context.requestFirebaseDeploy(FirebaseDeployPostActionType.functions);
  }
  if (enableDataConnect) {
    context.requestFirebaseDeploy(FirebaseDeployPostActionType.dataconnect);
  }
  // await command(
  //   "Run firebase deploy",
  //   [
  //     firebaseCommand,
  //     "deploy",
  //   ],
  //   workingDirectory: firebaseDir.path,
  // );
}