Skip to content

Commit

Permalink
feat: Added Agora.io settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrunet committed Apr 18, 2023
1 parent 034b633 commit c33753e
Show file tree
Hide file tree
Showing 6 changed files with 231 additions and 4 deletions.
102 changes: 102 additions & 0 deletions packages/katana_cli/lib/action/agora/agora.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Project imports:
import 'dart:io';

import 'package:katana_cli/katana_cli.dart';

/// Add a module to use Agora.io.
///
/// Agora.ioを利用するためのモジュールを追加します。
class AgoraCliAction extends CliCommand with CliActionMixin {
/// Add a module to use Agora.io.
///
/// Agora.ioを利用するためのモジュールを追加します。
const AgoraCliAction();

@override
String get description =>
"Add a module to use Agora.io. Agora.ioを利用するためのモジュールを追加します。";

@override
bool checkEnabled(ExecContext context) {
final value = context.yaml.getAsMap("agora");
final enabled = value.get("enable", false);
if (!enabled) {
return false;
}
return true;
}

@override
Future<void> exec(ExecContext context) async {
final bin = context.yaml.getAsMap("bin");
final flutter = bin.get("flutter", "flutter");
final firebaseCommand = bin.get("firebase", "firebase");
final agora = context.yaml.getAsMap("agora");
final appId = agora.get("app_id", "");
final appCertificate = agora.get("app_certificate", "");
final enableCloudRecording = agora.get("enable_cloud_recording", false);
final firebase = context.yaml.getAsMap("firebase");
final projectId = firebase.get("project_id", "");
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 command(
"Import packages.",
[
flutter,
"pub",
"add",
"masamune_agora",
"katana_functions_firebase",
],
);
label("Add firebase functions");
final functions = Fuctions();
await functions.load();
if (!functions.functions.any((e) => e == "agoraToken")) {
functions.functions.add("agoraToken");
}
if (enableCloudRecording &&
!functions.functions.any((e) => e == "agoraCloudRecording")) {
functions.functions.add("agoraCloudRecording");
}
await functions.save();
await command(
"Set firebase functions config.",
[
firebaseCommand,
"functions:config:set",
"agora.app_id=$appId",
"agora.app_certificate=$appCertificate",
],
workingDirectory: "firebase",
);
await command(
"Deploy firebase functions.",
[
firebaseCommand,
"deploy",
"--only",
"functions",
],
workingDirectory: "firebase",
);
}
}
41 changes: 41 additions & 0 deletions packages/katana_cli/lib/action/app/calendar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Project imports:
import 'package:katana_cli/katana_cli.dart';

/// Add a module to use the calendar.
///
/// カレンダーを利用するためのモジュールを追加します。
class AppCalendarCliAction extends CliCommand with CliActionMixin {
/// Add a module to use the calendar.
///
/// カレンダーを利用するためのモジュールを追加します。
const AppCalendarCliAction();

@override
String get description =>
"Add a module to use the calendar. カレンダーを利用するためのモジュールを追加します。";

@override
bool checkEnabled(ExecContext context) {
final value = context.yaml.getAsMap("app").getAsMap("calendar");
final enabled = value.get("enable", false);
if (!enabled) {
return false;
}
return true;
}

@override
Future<void> exec(ExecContext context) async {
final bin = context.yaml.getAsMap("bin");
final flutter = bin.get("flutter", "flutter");
await command(
"Import packages.",
[
flutter,
"pub",
"add",
"masamune_calendar",
],
);
}
}
41 changes: 41 additions & 0 deletions packages/katana_cli/lib/action/app/openai.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Project imports:
import 'package:katana_cli/katana_cli.dart';

