Chromium Code Reviews| Index: lib/dartdoc/dartdoc.dart |
| diff --git a/lib/dartdoc/dartdoc.dart b/lib/dartdoc/dartdoc.dart |
| index d336b5dc9c63dfbccaa650027bdd37f46606031f..85006da82c133e35f96250f71c4cc74abbb6d208 100644 |
| --- a/lib/dartdoc/dartdoc.dart |
| +++ b/lib/dartdoc/dartdoc.dart |
| @@ -23,6 +23,7 @@ |
| #import('../../frog/file_system_vm.dart'); |
| #import('classify.dart'); |
| #import('markdown.dart', prefix: 'md'); |
| +#import('../../frog/minfrogc.dart', prefix: 'frog'); |
| #source('comment_map.dart'); |
| #source('utils.dart'); |
| @@ -59,6 +60,12 @@ void main() { |
| int mode; |
| String outputDir; |
| bool generateAppCache; |
| + |
| + if (args.isEmpty()) { |
| + print('No arguments provided.'); |
| + printUsage(); |
| + return; |
| + } |
| for (int i = 0; i < args.length - 1; i++) { |
| final arg = args[i]; |
| @@ -86,6 +93,7 @@ void main() { |
| outputDir = arg.substring('--out='.length); |
| } else { |
| print('Unknown option: $arg'); |
| + printUsage(); |
| return; |
| } |
| break; |
| @@ -102,7 +110,6 @@ void main() { |
| // that dartdoc still works when run from the built SDK directory. |
| final frogPath = joinPaths(scriptDir, '../../frog/'); |
| final libDir = joinPaths(frogPath, 'lib'); |
| - final compilerPath = joinPaths(frogPath, 'minfrog'); |
| parseOptions(frogPath, ['', '', '--libdir=$libDir'], files); |
| initializeWorld(files); |
| @@ -118,19 +125,53 @@ void main() { |
| // Compile the client-side code to JS. |
| final clientScript = (dartdoc.mode == MODE_STATIC) ? 'static' : 'live-nav'; |
| - final Future scriptCompiled = compileScript(compilerPath, libDir, |
| - '$scriptDir/client-$clientScript.dart', |
| - '${dartdoc.outputDir}/client-$clientScript.js'); |
| + final Future scriptCompiled = compileScript(libDir, |
|
Bob Nystrom
2012/05/31 17:53:42
Local variables don't need type annotations.
|
| + '$scriptDir/client-$clientScript.dart', |
| + '${dartdoc.outputDir}/client-$clientScript.js'); |
| final Future filesCopied = copyFiles('$scriptDir/static', dartdoc.outputDir); |
| Futures.wait([scriptCompiled, filesCopied]).then((_) { |
| dartdoc.document(entrypoint); |
| + |
| + print('Documented ${dartdoc._totalLibraries} libraries, ' |
| + '${dartdoc._totalTypes} types, and ' |
| + '${dartdoc._totalMembers} members.'); |
| }); |
| - print('Documented ${dartdoc._totalLibraries} libraries, ' + |
| - '${dartdoc._totalTypes} types, and ' + |
| - '${dartdoc._totalMembers} members.'); |
| +} |
| + |
| +void printUsage() { |
| + print(''' |
| +Usage dartdoc [options] <entrypoint> |
| +[options] include |
|
Bob Nystrom
2012/05/31 17:53:42
Nice!
|
| + --no-code Do not include source code in the documentation. |
| + |
| + --mode=static Generates completely static HTML containing |
| + everything you need to browse the docs. The only |
| + client side behavior is trivial stuff like syntax |
| + highlighting code. |
| + |
| + --mode=live-nav (default) Generated docs do not include baked HTML |
| + navigation. Instead, a single `nav.json` file is |
| + created and the appropriate navigation is generated |
| + client-side by parsing that and building HTML. |
| + This dramatically reduces the generated size of |
| + the HTML since a large fraction of each static page |
| + is just redundant navigation links. |
| + In this mode, the browser will do a XHR for |
| + nav.json which means that to preview docs locally, |
| + you will need to enable requesting file:// links in |
| + your browser or run a little local server like |
| + `python -m SimpleHTTPServer`. |
| + |
| + --generate-app-cache Generates the App Cache manifest file, enabling |
| + offline doc viewing. |
| + --generate-app-cache=true --''-- |
| + |
| + --out=<dir> Generates files into directory <dir>. If omitted |
| + the files are generated into ./docs/ |
| +'''); |
| } |
| /** |
| @@ -152,7 +193,14 @@ void cleanOutputDirectory(String path) { |
| outputDir.deleteRecursivelySync(); |
| } |
| - outputDir.createSync(); |
| + try { |
| + // TODO(johnniwinther): hack to avoid 'file already exists' exception thrown |
| + // due to invalid result from dir.existsSync() (probably due to race |
| + // conditions). |
| + outputDir.createSync(); |
| + } catch (DirectoryIOException e) { |
| + // Ignore. |
| + } |
| } |
| /** |
| @@ -185,37 +233,31 @@ Future copyFiles(String from, String to) { |
| /** |
| * Compiles the given Dart script to a JavaScript file at [jsPath] using the |
| - * Dart-to-JS compiler located at [compilerPath]. |
| + * Frog compiler. |
| */ |
| -Future compileScript(String compilerPath, String libDir, |
| - String dartPath, String jsPath) { |
| +Future compileScript(String libDir, String dartPath, String jsPath) { |
|
Bob Nystrom
2012/05/31 17:53:42
Since this is no longer asynchronous, can you get
|
| final completer = new Completer(); |
| - onExit(ProcessResult result) { |
| - if (result.exitCode != 0) { |
| - final message = 'Non-zero exit code from $compilerPath'; |
| + print('Compiling $dartPath to $jsPath'); |
| + |
| + var result = true; |
| + try { |
| + result = frog.internalMain([ |
| + '--libdir=$libDir', '--out=$jsPath', |
| + '--compile-only', '--enable-type-checks', '--warnings-as-errors', |
| + dartPath]); |
| + if (!result) { |
| + final message = 'Non-zero exit code from the compiler'; |
| print('$message.'); |
| - print(result.stdout); |
| - print(result.stderr); |
| - throw message; |
| + completer.completeException(message); |
| + } else { |
| + completer.complete(result); |
| } |
| - completer.complete(true); |
| - } |
| - |
| - onError(error) { |
| - final message = 'Error trying to execute $compilerPath. Error: $error'; |
| + } catch (Object error) { |
| + final message = 'Error trying to execute the compiler. Error: $error'; |
| print('$message.'); |
| - throw message; |
| + completer.completeException(message); |
| } |
| - print('Compiling $dartPath to $jsPath'); |
| - var processFuture = Process.run(compilerPath, [ |
| - '--libdir=$libDir', '--out=$jsPath', |
| - '--compile-only', '--enable-type-checks', '--warnings-as-errors', |
| - dartPath]); |
| - |
| - processFuture.handleException(onError); |
| - processFuture.then(onExit); |
| - |
| return completer.future; |
| } |
| @@ -351,7 +393,14 @@ class Dartdoc { |
| final outPath = '$outputDir/$_filePath'; |
| final dir = new Directory(dirname(outPath)); |
| if (!dir.existsSync()) { |
| - dir.createSync(); |
| + //TODO(johnniwinther) hack to avoid 'file already exists' exception thrown |
| + // due to invalid result from dir.existsSync() (probably due to race |
| + // conditions) |
|
Bob Nystrom
2012/05/31 17:53:42
This worries me. I've never seen race conditions w
|
| + try { |
| + dir.createSync(); |
| + } catch (DirectoryIOException e) { |
| + // ignore |
| + } |
| } |
| world.files.writeString(outPath, _file.toString()); |
| @@ -1355,4 +1404,4 @@ class Dartdoc { |
| toCache.onDone = (done) => endFile(); |
| toCache.list(recursive: true); |
| } |
| -} |
| +} |