From d5347704cf9a203c6b9acbf2efd9434811bc8354 Mon Sep 17 00:00:00 2001 From: Arne Molland Date: Tue, 6 Jun 2023 15:29:18 +0200 Subject: [PATCH] tool: rewrite pigeon gen as dart program --- pigeon.sh | 23 -------------------- tool/gen_pigeon.dart | 51 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 23 deletions(-) delete mode 100755 pigeon.sh create mode 100644 tool/gen_pigeon.dart diff --git a/pigeon.sh b/pigeon.sh deleted file mode 100755 index 972f11e..0000000 --- a/pigeon.sh +++ /dev/null @@ -1,23 +0,0 @@ -# UserDefaults for iOS -dart run pigeon \ - --input api/user_defaults.dart \ - --dart_out lib/api/user_defaults.dart \ - --swift_out ios/Classes/UserDefaultsAPI.swift - -# UserDefaults for macOS -dart run pigeon \ - --input api/user_defaults.dart \ - --dart_out lib/api/user_defaults.dart \ - --swift_out macos/Classes/UserDefaultsAPI.swift - -# WidgetKit for iOS -dart run pigeon \ - --input api/widget_kit.dart \ - --dart_out lib/api/widget_kit.dart \ - --swift_out ios/Classes/WidgetKitAPI.swift - -# WidgetKit for macOS -dart run pigeon \ - --input api/widget_kit.dart \ - --dart_out lib/api/widget_kit.dart \ - --swift_out macos/Classes/WidgetKitAPI.swift diff --git a/tool/gen_pigeon.dart b/tool/gen_pigeon.dart new file mode 100644 index 0000000..f0f7902 --- /dev/null +++ b/tool/gen_pigeon.dart @@ -0,0 +1,51 @@ +// ignore_for_file: avoid_print + +import 'dart:io'; + +Future runPigeon(String input, String dartOut, String swiftOut) async { + var result = await Process.run('dart', [ + 'run', + 'pigeon', + '--input', + input, + '--dart_out', + dartOut, + '--swift_out', + swiftOut + ]); + + if (result.exitCode != 0) { + print('Error running pigeon:\n${result.stderr}'); + exit(result.exitCode); + } +} + +void main() async { + // UserDefaults for iOS + await runPigeon( + 'api/user_defaults.dart', + 'lib/api/user_defaults.dart', + 'ios/Classes/UserDefaultsAPI.swift', + ); + + // UserDefaults for macOS + await runPigeon( + 'api/user_defaults.dart', + 'lib/api/user_defaults.dart', + 'macos/Classes/UserDefaultsAPI.swift', + ); + + // WidgetKit for iOS + await runPigeon( + 'api/widget_kit.dart', + 'lib/api/widget_kit.dart', + 'ios/Classes/WidgetKitAPI.swift', + ); + + // WidgetKit for macOS + await runPigeon( + 'api/widget_kit.dart', + 'lib/api/widget_kit.dart', + 'macos/Classes/WidgetKitAPI.swift', + ); +}