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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: lib/dartdoc/dartdoc.dart
diff --git a/lib/dartdoc/dartdoc.dart b/lib/dartdoc/dartdoc.dart
index 0c121eb976c4c7890b9306c261a449e74d6e9e88..dc530403d91d28431ff5afcbb4af4c439a89747a 100644
--- a/lib/dartdoc/dartdoc.dart
+++ b/lib/dartdoc/dartdoc.dart
@@ -3,9 +3,10 @@
// BSD-style license that can be found in the LICENSE file.
/**
- * To use it, from this directory, run:
+ * To generate docs for a library, run this script with the path to an
+ * entrypoint .dart file, like:
*
- * $ ./dartdoc <path to .dart file>
+ * $ dart dartdoc.dart foo.dart
*
* This will create a "docs" directory with the docs for your libraries. To
* create these beautiful docs, dartdoc parses your library and every library
@@ -89,31 +90,35 @@ void main() {
final entrypoint = args[args.length - 1];
final files = new VMFileSystem();
+
+ final frogPath = joinPaths(scriptDir, '../../frog/');
+
// 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
// sure SDK builds still work.
- parseOptions('../../frog', ['', '', '--libdir=../../frog/lib'], files);
+ parseOptions(frogPath, ['', '', '--libdir=$frogPath/lib'], files);
initializeWorld(files);
- var dartdoc;
- final elapsed = time(() {
- dartdoc = new Dartdoc();
+ final dartdoc = new Dartdoc();
+
+ if (includeSource != null) dartdoc.includeSource = includeSource;
+ if (mode != null) dartdoc.mode = mode;
+ if (outputDir != null) dartdoc.outputDir = outputDir;
- if (includeSource != null) dartdoc.includeSource = includeSource;
- if (mode != null) dartdoc.mode = mode;
- if (outputDir != null) dartdoc.outputDir = outputDir;
+ cleanOutputDirectory(dartdoc.outputDir);
- cleanOutputDirectory(outputDir);
+ // Compile the client-side code to JS.
+ final clientScript = (dartdoc.mode == MODE_STATIC) ? 'static' : 'live-nav';
+ compileScript(frogPath, '$scriptDir/client-$clientScript.dart',
+ '${dartdoc.outputDir}/client-$clientScript.js');
- // TODO(rnystrom): Use platform-specific path separator.
- copyFiles('$scriptDir/static', outputDir);
+ copyFiles('$scriptDir/static', dartdoc.outputDir);
- dartdoc.document(entrypoint);
- });
+ dartdoc.document(entrypoint);
print('Documented ${dartdoc._totalLibraries} libraries, ' +
'${dartdoc._totalTypes} types, and ' +
- '${dartdoc._totalMembers} members in ${elapsed}msec.');
+ '${dartdoc._totalMembers} members.');
}
/**
@@ -161,6 +166,23 @@ void copyFiles(String from, String to) {
fromDir.list(recursive: false);
}
+/**
+ * Compiles the given Dart script to a JavaScript file at [jsPath] using frog.
+ */
+void compileScript(String frogPath, String dartPath, String jsPath) {
+ final process = new Process.start('$frogPath/minfrog', [
+ '--libdir=$frogPath/lib', '--out=$jsPath',
+ '--compile-only', '--enable-type-checks', '--warnings-as-errors',
+ dartPath]);
+
+ process.stdout.pipe(stdout, close: false);
+
+ process.onError = (error) {
+ print('Failed to compile $dartPath. Error:');
+ 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
+ };
+}
+
class Dartdoc {
/** Set to `false` to not include the source code in the generated docs. */
bool includeSource = true;
@@ -240,43 +262,15 @@ class Dartdoc {
member: _currentMember));
}
- void document(String entrypoint) {
+ void document([String entrypoint]) {
var oldDietParse = options.dietParse;
try {
options.dietParse = true;
- // Handle the built-in entrypoints.
- switch (entrypoint) {
- case 'corelib':
- world.getOrAddLibrary('dart:core');
- world.getOrAddLibrary('dart:coreimpl');
- world.getOrAddLibrary('dart:json');
- world.getOrAddLibrary('dart:isolate');
- world.process();
- break;
-
- case 'dom':
- world.getOrAddLibrary('dart:core');
- world.getOrAddLibrary('dart:coreimpl');
- world.getOrAddLibrary('dart:json');
- world.getOrAddLibrary('dart:dom');
- world.getOrAddLibrary('dart:isolate');
- world.process();
- break;
-
- case 'html':
- world.getOrAddLibrary('dart:core');
- world.getOrAddLibrary('dart:coreimpl');
- world.getOrAddLibrary('dart:json');
- world.getOrAddLibrary('dart:dom');
- world.getOrAddLibrary('dart:html');
- world.getOrAddLibrary('dart:isolate');
- world.process();
- break;
-
- default:
- // Normal entrypoint script.
- world.processDartScript(entrypoint);
+ // If we have an entrypoint, process it. Otherwise, just use whatever
+ // libraries have been previously loaded by the calling code.
+ if (entrypoint != null) {
+ world.processDartScript(entrypoint);
}
world.resolveAll();
« 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