Write snippets index file when generating docs (#25515)
This commit is contained in:
@@ -353,6 +353,7 @@ void createIndexAndCleanup() {
|
||||
addHtmlBaseToIndex();
|
||||
changePackageToSdkInTitlebar();
|
||||
putRedirectInOldIndexLocation();
|
||||
writeSnippetsIndexFile();
|
||||
print('\nDocs ready to go!');
|
||||
}
|
||||
|
||||
@@ -407,6 +408,23 @@ void putRedirectInOldIndexLocation() {
|
||||
File('$kPublishRoot/flutter/index.html').writeAsStringSync(metaTag);
|
||||
}
|
||||
|
||||
|
||||
void writeSnippetsIndexFile() {
|
||||
final Directory snippetsDir = Directory(path.join(kPublishRoot, 'snippets'));
|
||||
if (snippetsDir.existsSync()) {
|
||||
const JsonEncoder jsonEncoder = JsonEncoder.withIndent(' ');
|
||||
final Iterable<File> files = snippetsDir
|
||||
.listSync()
|
||||
.whereType<File>()
|
||||
.where((File file) => path.extension(file.path) == '.json');
|
||||
// Combine all the metadata into a single JSON array.
|
||||
final Iterable<String> fileContents = files.map((File file) => file.readAsStringSync());
|
||||
final List<dynamic> metadataObjects = fileContents.map<dynamic>(json.decode).toList();
|
||||
final String jsonArray = jsonEncoder.convert(metadataObjects);
|
||||
File('$kPublishRoot/snippets/index.json').writeAsStringSync(jsonArray);
|
||||
}
|
||||
}
|
||||
|
||||
List<String> findPackageNames() {
|
||||
return findPackages().map<String>((FileSystemEntity file) => path.basename(file.path)).toList();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user