Skip to content

Commit

Permalink
fix: Support for Region of Functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrunet committed Feb 8, 2023
1 parent dd1a0bc commit 68c0ee2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/katana_cli/lib/action/firebase/init.dart
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ import * as m from "@mathrunet/masamune";
// Functionsに追加する機能を[m.Functions.xxxx]を定義してください。
m.deploy(
exports,
["us-central1", "asia-northeast1"],
[],
);
""";
Expand Down
18 changes: 17 additions & 1 deletion packages/katana_cli/lib/src/functions.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// Dart imports:
import 'dart:io';

import 'package:katana_cli/katana_cli.dart';

/// Class for specifying Functions of Firebase Functions.
///
/// Firebase FunctionsのFunctionを指定するためのクラス。
class Fuctions {
Fuctions();

static final _regExp = RegExp(
r"m.deploy\([\s\S]*?exports,[\s\S]*?\[(?<functions>[^\]]*?)\],?[\s\S]*\);",
r"m.deploy\([\s\S]*?exports,[\s\S]*?\[(?<regions>[^\]]*?)\],[\s\S]*?\[(?<functions>[^\]]*?)\],?[\s\S]*\);",
);

/// Original text data.
Expand All @@ -23,6 +25,12 @@ class Fuctions {
List<String> get functions => _functions;
late List<String> _functions;

/// List of Regions.
///
/// Regionの一覧。
List<String> get regions => _regions;
late List<String> _regions;

/// Data loading.
///
/// データの読み込み。
Expand All @@ -33,6 +41,13 @@ class Fuctions {
if (region == null) {
return;
}
_regions = region
.namedGroup("regions")
?.split(",")
.map((e) => e.trim().trimString('"').trimString("'"))
.where((e) => e.isNotEmpty)
.toList() ??
[];
_functions = region
.namedGroup("functions")
?.split(",")
Expand All @@ -52,6 +67,7 @@ class Fuctions {
_rawData = _rawData.replaceAll(_regExp, """
m.deploy(
exports,
[${regions.map((e) => '"$e"').join(",")}],
[
${functions.map((e) => " m.Functions.$e").join(",")}
],
Expand Down

0 comments on commit 68c0ee2

Please sign in to comment.