4
4
5
5
import 'dart:io' ;
6
6
7
- void main (List <String > args) async {
8
- final testDataDirectory = Directory .fromUri (Platform .script.resolve ('.' ));
9
- updateManifest (testDataDirectory, allowPartialProjects: false );
7
+ import 'package:args/args.dart' ;
8
+ import 'package:native_test_helpers/native_test_helpers.dart' ;
9
+
10
+ void main (List <String > args) {
11
+ final stopwatch = Stopwatch ()..start ();
12
+ final parser = ArgParser ()
13
+ ..addFlag (
14
+ 'set-exit-if-changed' ,
15
+ negatable: false ,
16
+ help: 'Return a non-zero exit code if any files were changed.' ,
17
+ );
18
+ final argResults = parser.parse (args);
19
+ final setExitIfChanged = argResults['set-exit-if-changed' ] as bool ;
20
+
21
+ final counts = Counts ();
22
+
23
+ updateManifests (counts);
24
+
25
+ stopwatch.stop ();
26
+ final duration = stopwatch.elapsedMilliseconds / 1000.0 ;
27
+ print (
28
+ 'Generated ${counts .generated } files (${counts .changed } changed) in '
29
+ '${duration .toStringAsFixed (2 )} seconds.' ,
30
+ );
31
+ if (setExitIfChanged && counts.changed > 0 ) {
32
+ exit (1 );
33
+ }
34
+ }
35
+
36
+ class Counts {
37
+ int generated = 0 ;
38
+ int changed = 0 ;
39
+ }
40
+
41
+ void updateManifests (Counts counts) async {
42
+ final packageUri = findPackageRoot ('hooks_runner' );
43
+ final testDataUri = packageUri.resolve ('test_data/' );
44
+ final testDataDirectory = Directory .fromUri (testDataUri);
45
+ updateManifest (testDataDirectory, counts, allowPartialProjects: false );
10
46
final all = testDataDirectory.listSync (recursive: true );
11
47
all.whereType <Directory >().forEach (
12
- (e) => updateManifest (e, allowPartialProjects: true ),
48
+ (e) => updateManifest (e, counts, allowPartialProjects: true ),
13
49
);
14
50
}
15
51
@@ -34,13 +70,17 @@ const partialProjects = [
34
70
'simple_link_change_asset' ,
35
71
];
36
72
37
- void updateManifest (Directory directory, {required bool allowPartialProjects}) {
73
+ void updateManifest (
74
+ Directory directory,
75
+ Counts counts, {
76
+ required bool allowPartialProjects,
77
+ }) {
38
78
final manifestFile = File .fromUri (directory.uri.resolve ('manifest.yaml' ));
39
79
if (! manifestFile.existsSync ()) {
40
80
return ;
41
81
}
42
82
final all = directory.listSync (recursive: true );
43
- final dirPath = directory.uri.toFilePath ();
83
+ final dirPath = directory.uri.toFilePath (windows : false );
44
84
final files =
45
85
all
46
86
.whereType <File >()
@@ -52,15 +92,32 @@ void updateManifest(Directory directory, {required bool allowPartialProjects}) {
52
92
'$partialProject /pubspec.yaml' ,
53
93
],
54
94
]) {
55
- if (f.path.contains (denyString)) return false ;
95
+ if (f.uri.toFilePath (windows: false ).contains (denyString)) {
96
+ return false ;
97
+ }
56
98
}
57
99
58
100
return true ;
59
101
})
60
- .map ((e) => e.path.replaceFirst (dirPath, '' ))
102
+ .map (
103
+ (e) => e.uri.toFilePath (windows: false ).replaceFirst (dirPath, '' ),
104
+ )
61
105
.toList ()
62
106
..sort ();
63
- manifestFile.writeAsStringSync (header + files.map ((e) => '- $e \n ' ).join ());
107
+
108
+ var oldContent = '' ;
109
+ if (manifestFile.existsSync ()) {
110
+ oldContent = manifestFile.readAsStringSync ();
111
+ }
112
+ final newContent = header + files.map ((e) => '- $e \n ' ).join ();
113
+ final newContentNormalized = newContent.replaceAll ('\r\n ' , '\n ' );
114
+ final oldContentNormalized = oldContent.replaceAll ('\r\n ' , '\n ' );
115
+ if (newContentNormalized != oldContentNormalized) {
116
+ manifestFile.writeAsStringSync (newContent);
117
+ print ('Generated ${manifestFile .uri } (content changed)' );
118
+ counts.changed++ ;
119
+ }
120
+ counts.generated++ ;
64
121
}
65
122
66
123
const header = '''
0 commit comments