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 sendgrid = context.yaml.getAsMap("sendgrid");
final firebase = context.yaml.getAsMap("firebase");
final projectId = firebase.get("project_id", "");
final sendGridApiKey = sendgrid.get("api_key", "");
if (sendGridApiKey.isEmpty) {
error(
"If [sendgrid]->[enable] is enabled, please include [sendgrid]->[api_key].",
);
return;
}
if (projectId.isEmpty) {
error(
"The item [firebase]->[project_id] is missing. Please provide the Firebase project ID for the configuration.",
);
return;
}
final firebaseDir = Directory("firebase");
if (!firebaseDir.existsSync()) {
error(
"The directory `firebase` does not exist. Initialize Firebase by executing Firebase init.",
);
return;
}
final functionsDir = Directory("firebase/functions");
if (!functionsDir.existsSync()) {
error(
"The directory `firebase/functions` does not exist. Initialize Firebase by executing Firebase init.",
);
return;
}
await addFlutterImport(
[
"masamune_mail",
"katana_functions_firebase",
],
);
label("Add firebase functions");
final functions = Fuctions();
await functions.load();
if (!functions.functions.any((e) => e.startsWith("sendGrid"))) {
functions.functions.add("sendGrid()");
}
await functions.save();
label("Set firebase functions config.");
final env = FunctionsEnv();
await env.load();
env["MAIL_SENDGRID_APIKEY"] = sendgrid.get("api_key", "");
await env.save();
context.requestFirebaseDeploy(FirebaseDeployPostActionType.functions);
// await command(
// "Deploy firebase functions.",
// [
// firebaseCommand,
// "deploy",
// "--only",
// "functions",
// ],
// workingDirectory: "firebase",
// );
}