@@ -8,9 +8,16 @@ import 'dart:io';
8
8
9
9
import 'package:path/path.dart' as path;
10
10
11
+ const String kDocRoot = 'dev/docs/doc' ;
12
+
11
13
/// This script expects to run with the cwd as the root of the flutter repo. It
12
14
/// will generate documentation for the packages in `//packages/` and write the
13
15
/// documentation to `//dev/docs/doc/api/` .
16
+ ///
17
+ /// This script also updates the index.html file so that it can be placed
18
+ /// at the root of docs.flutter.io. We are keeping the files inside of
19
+ /// docs.flutter.io/flutter for now, so we need to manipulate paths
20
+ /// a bit. See https://github.com/flutter/flutter/issues/3900 for more info.
14
21
Future <Null > main (List <String > args) async {
15
22
// If we're run from the `tools` dir, set the cwd to the repo root.
16
23
if (path.basename (Directory .current.path) == 'tools' )
@@ -21,7 +28,7 @@ Future<Null> main(List<String> args) async {
21
28
name: Flutter
22
29
dependencies:
23
30
''' );
24
- for (String package in _findPackageNames ()) {
31
+ for (String package in findPackageNames ()) {
25
32
buf.writeln (' $package :' );
26
33
buf.writeln (' path: ../../packages/$package ' );
27
34
}
@@ -32,15 +39,15 @@ dependencies:
32
39
libDir.createSync ();
33
40
34
41
StringBuffer contents = new StringBuffer ('library temp_doc;\n\n ' );
35
- for (String libraryRef in _libraryRefs ()) {
42
+ for (String libraryRef in libraryRefs ()) {
36
43
contents.writeln ('import \' package:$libraryRef \' ;' );
37
44
}
38
45
new File ('dev/docs/lib/temp_doc.dart' ).writeAsStringSync (contents.toString ());
39
46
40
47
// Run pub.
41
48
Process process = await Process .start ('pub' , < String > ['get' ], workingDirectory: 'dev/docs' );
42
- _print (process.stdout);
43
- _print (process.stderr);
49
+ printStream (process.stdout);
50
+ printStream (process.stderr);
44
51
int code = await process.exitCode;
45
52
if (code != 0 )
46
53
exit (code);
@@ -56,24 +63,61 @@ dependencies:
56
63
'--use-categories'
57
64
];
58
65
59
- for (String libraryRef in _libraryRefs ()) {
66
+ for (String libraryRef in libraryRefs ()) {
60
67
String name = path.basename (libraryRef);
61
68
args.add ('--include-external' );
62
69
args.add (name.substring (0 , name.length - 5 ));
63
70
}
64
71
65
- _findSkyServicesLibraryNames ().forEach ((String libName) {
72
+ findSkyServicesLibraryNames ().forEach ((String libName) {
66
73
args.add ('--include-external' );
67
74
args.add (libName);
68
75
});
69
76
70
77
process = await Process .start ('pub' , args, workingDirectory: 'dev/docs' );
71
- _print (process.stdout);
72
- _print (process.stderr);
73
- exit (await process.exitCode);
78
+ printStream (process.stdout);
79
+ printStream (process.stderr);
80
+ int exitCode = await process.exitCode;
81
+
82
+ if (exitCode != 0 )
83
+ exit (exitCode);
84
+
85
+ createIndexAndCleanup ();
86
+ }
87
+
88
+ /// Creates a custom index.html because we try to maintain old
89
+ /// paths. Cleanup unused index.html files no longer needed.
90
+ void createIndexAndCleanup () {
91
+ print ('\n Creating a custom index.html in $kDocRoot /index.html' );
92
+ renameApiDir ();
93
+ copyIndexToRootOfDocs ();
94
+ addHtmlBaseToIndex ();
95
+ putRedirectInOldIndexLocation ();
96
+ print ('\n Docs ready to go!' );
97
+ }
98
+
99
+ void renameApiDir () {
100
+ new Directory ('$kDocRoot /api' ).renameSync ('$kDocRoot /flutter' );
101
+ }
102
+
103
+ File copyIndexToRootOfDocs () {
104
+ return new File ('$kDocRoot /flutter/index.html' ).copySync ('$kDocRoot /index.html' );
105
+ }
106
+
107
+ void addHtmlBaseToIndex () {
108
+ File indexFile = new File ('$kDocRoot /index.html' );
109
+ String indexContents = indexFile.readAsStringSync ();
110
+ indexContents = indexContents.replaceFirst ('</title>\n ' ,
111
+ '</title>\n <base href="./flutter/">\n ' );
112
+ indexFile.writeAsStringSync (indexContents);
113
+ }
114
+
115
+ void putRedirectInOldIndexLocation () {
116
+ String metaTag = '<meta http-equiv="refresh" content="0;URL=../index.html">' ;
117
+ new File ('$kDocRoot /flutter/index.html' ).writeAsStringSync (metaTag);
74
118
}
75
119
76
- List <String > _findSkyServicesLibraryNames () {
120
+ List <String > findSkyServicesLibraryNames () {
77
121
Directory skyServicesLocation = new Directory ('bin/cache/pkg/sky_services/lib' );
78
122
if (! skyServicesLocation.existsSync ()) {
79
123
throw 'Did not find sky_services package location in ${skyServicesLocation .path }.' ;
@@ -88,11 +132,11 @@ List<String> _findSkyServicesLibraryNames() {
88
132
});
89
133
}
90
134
91
- List <String > _findPackageNames () {
92
- return _findPackages ().map ((Directory dir) => path.basename (dir.path)).toList ();
135
+ List <String > findPackageNames () {
136
+ return findPackages ().map ((Directory dir) => path.basename (dir.path)).toList ();
93
137
}
94
138
95
- List <Directory > _findPackages () {
139
+ List <Directory > findPackages () {
96
140
return new Directory ('packages' )
97
141
.listSync ()
98
142
.where ((FileSystemEntity entity) => entity is Directory )
@@ -104,8 +148,8 @@ List<Directory> _findPackages() {
104
148
.toList ();
105
149
}
106
150
107
- Iterable <String > _libraryRefs () sync * {
108
- for (Directory dir in _findPackages ()) {
151
+ Iterable <String > libraryRefs () sync * {
152
+ for (Directory dir in findPackages ()) {
109
153
String dirName = path.basename (dir.path);
110
154
111
155
for (FileSystemEntity file in new Directory ('${dir .path }/lib' ).listSync ()) {
@@ -115,7 +159,7 @@ Iterable<String> _libraryRefs() sync* {
115
159
}
116
160
}
117
161
118
- void _print (Stream <List <int >> stream) {
162
+ void printStream (Stream <List <int >> stream) {
119
163
stream
120
164
.transform (UTF8 .decoder)
121
165
.transform (const LineSplitter ())
0 commit comments