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 algolia = firebase.getAsMap("algolia");
  final path = algolia.get("path", "").trimQuery().trimString("/");
  final appId = algolia.get("app_id", "");
  final apiKey = algolia.get("api_key", "");
  if (projectId.isEmpty) {
    error(
      "The item [firebase]->[project_id] is missing. Please provide the Firebase project ID for the configuration.",
    );
    return;
  }
  if (path.isEmpty) {
    error(
      "The item [firebase]->[algolia]->[path] is missing. Please provide the Algolia path for the configuration.",
    );
    return;
  }
  if (appId.isEmpty) {
    error(
      "The item [firebase]->[algolia]->[app_id] is missing. Please provide the Algolia App ID for the configuration.",
    );
    return;
  }
  if (apiKey.isEmpty) {
    error(
      "The item [firebase]->[algolia]->[api_key] is missing. Please provide the Algolia Api Key for the configuration.",
    );
    return;
  }
  if (!Directory("firebase/functions").existsSync()) {
    error(
        "The item [firebase]->[funcctions]->[enable] is false. Please enable this and initialize Functions.");
    return;
  }
  await addFlutterImport(
    [
      "masamune_model_algolia",
    ],
  );
  label("Add firebase functions");
  final functions = Fuctions();
  await functions.load();
  if (!functions.functions.any((e) => e.startsWith("algolia"))) {
    functions.functions.add("algolia({path: \"$path\"})");
  }
  await functions.save();
  label("Set firebase functions config.");
  final env = FunctionsEnv();
  await env.load();
  env["ALGOLIA_APPID"] = appId;
  env["ALGOLIA_APIKEY"] = apiKey;
  await env.save();
  context.requestFirebaseDeploy(FirebaseDeployPostActionType.functions);
  // await command(
  //   "Deploy firebase functions.",
  //   [
  //     firebaseCommand,
  //     "deploy",
  //     "--only",
  //     "functions",
  //   ],
  //   workingDirectory: "firebase",
  // );
}