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 gmail = context.yaml.getAsMap("gmail");
final gmailUserId = gmail.get("user_id", "");
final gmailUserPassword = gmail.get("user_password", "");
final firebase = context.yaml.getAsMap("firebase");
final projectId = firebase.get("project_id", "");
if (gmailUserId.isEmpty) {
error(
"If [gmail]->[enable] is enabled, please include [gmail]->[user_id].",
);
return;
}
if (gmailUserPassword.isEmpty) {
error(
"If [gmail]->[enable] is enabled, please include [gmail]->[user_password].",
);
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("gmail"))) {
functions.functions.add("gmail()");
}
await functions.save();
label("Set firebase functions config.");
final env = FunctionsEnv();
await env.load();
env["MAIL_GMAIL_ID"] = gmail.get("user_id", "");
env["MAIL_GMAIL_PASSWORD"] = gmail.get("user_password", "");
await env.save();
context.requestFirebaseDeploy(FirebaseDeployPostActionType.functions);
// await command(
// "Deploy firebase functions.",
// [
// firebaseCommand,
// "deploy",
// "--only",
// "functions",
// ],
// workingDirectory: "firebase",
// );
}