Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: lib/dartdoc/dartdoc.dart

Issue 9722012: Get rid of bash for dartdoc and do the whole thing in dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Respond to review. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * To use it, from this directory, run: 6 * To generate docs for a library, run this script with the path to an
7 * entrypoint .dart file, like:
7 * 8 *
8 * $ ./dartdoc <path to .dart file> 9 * $ dart dartdoc.dart foo.dart
9 * 10 *
10 * This will create a "docs" directory with the docs for your libraries. To 11 * This will create a "docs" directory with the docs for your libraries. To
11 * create these beautiful docs, dartdoc parses your library and every library 12 * create these beautiful docs, dartdoc parses your library and every library
12 * it imports (recursively). From each library, it parses all classes and 13 * it imports (recursively). From each library, it parses all classes and
13 * members, finds the associated doc comments and builds crosslinked docs from 14 * members, finds the associated doc comments and builds crosslinked docs from
14 * them. 15 * them.
15 */ 16 */
16 #library('dartdoc'); 17 #library('dartdoc');
17 18
18 #import('dart:io'); 19 #import('dart:io');
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 return; 83 return;
83 } 84 }
84 break; 85 break;
85 } 86 }
86 } 87 }
87 88
88 // The entrypoint of the library to generate docs for. 89 // The entrypoint of the library to generate docs for.
89 final entrypoint = args[args.length - 1]; 90 final entrypoint = args[args.length - 1];
90 91
91 final files = new VMFileSystem(); 92 final files = new VMFileSystem();
93
94 final frogPath = joinPaths(scriptDir, '../../frog/');
95
92 // TODO(rnystrom): Note that the following line gets munged by create-sdk to 96 // TODO(rnystrom): Note that the following line gets munged by create-sdk to
93 // work with the SDK's different file layout. If you change it here, make 97 // work with the SDK's different file layout. If you change it here, make
94 // sure SDK builds still work. 98 // sure SDK builds still work.
95 parseOptions('../../frog', ['', '', '--libdir=../../frog/lib'], files); 99 parseOptions(frogPath, ['', '', '--libdir=$frogPath/lib'], files);
96 initializeWorld(files); 100 initializeWorld(files);
97 101
98 var dartdoc; 102 final dartdoc = new Dartdoc();
99 final elapsed = time(() {
100 dartdoc = new Dartdoc();
101 103
102 if (includeSource != null) dartdoc.includeSource = includeSource; 104 if (includeSource != null) dartdoc.includeSource = includeSource;
103 if (mode != null) dartdoc.mode = mode; 105 if (mode != null) dartdoc.mode = mode;
104 if (outputDir != null) dartdoc.outputDir = outputDir; 106 if (outputDir != null) dartdoc.outputDir = outputDir;
105 107
106 cleanOutputDirectory(outputDir); 108 cleanOutputDirectory(dartdoc.outputDir);
107 109
108 // TODO(rnystrom): Use platform-specific path separator. 110 // Compile the client-side code to JS.
109 copyFiles('$scriptDir/static', outputDir); 111 final clientScript = (dartdoc.mode == MODE_STATIC) ? 'static' : 'live-nav';
112 compileScript(frogPath, '$scriptDir/client-$clientScript.dart',
113 '${dartdoc.outputDir}/client-$clientScript.js');
110 114
111 dartdoc.document(entrypoint); 115 copyFiles('$scriptDir/static', dartdoc.outputDir);
112 }); 116
117 dartdoc.document(entrypoint);
113 118
114 print('Documented ${dartdoc._totalLibraries} libraries, ' + 119 print('Documented ${dartdoc._totalLibraries} libraries, ' +
115 '${dartdoc._totalTypes} types, and ' + 120 '${dartdoc._totalTypes} types, and ' +
116 '${dartdoc._totalMembers} members in ${elapsed}msec.'); 121 '${dartdoc._totalMembers} members.');
117 } 122 }
118 123
119 /** 124 /**
120 * Gets the full path to the directory containing the entrypoint of the current 125 * Gets the full path to the directory containing the entrypoint of the current
121 * script. In other words, if you invoked dartdoc, directly, it will be the 126 * script. In other words, if you invoked dartdoc, directly, it will be the
122 * path to the directory containing `dartdoc.dart`. If you're running a script 127 * path to the directory containing `dartdoc.dart`. If you're running a script
123 * that imports dartdoc, it will be the path to that script. 128 * that imports dartdoc, it will be the path to that script.
124 */ 129 */
125 String get scriptDir() { 130 String get scriptDir() {
126 return dirname(new File(new Options().script).fullPathSync()); 131 return dirname(new File(new Options().script).fullPathSync());
(...skipping 27 matching lines...) Expand all
154 new File(path).readAsBytes((bytes) { 159 new File(path).readAsBytes((bytes) {
155 final outFile = new File('$to/$name'); 160 final outFile = new File('$to/$name');
156 final stream = outFile.openOutputStream(FileMode.WRITE); 161 final stream = outFile.openOutputStream(FileMode.WRITE);
157 stream.write(bytes, copyBuffer: false); 162 stream.write(bytes, copyBuffer: false);
158 stream.close(); 163 stream.close();
159 }); 164 });
160 }; 165 };
161 fromDir.list(recursive: false); 166 fromDir.list(recursive: false);
162 } 167 }
163 168
169 /**
170 * Compiles the given Dart script to a JavaScript file at [jsPath] using frog.
171 */
172 void compileScript(String frogPath, String dartPath, String jsPath) {
173 final process = new Process.start('$frogPath/minfrog', [
174 '--libdir=$frogPath/lib', '--out=$jsPath',
175 '--compile-only', '--enable-type-checks', '--warnings-as-errors',
176 dartPath]);
177
178 process.stdout.pipe(stdout, close: false);
179
180 process.onError = (error) {
181 print('Failed to compile $dartPath. Error:');
182 print(error);
ahe 2012/03/17 20:19:31 exit(1);
Bob Nystrom 2012/03/19 21:09:34 Leaving this alone for now. I'm not sure if I do w
183 };
184 }
185
164 class Dartdoc { 186 class Dartdoc {
165 /** Set to `false` to not include the source code in the generated docs. */ 187 /** Set to `false` to not include the source code in the generated docs. */
166 bool includeSource = true; 188 bool includeSource = true;
167 189
168 /** 190 /**
169 * Dartdoc can generate docs in a few different ways based on how dynamic you 191 * Dartdoc can generate docs in a few different ways based on how dynamic you
170 * want the client-side behavior to be. The value for this should be one of 192 * want the client-side behavior to be. The value for this should be one of
171 * the `MODE_` constants. 193 * the `MODE_` constants.
172 */ 194 */
173 int mode = MODE_LIVE_NAV; 195 int mode = MODE_LIVE_NAV;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 // Patch in support for [:...:]-style code to the markdown parser. 255 // Patch in support for [:...:]-style code to the markdown parser.
234 // TODO(rnystrom): Markdown already has syntax for this. Phase this out? 256 // TODO(rnystrom): Markdown already has syntax for this. Phase this out?
235 md.InlineParser.syntaxes.insertRange(0, 1, 257 md.InlineParser.syntaxes.insertRange(0, 1,
236 new md.CodeSyntax(@'\[\:((?:.|\n)*?)\:\]')); 258 new md.CodeSyntax(@'\[\:((?:.|\n)*?)\:\]'));
237 259
238 md.setImplicitLinkResolver((name) => resolveNameReference(name, 260 md.setImplicitLinkResolver((name) => resolveNameReference(name,
239 library: _currentLibrary, type: _currentType, 261 library: _currentLibrary, type: _currentType,
240 member: _currentMember)); 262 member: _currentMember));
241 } 263 }
242 264
243 void document(String entrypoint) { 265 void document([String entrypoint]) {
244 var oldDietParse = options.dietParse; 266 var oldDietParse = options.dietParse;
245 try { 267 try {
246 options.dietParse = true; 268 options.dietParse = true;
247 269
248 // Handle the built-in entrypoints. 270 // If we have an entrypoint, process it. Otherwise, just use whatever
249 switch (entrypoint) { 271 // libraries have been previously loaded by the calling code.
250 case 'corelib': 272 if (entrypoint != null) {
251 world.getOrAddLibrary('dart:core'); 273 world.processDartScript(entrypoint);
252 world.getOrAddLibrary('dart:coreimpl');
253 world.getOrAddLibrary('dart:json');
254 world.getOrAddLibrary('dart:isolate');
255 world.process();
256 break;
257
258 case 'dom':
259 world.getOrAddLibrary('dart:core');
260 world.getOrAddLibrary('dart:coreimpl');
261 world.getOrAddLibrary('dart:json');
262 world.getOrAddLibrary('dart:dom');
263 world.getOrAddLibrary('dart:isolate');
264 world.process();
265 break;
266
267 case 'html':
268 world.getOrAddLibrary('dart:core');
269 world.getOrAddLibrary('dart:coreimpl');
270 world.getOrAddLibrary('dart:json');
271 world.getOrAddLibrary('dart:dom');
272 world.getOrAddLibrary('dart:html');
273 world.getOrAddLibrary('dart:isolate');
274 world.process();
275 break;
276
277 default:
278 // Normal entrypoint script.
279 world.processDartScript(entrypoint);
280 } 274 }
281 275
282 world.resolveAll(); 276 world.resolveAll();
283 277
284 // Sort the libraries by name (not key). 278 // Sort the libraries by name (not key).
285 _sortedLibraries = world.libraries.getValues(); 279 _sortedLibraries = world.libraries.getValues();
286 _sortedLibraries.sort((a, b) { 280 _sortedLibraries.sort((a, b) {
287 return a.name.toUpperCase().compareTo(b.name.toUpperCase()); 281 return a.name.toUpperCase().compareTo(b.name.toUpperCase());
288 }); 282 });
289 283
(...skipping 984 matching lines...) Expand 10 before | Expand all | Expand 10 after
1274 1268
1275 return new md.Element.text('code', name); 1269 return new md.Element.text('code', name);
1276 } 1270 }
1277 1271
1278 // TODO(rnystrom): Move into SourceSpan? 1272 // TODO(rnystrom): Move into SourceSpan?
1279 int getSpanColumn(SourceSpan span) { 1273 int getSpanColumn(SourceSpan span) {
1280 final line = span.file.getLine(span.start); 1274 final line = span.file.getLine(span.start);
1281 return span.file.getColumn(line, span.start); 1275 return span.file.getColumn(line, span.start);
1282 } 1276 }
1283 } 1277 }
OLDNEW
« no previous file with comments | « lib/dartdoc/dartdoc ('k') | lib/dartdoc/utils.dart » ('j') | utils/apidoc/apidoc.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698