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 firebase = context.yaml.getAsMap("firebase");
  final projectId = firebase.get("project_id", "");
  final firestore = firebase.getAsMap("firestore");
  final database = firestore.getAsList<String>("database");
  if (projectId.isEmpty) {
    error(
      "The item [firebase]->[project_id] is missing. Please provide the Firebase project ID for the configuration.",
    );
    return;
  }
  label("Set firebase firestore config.");
  final file = File("firebase/firebase.json");
  final json = jsonDecodeAsMap(await file.readAsString());
  if (database.isEmpty) {
    json["firestore"] = {
      "rules": "firestore.rules",
      "indexes": "firestore.indexes.json",
    };
  } else {
    json["firestore"] = database
        .map((name) => {
              "database": name,
              "rules": "firestore.rules",
              "indexes": "firestore.indexes.json"
            })
        .toList();
  }
  await file.writeAsString(jsonEncode(json));
}