/// Add a module to use OpenAI's API.
///
/// OpenAIのAPIを利用するためのモジュールを追加します。
class AppOpenAICliAction extends CliCommand with CliActionMixin {
/// Add a module to use OpenAI's API.
///
/// OpenAIのAPIを利用するためのモジュールを追加します。
const AppOpenAICliAction();

@override
String get description =>
"Add a module to use OpenAI's API. OpenAIのAPIを利用するためのモジュールを追加します。";

@override
bool checkEnabled(ExecContext context) {
final value = context.yaml.getAsMap("app").getAsMap("openai");
final enabled = value.get("enable", false);
if (!enabled) {
return false;
}
return true;
}

@override
Future<void> exec(ExecContext context) async {
final bin = context.yaml.getAsMap("bin");
final flutter = bin.get("flutter", "flutter");
await command(
"Import packages.",
[
flutter,
"pub",
"add",
"masamune_ai_openai",
],
);
}
}
6 changes: 6 additions & 0 deletions packages/katana_cli/lib/command/apply.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// Project imports:
import 'package:katana_cli/action/app/calendar.dart';
import 'package:katana_cli/action/app/csr.dart';
import 'package:katana_cli/action/app/icon.dart';
import 'package:katana_cli/action/app/keystore.dart';
import 'package:katana_cli/action/app/openai.dart';
import 'package:katana_cli/action/app/p12.dart';
import 'package:katana_cli/action/app/picker.dart';
import 'package:katana_cli/action/app/spread_sheet.dart';
import 'package:katana_cli/action/agora/agora.dart';
import 'package:katana_cli/action/firebase/init.dart';
import 'package:katana_cli/action/firebase/messaging.dart';
import 'package:katana_cli/action/firebase/terms_and_privacy.dart';
Expand All @@ -31,6 +34,9 @@ const _actions = <CliActionMixin>[
FirebaseTermsAndPrivacyCliAction(),
GitActionCliAction(),
GitPreCommitCliAction(),
AppOpenAICliAction(),
AppCalendarCliAction(),
AgoraCliAction(),
];

/// Reflect the settings in katana.yaml in the application project.
Expand Down
37 changes: 37 additions & 0 deletions packages/katana_cli/lib/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ app:
permission:
en: Use the library for profile images.
# Describe the settings for using the calendar.
# カレンダーを利用するための設定を記述します。
calendar:
enable: false
# Describe the settings for using OpenAI's GPT, etc.
# OpenAIのGPT等を利用するための設定を記述します。
openai:
enable: false
# This section contains information related to Firebase.
# Firebase関連の情報を記載します。
firebase:
Expand Down Expand Up @@ -204,5 +214,32 @@ store:
feature_image: document/feature.png
orientation: portrait
color: '000000'
# Configure Agora.io streaming settings.
# Agora.ioのストリーミング設定を行います。
agora:
# Set to `true` if you use Agora.io.
# Agora.ioを利用する場合は`true`にしてください。
enable: false
# AppID for Agora.
# Log in to the following URL and create a project.
# After the project is created, the AppID can be copied.
# Agora用のAppID。
# 下記URLにログインし、プロジェクトを作成します。
# プロジェクト作成後、AppIDをコピーすることができます。
# https://console.agora.io/projects
app_id:
# AppCertificate for Agora.
# You can obtain the certificate after entering the project you created and activating it in Security -> App certificate.
# Agora用のAppCertificate。
# 作成したプロジェクトに入り、Security -> App certificateにて有効化した後取得できます。
# https://console.agora.io/projects
app_certificate:
# Set to `true` to enable Agora cloud recording.
# Agoraのクラウドレコーディングを有効にする場合は`true`にしてください。
enable_cloud_recording: false
""";
}
8 changes: 4 additions & 4 deletions packages/katana_cli/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ packages:
dependency: "direct main"
description:
name: katana
sha256: d2994914d6a1ec082f05cb753138e0a729370479dc7b47f51d4d6db4027e4087
sha256: "427d91c692617ecb1c645fdf11678e82d5e9273c4929934cdea0d6fda4c32e6b"
url: "https://pub.dev"
source: hosted
version: "1.0.12"
version: "1.0.13"
lints:
dependency: "direct main"
description:
Expand Down Expand Up @@ -197,10 +197,10 @@ packages:
dependency: transitive
description:
name: pointycastle
sha256: c3120a968135aead39699267f4c74bc9a08e4e909e86bc1b0af5bfd78691123c
sha256: "7c1e5f0d23c9016c5bbd8b1473d0d3fb3fc851b876046039509e18e0c7485f2c"
url: "https://pub.dev"
source: hosted
version: "3.7.2"
version: "3.7.3"
recase:
dependency: transitive
description:
Expand Down

0 comments on commit c33753e

Please sign in to comment.