|
| 1 | +import 'dart:io'; |
| 2 | + |
| 3 | +import 'package:args/args.dart'; |
| 4 | + |
| 5 | +void main(List<String> arguments) async { |
| 6 | + final parser = ArgParser() |
| 7 | + ..addOption( |
| 8 | + 'executable', |
| 9 | + allowed: ['dart', 'flutter'], |
| 10 | + defaultsTo: 'dart', |
| 11 | + help: 'Specify the executable to use (dart or flutter)', |
| 12 | + ); |
| 13 | + |
| 14 | + ArgResults args; |
| 15 | + try { |
| 16 | + args = parser.parse(arguments); |
| 17 | + } on FormatException catch (e) { |
| 18 | + print('Error: ${e.message}'); |
| 19 | + print('Usage: dart script.dart [--executable <dart|flutter>]'); |
| 20 | + exit(1); |
| 21 | + } |
| 22 | + |
| 23 | + final executable = args['executable'] as String; |
| 24 | + |
| 25 | + final result = await Process.run(executable, ['pub', 'publish', '--dry-run']); |
| 26 | + final publishOutput = result.stderr as String; |
| 27 | + |
| 28 | + if (publishOutput.contains('Found no `pubspec.yaml` file')) { |
| 29 | + print(publishOutput); |
| 30 | + exit(1); |
| 31 | + } |
| 32 | + |
| 33 | + const expectedErrors = [ |
| 34 | + 'lib/src/integrations/connectivity/web_connectivity_provider.dart: This package does not have web in the `dependencies` section of `pubspec.yaml`', |
| 35 | + 'lib/src/event_processor/enricher/web_enricher_event_processor.dart: This package does not have web in the `dependencies` section of `pubspec.yaml`', |
| 36 | + 'lib/src/origin_web.dart: This package does not have web in the `dependencies` section of `pubspec.yaml`', |
| 37 | + 'lib/src/platform/_web_platform.dart: This package does not have web in the `dependencies` section of `pubspec.yaml`' |
| 38 | + ]; |
| 39 | + |
| 40 | + // So far the expected errors all start with `* line` |
| 41 | + final errorLines = publishOutput |
| 42 | + .split('\n') |
| 43 | + .where((line) => line.startsWith('* line')) |
| 44 | + .toList(); |
| 45 | + |
| 46 | + final unexpectedErrors = errorLines.where((errorLine) { |
| 47 | + return !expectedErrors |
| 48 | + .any((expectedError) => errorLine.contains(expectedError)); |
| 49 | + }).toList(); |
| 50 | + |
| 51 | + if (unexpectedErrors.isEmpty) { |
| 52 | + print('Only expected errors found. Validation passed.'); |
| 53 | + exit(0); |
| 54 | + } else { |
| 55 | + print('Unexpected errors found:'); |
| 56 | + unexpectedErrors.forEach(print); |
| 57 | + exit(1); |
| 58 | + } |
| 59 | +} |
0 commit comments