Skip to content

Commit

Permalink
fix: Added Geocoding section.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrunet committed Nov 29, 2023
1 parent 2b69a36 commit edd86cb
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 3 deletions.
103 changes: 103 additions & 0 deletions packages/katana_cli/lib/action/app/geocoding.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Dart imports:
import 'dart:io';

// Project imports:
import 'package:katana_cli/katana_cli.dart';

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

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

@override
bool checkEnabled(ExecContext context) {
final value = context.yaml.getAsMap("location").getAsMap("geocoding");
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 location = context.yaml.getAsMap("location");
final geocoding = location.getAsMap("geocoding");
final firebase = context.yaml.getAsMap("firebase");
final projectId = firebase.get("project_id", "");
final geocodingApiKey = geocoding.get("api_key", "");
if (geocodingApiKey.isEmpty) {
error(
"If [location]->[geocoding]->[enable] is enabled, please include [location]->[geocoding]->[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 command(
"Import packages.",
[
flutter,
"pub",
"add",
"masamune_geocoding",
"katana_functions_firebase",
],
);
label("Add firebase functions");
final functions = Fuctions();
await functions.load();
if (!functions.functions.any((e) => e.startsWith("geocoding"))) {
functions.functions.add("geocoding()");
}
await functions.save();
await command(
"Set firebase functions config.",
[
firebaseCommand,
"functions:config:set",
"map.geocoding.api_key=${geocoding.get("api_key", "")}",
],
workingDirectory: "firebase",
);
await command(
"Deploy firebase functions.",
[
firebaseCommand,
"deploy",
"--only",
"functions",
],
workingDirectory: "firebase",
);
}
}
2 changes: 1 addition & 1 deletion packages/katana_cli/lib/action/mail/send_grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class MailSendGridCliAction extends CliCommand with CliActionMixin {
final sendGridApiKey = sendgrid.get("api_key", "");
if (sendGridApiKey.isEmpty) {
error(
"If [stripe]->[email_provider] is `sendgrid`, please include [sendgrid]->[api_key].",
"If [sendgrid]->[enable] is enabled, please include [sendgrid]->[api_key].",
);
return;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/katana_cli/lib/command/apply.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:katana_cli/action/agora/agora.dart';
import 'package:katana_cli/action/app/calendar.dart';
import 'package:katana_cli/action/app/csr.dart';
import 'package:katana_cli/action/app/deeplink.dart';
import 'package:katana_cli/action/app/geocoding.dart';
import 'package:katana_cli/action/app/icon.dart';
import 'package:katana_cli/action/app/info.dart';
import 'package:katana_cli/action/app/introduction.dart';
Expand Down Expand Up @@ -66,6 +67,7 @@ const _actions = <CliActionMixin>[
StripeCliAction(),
MailGmailCliAction(),
MailSendGridCliAction(),
AppGeocodingCliAction(),
EcosystemCliAction(),
];

Expand Down
11 changes: 10 additions & 1 deletion packages/katana_cli/lib/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ store:
# If you wish to use GoogleMap, set [google_map]->[enable] to true. Also, obtain a GoogleMap API key from the following link in advance and enter it in [google_map]->[api_key].
# https://console.cloud.google.com/google/maps-apis/credentials
#
# If you want to use Geocoding to obtain location information from addresses, set [geocoding]->[enable] to true. Also, please obtain an API key for Geocoding from the link below and enter it in the [geocoding]->[api_key] field.
# https://console.cloud.google.com/google/maps-apis/credentials
#
# Specify the permission message to use the library in IOS in [permission].
# Please include `en`, `ja`, etc. and write the message in that language there.
#
Expand All @@ -411,6 +414,9 @@ store:
# GoogleMapを利用する場合は[google_map]->[enable]をtrueにしてください。また事前に下記のリンクからGoogleMapのAPIキーを取得しておき[google_map]->[api_key]に記載してください。
# https://console.cloud.google.com/google/maps-apis/credentials
#
# Geocodingで住所から位置情報を取得する場合は[geocoding]->[enable]をtrueにしてください。また事前に下記のリンクからGeocoding専用のAPIキーを取得しておき[geocoding]->[api_key]に記載してください。
# https://console.cloud.google.com/google/maps-apis/credentials
#
# [permission]にIOSでライブラリを利用するための権限許可メッセージを指定します。
# `en`や`ja`などを記載しそこにその言語でのメッセージを記述してください。
location:
Expand All @@ -421,7 +427,10 @@ location:
api_key:
android:
ios:
web:
web:
geocoding:
enable: false
api_key:
permission:
en: Location information is used to display the map.
Expand Down
2 changes: 1 addition & 1 deletion packages/katana_cli/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ packages:
path: "../katana"
relative: true
source: path
version: "2.6.3"
version: "2.7.1"
lints:
dependency: transitive
description:
Expand Down

0 comments on commit edd86cb

Please sign in to comment.