1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:path/path.dart' as path;
/// This script expects to run with the cwd as the root of the flutter repo. It
/// will generate documentation for the packages in `//packages/` and write the
/// documentation to `//dev/docs/doc/api/`.
Future<Null> main(List<String> args) async {
// If we're run from the `tools` dir, set the cwd to the repo root.
if (path.basename(Directory.current.path) == 'tools')
Directory.current = Directory.current.parent.parent;
// Create the pubspec.yaml file.
StringBuffer buf = new StringBuffer('''
name: Flutter
dependencies:
''');
for (String package in _findPackageNames()) {
buf.writeln(' $package:');
buf.writeln(' path: ../../packages/$package');
}
new File('dev/docs/pubspec.yaml').writeAsStringSync(buf.toString());
// Create the library file.
Directory libDir = new Directory('dev/docs/lib');
libDir.createSync();
StringBuffer contents = new StringBuffer('library temp_doc;\n\n');
for (String libraryRef in _libraryRefs()) {
contents.writeln('import \'package:$libraryRef\';');
}
new File('dev/docs/lib/temp_doc.dart').writeAsStringSync(contents.toString());
// Run pub.
Process process = await Process.start('pub', <String>['get'], workingDirectory: 'dev/docs');
_print(process.stdout);
_print(process.stderr);
int code = await process.exitCode;
if (code != 0)
exit(code);
// Generate the documentation; we require dartdoc >= 0.9.4.
List<String> args = <String>[
'global', 'run', 'dartdoc',
'--header', 'styles.html',
'--header', 'analytics.html',
'--dart-sdk', '../../bin/cache/dart-sdk',
'--exclude', 'temp_doc',
'--favicon=favicon.ico',
'--use-categories'
];
for (String libraryRef in _libraryRefs()) {
String name = path.basename(libraryRef);
args.add('--include-external');
args.add(name.substring(0, name.length - 5));
}
_findSkyServicesLibraryNames().forEach((String libName) {
args.add('--include-external');
args.add(libName);
});
process = await Process.start('pub', args, workingDirectory: 'dev/docs');
_print(process.stdout);
_print(process.stderr);
exit(await process.exitCode);
}
List<String> _findSkyServicesLibraryNames() {
Directory skyServicesLocation = new Directory('bin/cache/pkg/sky_services/lib');
if (!skyServicesLocation.existsSync()) {
throw 'Did not find sky_services package location in ${skyServicesLocation.path}.';
}
return skyServicesLocation.listSync(followLinks: false, recursive: true)
.where((FileSystemEntity entity) {
return entity is File && entity.path.endsWith('.mojom.dart');
}).map((FileSystemEntity entity) {
String basename = path.basename(entity.path);
basename = basename.substring(0, basename.length-('.dart'.length));
return basename.replaceAll('.', '_');
});
}
List<String> _findPackageNames() {
return _findPackages().map((Directory dir) => path.basename(dir.path)).toList();
}
List<Directory> _findPackages() {
return new Directory('packages')
.listSync()
.where((FileSystemEntity entity) => entity is Directory)
.where((Directory dir) {
File pubspec = new File('${dir.path}/pubspec.yaml');
bool nodoc = pubspec.readAsStringSync().contains('nodoc: true');
return !nodoc;
})
.toList();
}
Iterable<String> _libraryRefs() sync* {
for (Directory dir in _findPackages()) {
String dirName = path.basename(dir.path);
for (FileSystemEntity file in new Directory('${dir.path}/lib').listSync()) {
if (file is File && file.path.endsWith('.dart'))
yield '$dirName/${path.basename(file.path)}';
}
}
}
void _print(Stream<List<int>> stream) {
stream
.transform(UTF8.decoder)
.transform(const LineSplitter())
.listen(print);
}