@@ -15,7 +15,7 @@ import 'common/package_looping_command.dart';
15
15
import 'common/process_runner.dart' ;
16
16
import 'common/repository_package.dart' ;
17
17
18
- /// A command to update README code excerpts from code files.
18
+ /// A command to update .md code excerpts from code files.
19
19
class UpdateExcerptsCommand extends PackageLoopingCommand {
20
20
/// Creates a excerpt updater command instance.
21
21
UpdateExcerptsCommand (
@@ -51,7 +51,7 @@ class UpdateExcerptsCommand extends PackageLoopingCommand {
51
51
final String name = 'update-excerpts' ;
52
52
53
53
@override
54
- final String description = 'Updates code excerpts in README .md files, based '
54
+ final String description = 'Updates code excerpts in .md files, based '
55
55
'on code from code files, via code-excerpt' ;
56
56
57
57
@override
@@ -105,13 +105,16 @@ class UpdateExcerptsCommand extends PackageLoopingCommand {
105
105
}
106
106
107
107
if (getBoolArg (_failOnChangeFlag)) {
108
- final String ? stateError = await _validateRepositoryState ();
108
+ final String ? stateError = await _validateRepositoryState (package );
109
109
if (stateError != null ) {
110
- printError ('README.md is out of sync with its source excerpts.\n\n '
111
- 'If you edited code in README.md directly, you should instead edit '
112
- 'the example source files. If you edited source files, run the '
113
- 'repository tooling\' s "$name " command on this package, and update '
114
- 'your PR with the resulting changes.' );
110
+ printError ('One or more .md files are out of sync with their source '
111
+ 'excerpts.\n\n '
112
+ 'If you edited code in a .md file directly, you should instead '
113
+ 'edit the example source files. If you edited source files, run '
114
+ 'the repository tooling\' s "$name " command on this package, and '
115
+ 'update your PR with the resulting changes.\n\n '
116
+ 'For more information, see '
117
+ 'https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#readme-code' );
115
118
return PackageResult .fail (< String > [stateError]);
116
119
}
117
120
}
@@ -138,14 +141,24 @@ class UpdateExcerptsCommand extends PackageLoopingCommand {
138
141
return exitCode == 0 ;
139
142
}
140
143
141
- /// Runs the injection step to update [targetPackage] 's README with the latest
142
- /// excerpts from [example] , returning true on success.
144
+ /// Runs the injection step to update [targetPackage] 's top-level .md files
145
+ /// with the latest excerpts from [example] , returning true on success.
143
146
Future <bool > _injectSnippets (
144
147
RepositoryPackage example, {
145
148
required RepositoryPackage targetPackage,
146
149
}) async {
147
- final String relativeReadmePath =
148
- getRelativePosixPath (targetPackage.readmeFile, from: example.directory);
150
+ final List <String > relativeMdPaths = targetPackage.directory
151
+ .listSync ()
152
+ .whereType <File >()
153
+ .where ((File f) =>
154
+ f.basename.toLowerCase ().endsWith ('.md' ) &&
155
+ // Exclude CHANGELOG since it should never have excerpts.
156
+ f.basename != 'CHANGELOG.md' )
157
+ .map ((File f) => getRelativePosixPath (f, from: example.directory))
158
+ .toList ();
159
+ if (relativeMdPaths.isEmpty) {
160
+ return true ;
161
+ }
149
162
final int exitCode = await processRunner.runAndStream (
150
163
'dart' ,
151
164
< String > [
@@ -154,7 +167,7 @@ class UpdateExcerptsCommand extends PackageLoopingCommand {
154
167
'--write-in-place' ,
155
168
'--yaml' ,
156
169
'--no-escape-ng-interpolation' ,
157
- relativeReadmePath ,
170
+ ...relativeMdPaths ,
158
171
],
159
172
workingDir: example.directory);
160
173
return exitCode == 0 ;
@@ -212,11 +225,11 @@ class UpdateExcerptsCommand extends PackageLoopingCommand {
212
225
213
226
/// Checks the git state, returning an error string if any .md files have
214
227
/// changed.
215
- Future <String ?> _validateRepositoryState () async {
228
+ Future <String ?> _validateRepositoryState (RepositoryPackage package ) async {
216
229
final io.ProcessResult checkFiles = await processRunner.run (
217
230
'git' ,
218
231
< String > ['ls-files' , '--modified' ],
219
- workingDir: packagesDir ,
232
+ workingDir: package.directory ,
220
233
logOnError: true ,
221
234
);
222
235
if (checkFiles.exitCode != 0 ) {
0 commit comments