diff --git a/pubspec.yaml b/pubspec.yaml index 78a07cf..61d801d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -44,6 +44,7 @@ dependencies: vibration: 1.8.1 dev_dependencies: + args: 2.5.0 bloc_test: 9.1.3 build_runner: 2.4.6 flutter_native_splash: 2.3.5 @@ -55,6 +56,7 @@ dev_dependencies: integration_test: sdk: flutter lint: 2.1.2 + logging: 1.2.0 meta: 1.9.1 mocktail: 0.3.0 test: 1.24.3 diff --git a/screenshots/main.dart b/screenshots/main.dart new file mode 100644 index 0000000..11beb4f --- /dev/null +++ b/screenshots/main.dart @@ -0,0 +1,58 @@ +import 'dart:io'; +import 'dart:typed_data'; + +import 'package:args/args.dart'; +import 'package:image/image.dart'; +import 'package:logging/logging.dart'; + +import 'convert_to_store_screenshot.dart'; +import 'models/screenshot_args.dart'; +import 'models/screenshot_layout.dart'; + +Future main(List args) async { + final parser = ArgParser() + ..addFlag('verbose', abbr: 'v', help: 'Verbose output.') + ..addOption('platform', abbr: 'p', help: 'Device platform.', mandatory: true) + ..addOption('device', abbr: 'd', help: 'device_snake_name', mandatory: true); + final ArgResults argResults = parser.parse(args); + + if (argResults['verbose'] as bool) { + Logger.root.level = Level.ALL; + } else { + Logger.root.level = Level.INFO; + } + + final device = argResults["device"] as String; + final platform = argResults["platform"] as String; + Directory('screenshots/generated/raw/$platform/$device').listSync().forEach((filePath) async { + final screenshotName = filePath.path.split('/').last.replaceAll('.png', ''); + final screenshotBytes = File(filePath.path).readAsBytesSync(); + final screenshot = decodePng(Uint8List.fromList(screenshotBytes))!; + final topLeftPixel = screenshot.getPixel(0, 0); + + final screenshotArgs = ScreenshotArgs( + name: screenshotName, + deviceName: device, + platformFolder: platform, + backgroundColor: ( + r: topLeftPixel.r.toInt(), + g: topLeftPixel.g.toInt(), + b: topLeftPixel.b.toInt(), + a: topLeftPixel.a.toInt(), + ), + isDark: filePath.path.contains('dark-'), + ); + + final file = await File(filePath.path.replaceAll('/raw', '')).create(recursive: true); + file.writeAsBytesSync( + encodePng( + screenshot.convertToStoreScreenshot( + args: screenshotArgs, + layout: ScreenshotLayout.iphone65inch, + ), + ), + ); + }); + + return 0; +}