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 bin = context.yaml.getAsMap("bin");
final openssl = bin.get("openssl", "openssl");
final app = context.yaml.getAsMap("app");
if (app.isEmpty) {
error("The item [app] is missing. Please add an item.");
return;
}
final csr = app.getAsMap("csr");
if (csr.isEmpty) {
error("The item [app]->[csr] is missing. Please add an item.");
return;
}
final email = csr.get("email", "");
if (email.isEmpty) {
error(
"The item [app]->[csr]->[email] is missing. Please provide an email address to create a CertificateSigningRequest.",
);
return;
}
if (!File("ios/CertificateSigningRequest.certSigningRequest")
.existsSync()) {
label("Create a CertificateSigningRequest.certificateSigningRequest");
final process = await Process.start(
openssl,
[
"req",
"-nodes",
"-newkey",
"rsa:2048",
"-keyout",
"ios/ios_enterprise.key",
"-out",
"ios/CertificateSigningRequest.certSigningRequest",
],
runInShell: true,
mode: ProcessStartMode.normal,
);
// ignore: avoid_print
process.stdout.transform(utf8.decoder).forEach(print);
process.stdin.write(".\n");
process.stdin.write(".\n");
process.stdin.write(".\n");
process.stdin.write(".\n");
process.stdin.write(".\n");
process.stdin.write(".\n");
process.stdin.write("$email\n");
process.stdin.write("\n");
process.stdin.write("\n");
await process.exitCode;
}
label("Rewrite `.gitignore`.");
final gitignore = File("ios/.gitignore");
if (!gitignore.existsSync()) {
error("Cannot find `ios/.gitignore`. Project is broken.");
return;
}
final gitignores = await gitignore.readAsLines();
if (context.yaml.getAsMap("git").get("ignore_secure_file", true)) {
if (!gitignores.any((e) => e.startsWith("**/*.p12"))) {
gitignores.add("**/*.p12");
}
if (!gitignores.any((e) => e.startsWith("**/*.p8"))) {
gitignores.add("**/*.p8");
}
if (!gitignores.any((e) => e.startsWith("**/*.mobileprovision"))) {
gitignores.add("**/*.mobileprovision");
}
if (!gitignores.any((e) => e.startsWith("**/*.pem"))) {
gitignores.add("**/*.pem");
}
if (!gitignores.any((e) => e.startsWith("**/*.cer"))) {
gitignores.add("**/*.cer");
}
if (!gitignores.any((e) => e.startsWith("**/*.certSigningRequest"))) {
gitignores.add("**/*.certSigningRequest");
}
if (!gitignores
.any((e) => e.startsWith("**/ios_certificate_password.key"))) {
gitignores.add("**/ios_certificate_password.key");
}
if (!gitignores.any((e) => e.startsWith("**/ios_enterprise.key"))) {
gitignores.add("**/ios_enterprise.key");
}
} else {
gitignores.removeWhere((e) => e.startsWith("**/*.p12"));
gitignores.removeWhere((e) => e.startsWith("**/*.p8"));
gitignores.removeWhere((e) => e.startsWith("**/*.mobileprovision"));
gitignores.removeWhere((e) => e.startsWith("**/*.pem"));
gitignores.removeWhere((e) => e.startsWith("**/*.cer"));
gitignores.removeWhere((e) => e.startsWith("**/*.certSigningRequest"));
gitignores
.removeWhere((e) => e.startsWith("**/ios_certificate_password.key"));
gitignores.removeWhere((e) => e.startsWith("**/ios_enterprise.key"));
}
await gitignore.writeAsString(gitignores.join("\n"));
}