Chromium Code Reviews| Index: lib/dartdoc/dartdoc.dart |
| diff --git a/lib/dartdoc/dartdoc.dart b/lib/dartdoc/dartdoc.dart |
| index 22456bad8209c0fecffa53db3c7d36763535f996..b2b3d33df7a84ba0dec823d1bb02c7c22d85c4f4 100644 |
| --- a/lib/dartdoc/dartdoc.dart |
| +++ b/lib/dartdoc/dartdoc.dart |
| @@ -26,9 +26,6 @@ |
| #source('comment_map.dart'); |
| #source('utils.dart'); |
| -/** Path to generate HTML files into. */ |
| -final _outdir = 'docs'; |
| - |
| /** |
| * Generates completely static HTML containing everything you need to browse |
| * the docs. The only client side behavior is trivial stuff like syntax |
| @@ -56,15 +53,14 @@ final MODE_LIVE_NAV = 1; |
| void main() { |
| final args = new Options().arguments; |
| - // The entrypoint of the library to generate docs for. |
| - final entrypoint = args[args.length - 1]; |
| - |
| // Parse the dartdoc options. |
| - bool includeSource = true; |
| - var mode = MODE_LIVE_NAV; |
| + var includeSource; |
| + var mode; |
| + var outputDir; |
|
nweiz
2012/03/15 23:45:48
These should have types declared, since they're no
Bob Nystrom
2012/03/15 23:58:23
Done.
|
| - for (int i = 2; i < args.length - 1; i++) { |
| + for (int i = 0; i < args.length - 1; i++) { |
| final arg = args[i]; |
| + |
| switch (arg) { |
| case '--no-code': |
| includeSource = false; |
| @@ -79,10 +75,18 @@ void main() { |
| break; |
| default: |
| - print('Unknown option: $arg'); |
| + if (arg.startsWith('--out=')) { |
| + outputDir = arg.substring('--out='.length); |
|
nweiz
2012/03/15 23:45:48
Is there a bug filed against Options to support op
Bob Nystrom
2012/03/15 23:58:23
No, but I don't really think arg parsing should be
nweiz
2012/03/16 00:15:49
What's the Options class for if not arg parsing?
Bob Nystrom
2012/03/16 00:22:37
It's for being able to access them at all. I would
nweiz
2012/03/16 18:25:51
Maybe this is more of an API design issue, but the
|
| + } else { |
| + print('Unknown option: $arg'); |
| + return; |
| + } |
|
mattsh
2012/03/15 23:52:55
missing break
Bob Nystrom
2012/03/15 23:58:23
Done.
|
| } |
| } |
| + // The entrypoint of the library to generate docs for. |
| + final entrypoint = args[args.length - 1]; |
| + |
| final files = new VMFileSystem(); |
| // TODO(rnystrom): Note that the following line gets munged by create-sdk to |
| // work with the SDK's different file layout. If you change it here, make |
| @@ -93,8 +97,15 @@ void main() { |
| var dartdoc; |
| final elapsed = time(() { |
| dartdoc = new Dartdoc(); |
| - dartdoc.includeSource = includeSource; |
| - dartdoc.mode = mode; |
| + |
| + if (includeSource != null) dartdoc.includeSource = includeSource; |
| + if (mode != null) dartdoc.mode = mode; |
| + if (outputDir != null) dartdoc.outputDir = outputDir; |
| + |
| + cleanOutputDirectory(outputDir); |
| + |
| + // TODO(rnystrom): Use platform-specific path separator. |
|
nweiz
2012/03/15 23:45:48
Won't Windows understand "/", even if it doesn't p
Bob Nystrom
2012/03/15 23:58:23
Not sure. The Platform class in Dart does have a p
nweiz
2012/03/16 00:15:49
If we don't have to use the separator constant for
Bob Nystrom
2012/03/16 00:22:37
Works for me. I won't plan to change this until I
|
| + copyFiles('$scriptDir/static', outputDir); |
| dartdoc.document(entrypoint); |
| }); |
| @@ -104,6 +115,51 @@ void main() { |
| '${dartdoc._totalMembers} members in ${elapsed}msec.'); |
| } |
| +/** |
| + * Gets the full path to the directory containing the entrypoint of the current |
| + * script. In other words, if you invoked dartdoc, directly, it will be the |
| + * path to the directory containing `dartdoc.dart`. If you're running a script |
| + * that imports dartdoc, it will be the path to that script. |
| + */ |
| +String get scriptDir() { |
| + return dirname(new File(new Options().script).fullPathSync()); |
| +} |
| + |
| +/** |
| + * Deletes and recreates the output directory at [path] if it exists. |
| + */ |
| +void cleanOutputDirectory(String path) { |
| + final outputDir = new Directory(path); |
| + if (outputDir.existsSync()) { |
| + outputDir.deleteRecursivelySync(); |
| + outputDir.createSync(); |
| + } |
| +} |
| + |
| +/** |
| + * Copies all of the files in the directory [from] to [to]. Does *not* |
| + * recursively copy subdirectories. |
| + * |
| + * Note: runs asynchronously, so you won't see any files copied until after the |
| + * event loop has had a chance to pump (i.e. after `main()` has returned). |
| + */ |
| +void copyFiles(String from, String to) { |
| + final fromDir = new Directory(from); |
| + fromDir.onFile = (path) { |
| + final name = basename(path); |
| + // TODO(rnystrom): Hackish. Ignore 'hidden' files like .DS_Store. |
| + if (name.startsWith('.')) return; |
| + |
| + new File(path).readAsBytes((bytes) { |
| + final outFile = new File('$to/$name'); |
| + final stream = outFile.openOutputStream(FileMode.WRITE); |
| + stream.write(bytes, copyBuffer: false); |
| + stream.close(); |
| + }); |
| + }; |
| + fromDir.list(recursive: false); |
| +} |
| + |
| class Dartdoc { |
| /** Set to `false` to not include the source code in the generated docs. */ |
| bool includeSource = true; |
| @@ -115,6 +171,9 @@ class Dartdoc { |
| */ |
| int mode = MODE_LIVE_NAV; |
| + /** Path to generate HTML files into. */ |
| + String outputDir = 'docs'; |
| + |
| /** |
| * The title used for the overall generated output. Set this to change it. |
| */ |
| @@ -245,7 +304,7 @@ class Dartdoc { |
| } |
| void endFile() { |
| - final outPath = '$_outdir/$_filePath'; |
| + final outPath = '$outputDir/$_filePath'; |
| final dir = new Directory(dirname(outPath)); |
| if (!dir.existsSync()) { |
| dir.createSync(); |