Index: lib/dartdoc/dartdoc.dart |
diff --git a/lib/dartdoc/dartdoc.dart b/lib/dartdoc/dartdoc.dart |
index d336b5dc9c63dfbccaa650027bdd37f46606031f..13aecfef53c0456f08a5b74ccb8ee56c3a58954e 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'); |
@@ -48,6 +49,39 @@ final MODE_STATIC = 0; |
*/ |
final MODE_LIVE_NAV = 1; |
+void printUsage() { |
kasperl
2012/05/31 13:30:23
I would consider moving printUsage down below main
|
+ print(''' |
+Usage dartdoc [options] <entrypoint> |
+[options] include |
+ --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/ |
+'''); |
+} |
+ |
/** |
* Run this from the `lib/dartdoc` directory. |
*/ |
@@ -59,6 +93,12 @@ void main() { |
int mode; |
String outputDir; |
bool generateAppCache; |
+ |
+ if (args.length == 0) { |
kasperl
2012/05/31 13:30:23
args.isEmpty()?
|
+ print('No arguments provided.'); |
+ printUsage(); |
+ return; |
+ } |
for (int i = 0; i < args.length - 1; i++) { |
final arg = args[i]; |
@@ -86,6 +126,7 @@ void main() { |
outputDir = arg.substring('--out='.length); |
} else { |
print('Unknown option: $arg'); |
+ printUsage(); |
return; |
} |
break; |
@@ -102,7 +143,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,7 +158,7 @@ void main() { |
// Compile the client-side code to JS. |
final clientScript = (dartdoc.mode == MODE_STATIC) ? 'static' : 'live-nav'; |
- final Future scriptCompiled = compileScript(compilerPath, libDir, |
+ final Future scriptCompiled = compileScript(libDir, |
'$scriptDir/client-$clientScript.dart', |
kasperl
2012/05/31 13:30:23
The indentation here seems off (not your fault). I
|
'${dartdoc.outputDir}/client-$clientScript.js'); |
@@ -126,11 +166,12 @@ void main() { |
Futures.wait([scriptCompiled, filesCopied]).then((_) { |
dartdoc.document(entrypoint); |
- }); |
- |
- print('Documented ${dartdoc._totalLibraries} libraries, ' + |
+ |
+ print('Documented ${dartdoc._totalLibraries} libraries, ' + |
ngeoffray
2012/05/31 13:22:56
You can remove the '+'s here, they're not needed,
kasperl
2012/05/31 13:30:23
We're deprecating using + for string concatenation
|
'${dartdoc._totalTypes} types, and ' + |
'${dartdoc._totalMembers} members.'); |
+ }); |
+ |
} |
/** |
@@ -152,7 +193,15 @@ void cleanOutputDirectory(String path) { |
outputDir.deleteRecursivelySync(); |
} |
- outputDir.createSync(); |
+ try { |
+ //TODO(johnniwinther) hack to avoid 'file already exists' exception thrown |
ngeoffray
2012/05/31 13:22:56
missing space before TODO
kasperl
2012/05/31 13:30:23
Add a space before TODO and terminate the comment
|
+ // due to invalid result from dir.existsSync() (probably due to race |
+ // conditions) |
+ outputDir.createSync(); |
+ } catch (DirectoryIOException e) { |
+ // ignore |
kasperl
2012/05/31 13:30:23
Start comments with uppercase and terminate with .
|
+ // print('$e: $path'); |
ngeoffray
2012/05/31 13:22:56
Leftover debugging?
kasperl
2012/05/31 13:30:23
We try to avoid code in comments.
|
+ } |
} |
/** |
@@ -185,36 +234,30 @@ 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 located. |
ngeoffray
2012/05/31 13:22:56
Remove located.
|
*/ |
-Future compileScript(String compilerPath, String libDir, |
- String dartPath, String jsPath) { |
+Future compileScript(String libDir, |
+ String dartPath, String jsPath) { |
kasperl
2012/05/31 13:30:23
Would all the parameters fit on one line now?
|
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', |
kasperl
2012/05/31 13:30:23
4 space indent.
|
+ '--compile-only', '--enable-type-checks', '--warnings-as-errors', |
+ dartPath]); |
+ } catch (Object error) { |
ngeoffray
2012/05/31 13:22:56
strange indentation
kasperl
2012/05/31 13:30:23
Indentation seems off.
|
+ final message = 'Error trying to execute the compiler. Error: $error'; |
print('$message.'); |
ngeoffray
2012/05/31 13:22:56
Note that you can just write:
print(message)
The
|
- print(result.stdout); |
- print(result.stderr); |
throw message; |
kasperl
2012/05/31 13:30:23
This should probably be completer.completeExceptio
|
} |
- completer.complete(true); |
- } |
- |
- onError(error) { |
- final message = 'Error trying to execute $compilerPath. Error: $error'; |
+ if (!result) { |
+ final message = 'Non-zero exit code from the compiler'; |
print('$message.'); |
throw message; |
kasperl
2012/05/31 13:30:23
This should probably be completer.completeExceptio
kasperl
2012/05/31 13:30:23
This should probably be completer.completeExceptio
|
} |
- |
- 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); |
+ completer.complete(result); |
return completer.future; |
} |
@@ -351,7 +394,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 |
ngeoffray
2012/05/31 13:22:56
Space before TODO
kasperl
2012/05/31 13:30:23
Space before TODO. Terminate comment with . Consid
|
+ // due to invalid result from dir.existsSync() (probably due to race |
+ // conditions) |
+ try { |
+ dir.createSync(); |
+ } catch (DirectoryIOException e) { |
+ // ignore |
kasperl
2012/05/31 13:30:23
// Ignore.
|
+ } |
} |
world.files.writeString(outPath, _file.toString()); |
@@ -1355,4 +1405,4 @@ class Dartdoc { |
toCache.onDone = (done) => endFile(); |
toCache.list(recursive: true); |
} |
-} |
+} |