mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 22:51:29 +00:00
Lots of little changes for dartdoc/apidoc.
* Alphabetized imports. * Added TODOs. * Removed some prefixes. * Cleaned up a LOT of async code to make it work better. * Much, much, much friendlier status messages for dartdoc/apidoc. More to do... * Prevented many, many bad warnings from showing up... by fixing them. * Smarter finding of packages directories. * Started using pathos all over the place. * Added indexed_db to html_diff. Review URL: https://codereview.chromium.org//12448006 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@19817 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
7c9197fa79
commit
6e056b8044
|
@ -5,9 +5,9 @@
|
|||
library webdriver;
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:json' as json;
|
||||
import 'dart:uri';
|
||||
import 'dart:io';
|
||||
|
||||
part 'src/base64decoder.dart';
|
||||
|
||||
|
|
|
@ -16,13 +16,14 @@
|
|||
*/
|
||||
library dartdoc;
|
||||
|
||||
import 'dart:io';
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import '../lib/dartdoc.dart';
|
||||
|
||||
// TODO(rnystrom): Use "package:" URL (#4968).
|
||||
import '../lib/dartdoc.dart';
|
||||
import '../../../../../pkg/pathos/lib/path.dart' as path;
|
||||
import '../../../../../pkg/args/lib/args.dart';
|
||||
import '../../../../../pkg/pathos/lib/path.dart' as path;
|
||||
|
||||
/**
|
||||
* Run this from the `lib/_internal/dartdoc` directory.
|
||||
|
@ -224,7 +225,7 @@ main() {
|
|||
var parts = path.split(dir);
|
||||
var libDir = parts.lastIndexOf('lib');
|
||||
if (libDir > 0) {
|
||||
pkgPath = new Path(path.join(path.joinAll(parts.take(libDir - 1)),
|
||||
pkgPath = new Path(path.join(path.joinAll(parts.take(libDir)),
|
||||
'packages'));
|
||||
}
|
||||
}
|
||||
|
@ -232,29 +233,27 @@ main() {
|
|||
|
||||
cleanOutputDirectory(dartdoc.outputDir);
|
||||
|
||||
print('Analyzing sources');
|
||||
Future documented = dartdoc.documentLibraries(entrypoints, libPath, pkgPath);
|
||||
|
||||
documented.then((_) {
|
||||
Future compiled = compileScript(dartdoc.mode, dartdoc.outputDir, libPath);
|
||||
Future filesCopied = copyDirectory(scriptDir.append('../static'),
|
||||
dartdoc.outputDir);
|
||||
|
||||
Future.wait([compiled, filesCopied]).then((_) {
|
||||
dartdoc.cleanup();
|
||||
if (dartdoc.totalLibraries + dartdoc.totalTypes +
|
||||
dartdoc.totalMembers == 0) {
|
||||
print('Nothing was documented!');
|
||||
// Start the analysis and documentation.
|
||||
dartdoc.documentLibraries(entrypoints, libPath, pkgPath)
|
||||
.then((_) {
|
||||
print('Copying static files...');
|
||||
Future.wait([
|
||||
// Prepare the dart2js script code and copy static resources.
|
||||
// TODO(amouravski): move compileScript out and pre-generate the client
|
||||
// scripts. This takes a long time and the js hardly ever changes.
|
||||
compileScript(dartdoc.mode, dartdoc.outputDir, libPath),
|
||||
copyDirectory(scriptDir.append('../static'), dartdoc.outputDir)
|
||||
]);
|
||||
})
|
||||
.then((_) {
|
||||
print(dartdoc.status);
|
||||
if (dartdoc.totals == 0) {
|
||||
exit(1);
|
||||
} else {
|
||||
print('Documented ${dartdoc.totalLibraries} libraries, '
|
||||
'${dartdoc.totalTypes} types, and ${dartdoc.totalMembers} '
|
||||
'members.');
|
||||
}
|
||||
});
|
||||
}, onError: (AsyncError asyncError) {
|
||||
print('Generation failed: ${asyncError.error}');
|
||||
dartdoc.cleanup();
|
||||
exit(1);
|
||||
});
|
||||
})
|
||||
.catchError((e) {
|
||||
print('Error: generation failed: ${e.error}');
|
||||
exit(1);
|
||||
})
|
||||
.whenComplete(() => dartdoc.cleanup());
|
||||
}
|
||||
|
|
|
@ -18,19 +18,22 @@ library dartdoc;
|
|||
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:json' as json;
|
||||
import 'dart:math';
|
||||
import 'dart:uri';
|
||||
import 'dart:json' as json;
|
||||
|
||||
import 'classify.dart';
|
||||
import 'markdown.dart' as md;
|
||||
import 'universe_serializer.dart';
|
||||
|
||||
import 'src/dartdoc/nav.dart';
|
||||
import 'src/json_serializer.dart' as json_serializer;
|
||||
|
||||
// TODO(rnystrom): Use "package:" URL (#4968).
|
||||
import '../../compiler/implementation/mirrors/dart2js_mirror.dart' as dart2js;
|
||||
import '../../compiler/implementation/mirrors/mirrors.dart';
|
||||
import '../../compiler/implementation/mirrors/mirrors_util.dart';
|
||||
import '../../compiler/implementation/mirrors/dart2js_mirror.dart' as dart2js;
|
||||
import 'classify.dart';
|
||||
import 'universe_serializer.dart';
|
||||
import 'markdown.dart' as md;
|
||||
import 'src/json_serializer.dart' as json_serializer;
|
||||
import '../../libraries.dart';
|
||||
import 'src/dartdoc/nav.dart';
|
||||
|
||||
part 'src/dartdoc/utils.dart';
|
||||
|
||||
|
@ -127,21 +130,17 @@ Future copyDirectory(Path from, Path to) {
|
|||
* Compiles the dartdoc client-side code to JavaScript using Dart2js.
|
||||
*/
|
||||
Future compileScript(int mode, Path outputDir, Path libPath) {
|
||||
print('Compiling client JavaScript...');
|
||||
var clientScript = (mode == MODE_STATIC) ? 'static' : 'live-nav';
|
||||
var dartPath = libPath.append(
|
||||
'lib/_internal/dartdoc/lib/src/client/client-$clientScript.dart');
|
||||
var jsPath = outputDir.append('client-$clientScript.js');
|
||||
|
||||
var completer = new Completer<bool>();
|
||||
Future<String> result = dart2js.compile(
|
||||
dartPath, libPath, options: const <String>['--categories=Client,Server']);
|
||||
result.then((jsCode) {
|
||||
if (jsCode != null) {
|
||||
return dart2js.compile(dartPath, libPath,
|
||||
options: const <String>['--categories=Client,Server'])
|
||||
.then((jsCode) {
|
||||
writeString(new File.fromPath(jsPath), jsCode);
|
||||
}
|
||||
completer.complete(jsCode != null);
|
||||
});
|
||||
return completer.future;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -290,6 +289,39 @@ class Dartdoc {
|
|||
int get totalTypes => _totalTypes;
|
||||
int get totalMembers => _totalMembers;
|
||||
|
||||
// Check if the compilation has started and finished.
|
||||
bool _started = false;
|
||||
bool _finished = false;
|
||||
|
||||
/**
|
||||
* Prints the status of dartdoc.
|
||||
*
|
||||
* Prints whether dartdoc is running, whether dartdoc has finished
|
||||
* succesfully or not, and how many libraries, types, and members were
|
||||
* documented.
|
||||
*/
|
||||
String get status {
|
||||
// TODO(amouravski): Make this more full featured and remove all other
|
||||
// prints and put them under verbose flag.
|
||||
if (!_started) {
|
||||
return 'Documentation has not yet started.';
|
||||
} else if (!_finished) {
|
||||
return 'Documentation in progress -- documented $_statisticsSummary so far.';
|
||||
} else {
|
||||
if (totals == 0) {
|
||||
return 'Documentation complete -- warning: nothing was documented!';
|
||||
} else {
|
||||
return 'Documentation complete -- documented $_statisticsSummary.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int get totals => totalLibraries + totalTypes + totalMembers;
|
||||
|
||||
String get _statisticsSummary =>
|
||||
'${totalLibraries} libraries, ${totalTypes} types, and '
|
||||
'${totalMembers} members';
|
||||
|
||||
static const List<String> COMPILER_OPTIONS =
|
||||
const <String>['--preserve-comments', '--categories=Client,Server'];
|
||||
|
||||
|
@ -376,19 +408,20 @@ class Dartdoc {
|
|||
}
|
||||
|
||||
Future documentLibraries(List<Path> libraryList, Path libPath, Path pkgPath) {
|
||||
Completer completer = new Completer();
|
||||
Future<MirrorSystem> result = dart2js.analyze(libraryList, libPath,
|
||||
packageRoot: pkgPath, options: COMPILER_OPTIONS);
|
||||
result.then((MirrorSystem mirrors) {
|
||||
_document(mirrors);
|
||||
completer.complete(true);
|
||||
}, onError: (AsyncError error) {
|
||||
completer.completeError(error.error);
|
||||
});
|
||||
return completer.future;
|
||||
// TODO(amouravski): make all of these print statements into logging
|
||||
// statements.
|
||||
print('Analyzing libraries...');
|
||||
return dart2js.analyze(libraryList, libPath, packageRoot: pkgPath,
|
||||
options: COMPILER_OPTIONS)
|
||||
.then((MirrorSystem mirrors) {
|
||||
print('Generating documentation...');
|
||||
_document(mirrors);
|
||||
});
|
||||
}
|
||||
|
||||
void _document(MirrorSystem mirrors) {
|
||||
_started = true;
|
||||
|
||||
// Sort the libraries by name (not key).
|
||||
_sortedLibraries = new List<LibraryMirror>.from(
|
||||
mirrors.libraries.values.where(shouldIncludeLibrary));
|
||||
|
@ -447,6 +480,8 @@ class Dartdoc {
|
|||
packageManifest.location = revision;
|
||||
write(json_serializer.serialize(packageManifest));
|
||||
endFile();
|
||||
|
||||
_finished = true;
|
||||
}
|
||||
|
||||
MdnComment lookupMdnComment(Mirror mirror) => null;
|
||||
|
|
|
@ -8,11 +8,14 @@
|
|||
*/
|
||||
library universe_serializer;
|
||||
|
||||
import 'dartdoc.dart';
|
||||
|
||||
// TODO(rnystrom): Use "package:" URL (#4968).
|
||||
import '../../../../../pkg/pathos/lib/path.dart' as path;
|
||||
import '../../compiler/implementation/mirrors/dart2js_mirror.dart' as dart2js;
|
||||
import '../../compiler/implementation/mirrors/mirrors.dart';
|
||||
import '../../compiler/implementation/mirrors/mirrors_util.dart';
|
||||
import '../../compiler/implementation/mirrors/dart2js_mirror.dart' as dart2js;
|
||||
import '../../libraries.dart';
|
||||
import 'dartdoc.dart';
|
||||
|
||||
String _stripUri(String uri) {
|
||||
String prefix = "/dart/";
|
||||
|
@ -40,7 +43,7 @@ class Element {
|
|||
final String id;
|
||||
/** Raw text of the comment associated with the Element if any. */
|
||||
final String comment;
|
||||
/** Raw html comment for the Element from MDN. */
|
||||
/** Raw html comment for the Element from MDN. */
|
||||
String mdnCommentHtml;
|
||||
/**
|
||||
* The URL to the page on MDN that content was pulled from for the current
|
||||
|
@ -136,7 +139,7 @@ class LibraryElement extends Element {
|
|||
* or implemented by classes in this library.
|
||||
*/
|
||||
List<LibraryElement> dependencies;
|
||||
|
||||
|
||||
/**
|
||||
* Construct a LibraryElement from a [mirror].
|
||||
*
|
||||
|
@ -197,21 +200,30 @@ class LibraryElement extends Element {
|
|||
// TODO(jacobr): this is a hack. Remove once these libraries are removed
|
||||
// from the sdk.
|
||||
var uri = mirror.uri;
|
||||
var path = uri.path;
|
||||
var pattern = new RegExp(r'[\\/]dart[\\/]pkg[\\/]([^\\/]+)[\\/]lib[\\/](.+)$');
|
||||
var match = pattern.firstMatch(path);
|
||||
var package;
|
||||
if (match != null) {
|
||||
package = match.group(1);
|
||||
path = match.group(2);
|
||||
var uriPath = uri.path;
|
||||
|
||||
var parts = path.split(uriPath);
|
||||
|
||||
// Find either pkg/ or packages/
|
||||
var pkgDir = parts.lastIndexOf('pkg');
|
||||
var packageDir = parts.lastIndexOf('packages');
|
||||
|
||||
if (pkgDir >= 0) {
|
||||
packageDir = pkgDir;
|
||||
}
|
||||
// TODO(jacobr): add a second pattern for a more typical pub environment.
|
||||
if (package != null) {
|
||||
return 'package:$package/$path';
|
||||
} else {
|
||||
|
||||
var libDir = parts.lastIndexOf('lib');
|
||||
var rest = parts.getRange(libDir + 1, parts.length - libDir - 1);
|
||||
|
||||
// If there's no lib, we can't find the package.
|
||||
if (libDir < 0 || libDir < packageDir) {
|
||||
// TODO(jacobr): this is a lousy fallback.
|
||||
print("Unable to determine package for $path.");
|
||||
print("Unable to determine package for $uriPath.");
|
||||
return mirror.uri.toString();
|
||||
} else if (packageDir >= 0 && rest.length >= 1) {
|
||||
// For URI: foo/bar/packages/widget/lib/sprocket.dart will return:
|
||||
// 'package:widget/sprocket.dart'
|
||||
return 'package:${parts[packageDir + 1]}/${rest.join('/')}';
|
||||
}
|
||||
} else {
|
||||
return mirror.uri.toString();
|
||||
|
@ -253,7 +265,7 @@ class ClassElement extends Element {
|
|||
List<Reference> interfaces;
|
||||
/** Whether the class implements or extends [Error] or [Exception]. */
|
||||
bool isThrowable;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a [ClassElement] from a [ClassMirror].
|
||||
*
|
||||
|
@ -393,7 +405,7 @@ class ParameterElement extends Element {
|
|||
* Returns the initialized field, if this parameter is an initializing formal.
|
||||
*/
|
||||
final Reference initializedField;
|
||||
|
||||
|
||||
ParameterElement(ParameterMirror mirror)
|
||||
: super(mirror, 'param', mirror.simpleName, mirror.simpleName, null,
|
||||
null),
|
||||
|
@ -402,7 +414,7 @@ class ParameterElement extends Element {
|
|||
defaultValue = mirror.defaultValue,
|
||||
isNamed = _optionalBool(mirror.isNamed),
|
||||
initializedField = _optionalReference(mirror.initializedField) {
|
||||
|
||||
|
||||
if (mirror.type is FunctionTypeMirror) {
|
||||
addChild(new FunctionTypeElement(mirror.type));
|
||||
}
|
||||
|
@ -411,7 +423,7 @@ class ParameterElement extends Element {
|
|||
|
||||
class FunctionTypeElement extends Element {
|
||||
final Reference returnType;
|
||||
|
||||
|
||||
FunctionTypeElement(FunctionTypeMirror mirror)
|
||||
: super(mirror, 'functiontype', mirror.simpleName, mirror.simpleName, null, null),
|
||||
returnType = _optionalReference(mirror.returnType) {
|
||||
|
@ -431,7 +443,7 @@ class FunctionTypeElement extends Element {
|
|||
class TypeParameterElement extends Element {
|
||||
/**
|
||||
* Upper bound for the parameter.
|
||||
*
|
||||
*
|
||||
* In the following code sample, [:Bar:] is an upper bound:
|
||||
* [: class Bar<T extends Foo> { } :]
|
||||
*/
|
||||
|
@ -505,7 +517,7 @@ class Reference {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO(jacobr): compute the referenceId correctly for the general case so
|
||||
// that this method can work with all element types not just LibraryElements.
|
||||
Reference.fromElement(LibraryElement e) : name = e.name, refId = e.id;
|
||||
|
|
|
@ -261,7 +261,7 @@ Future<ProcessResult> _runDartdoc(List<String> libraryPaths) {
|
|||
}
|
||||
|
||||
final _dartdocCompletionRegExp =
|
||||
new RegExp(r'Documented (\d+) libraries, (\d+) types, and (\d+) members\.');
|
||||
new RegExp(r'Documentation complete -- documented (\d+) libraries, (\d+) types, and (\d+) members\.');
|
||||
|
||||
void _expectDocumented(String output, { int libCount, int typeCount,
|
||||
int memberCount}) {
|
||||
|
|
|
@ -17,11 +17,13 @@ library apidoc;
|
|||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:json' as json;
|
||||
|
||||
import 'html_diff.dart';
|
||||
|
||||
// TODO(rnystrom): Use "package:" URL (#4968).
|
||||
import '../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart';
|
||||
import '../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.dart';
|
||||
import '../../sdk/lib/_internal/dartdoc/lib/dartdoc.dart' as doc;
|
||||
import '../../sdk/lib/_internal/dartdoc/lib/dartdoc.dart';
|
||||
import '../../sdk/lib/_internal/libraries.dart';
|
||||
|
||||
HtmlDiff _diff;
|
||||
|
@ -29,7 +31,7 @@ HtmlDiff _diff;
|
|||
void main() {
|
||||
final args = new Options().arguments;
|
||||
|
||||
int mode = doc.MODE_STATIC;
|
||||
int mode = MODE_STATIC;
|
||||
Path outputDir = new Path('docs');
|
||||
bool generateAppCache = false;
|
||||
|
||||
|
@ -44,11 +46,11 @@ void main() {
|
|||
|
||||
switch (arg) {
|
||||
case '--mode=static':
|
||||
mode = doc.MODE_STATIC;
|
||||
mode = MODE_STATIC;
|
||||
break;
|
||||
|
||||
case '--mode=live-nav':
|
||||
mode = doc.MODE_LIVE_NAV;
|
||||
mode = MODE_LIVE_NAV;
|
||||
break;
|
||||
|
||||
case '--generate-app-cache=true':
|
||||
|
@ -74,30 +76,31 @@ void main() {
|
|||
}
|
||||
}
|
||||
|
||||
final libPath = doc.scriptDir.append('../../sdk/');
|
||||
final libPath = scriptDir.append('../../sdk/');
|
||||
|
||||
doc.cleanOutputDirectory(outputDir);
|
||||
cleanOutputDirectory(outputDir);
|
||||
|
||||
print('Copying static files...');
|
||||
// The basic dartdoc-provided static content.
|
||||
final copiedStatic = doc.copyDirectory(
|
||||
doc.scriptDir.append('../../sdk/lib/_internal/dartdoc/static'),
|
||||
final copiedStatic = copyDirectory(
|
||||
scriptDir.append('../../sdk/lib/_internal/dartdoc/static'),
|
||||
outputDir);
|
||||
|
||||
// The apidoc-specific static content.
|
||||
final copiedApiDocStatic = doc.copyDirectory(
|
||||
doc.scriptDir.append('static'),
|
||||
final copiedApiDocStatic = copyDirectory(
|
||||
scriptDir.append('static'),
|
||||
outputDir);
|
||||
|
||||
print('Parsing MDN data...');
|
||||
final mdnFile = new File.fromPath(doc.scriptDir.append('mdn/database.json'));
|
||||
final mdnFile = new File.fromPath(scriptDir.append('mdn/database.json'));
|
||||
final mdn = json.parse(mdnFile.readAsStringSync());
|
||||
|
||||
print('Cross-referencing dart:html...');
|
||||
// TODO(amouravski): move HtmlDiff inside of the future chain below to re-use
|
||||
// the MirrorSystem already analyzed.
|
||||
_diff = new HtmlDiff(printWarnings:false);
|
||||
Future htmlDiff = _diff.run(libPath);
|
||||
|
||||
// Process libraries.
|
||||
|
||||
// TODO(johnniwinther): Libraries for the compilation seem to be more like
|
||||
// URIs. Perhaps Path should have a toURI() method.
|
||||
// Add all of the core libraries.
|
||||
|
@ -108,63 +111,51 @@ void main() {
|
|||
}
|
||||
});
|
||||
|
||||
var lister = new Directory.fromPath(doc.scriptDir.append('../../pkg')).list();
|
||||
lister.listen(
|
||||
(entity) {
|
||||
if (entity is Directory) {
|
||||
var path = new Path(entity.path);
|
||||
var libName = path.filename;
|
||||
// TODO(amouravski): This code is really wonky.
|
||||
var lister = new Directory.fromPath(scriptDir.append('../../pkg')).list();
|
||||
lister.listen((entity) {
|
||||
if (entity is Directory) {
|
||||
var path = new Path(entity.path);
|
||||
var libName = path.filename;
|
||||
var libPath = path.append('lib/$libName.dart');
|
||||
|
||||
// Ignore hidden directories (like .svn) as well as pkg.xcodeproj.
|
||||
if (libName.startsWith('.') || libName.endsWith('.xcodeproj')) {
|
||||
return;
|
||||
}
|
||||
// Ignore some libraries.
|
||||
if (excludedLibraries.contains(libName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO(rnystrom): Get rid of oldStylePath support when all
|
||||
// packages are using new layout. See #5106.
|
||||
var oldStylePath = path.append('${libName}.dart');
|
||||
var newStylePath = path.append('lib/${libName}.dart');
|
||||
// Ignore hidden directories (like .svn) as well as pkg.xcodeproj.
|
||||
if (libName.startsWith('.') || libName.endsWith('.xcodeproj')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (new File.fromPath(oldStylePath).existsSync()) {
|
||||
apidocLibraries.add(oldStylePath);
|
||||
includedLibraries.add(libName);
|
||||
} else if (new File.fromPath(newStylePath).existsSync()) {
|
||||
apidocLibraries.add(newStylePath);
|
||||
includedLibraries.add(libName);
|
||||
} else {
|
||||
print('Warning: could not find package at $path');
|
||||
}
|
||||
}
|
||||
},
|
||||
onDone: () {
|
||||
print('Generating docs...');
|
||||
final apidoc = new Apidoc(mdn, outputDir, mode, generateAppCache,
|
||||
excludedLibraries, version);
|
||||
apidoc.dartdocPath =
|
||||
doc.scriptDir.append('../../sdk/lib/_internal/dartdoc/');
|
||||
// Select the libraries to include in the produced documentation:
|
||||
apidoc.includeApi = true;
|
||||
apidoc.includedLibraries = includedLibraries;
|
||||
if (new File.fromPath(libPath).existsSync()) {
|
||||
apidocLibraries.add(libPath);
|
||||
includedLibraries.add(libName);
|
||||
} else {
|
||||
print('Warning: could not find package at $path');
|
||||
}
|
||||
}
|
||||
}, onDone: () {
|
||||
final apidoc = new Apidoc(mdn, outputDir, mode, generateAppCache,
|
||||
excludedLibraries, version);
|
||||
apidoc.dartdocPath =
|
||||
scriptDir.append('../../sdk/lib/_internal/dartdoc/');
|
||||
// Select the libraries to include in the produced documentation:
|
||||
apidoc.includeApi = true;
|
||||
apidoc.includedLibraries = includedLibraries;
|
||||
|
||||
Future.wait([copiedStatic, copiedApiDocStatic, htmlDiff]).then((_) {
|
||||
Future<bool> documented =
|
||||
apidoc.documentLibraries(apidocLibraries, libPath, pkgPath);
|
||||
|
||||
documented.then((_) {
|
||||
final compiled = doc.compileScript(mode, outputDir, libPath);
|
||||
|
||||
Future.wait([compiled]).then((_) {
|
||||
apidoc.cleanup();
|
||||
});
|
||||
}, onError: (AsyncError asyncError) {
|
||||
print('Generation failed: ${asyncError.error}');
|
||||
apidoc.cleanup();
|
||||
});
|
||||
});
|
||||
});
|
||||
// TODO(amouravski): make apidoc use roughly the same flow as bin/dartdoc.
|
||||
Future.wait([copiedStatic, copiedApiDocStatic, htmlDiff])
|
||||
.then((_) => apidoc.documentLibraries(apidocLibraries, libPath, pkgPath))
|
||||
.then((_) => compileScript(mode, outputDir, libPath))
|
||||
.then((_) => print(apidoc.status))
|
||||
.catchError((e) => print('Error: generation failed: ${e.error}'))
|
||||
.whenComplete(() => apidoc.cleanup());
|
||||
});
|
||||
}
|
||||
|
||||
class Apidoc extends doc.Dartdoc {
|
||||
class Apidoc extends Dartdoc {
|
||||
/** Big ball of JSON containing the scraped MDN documentation. */
|
||||
final Map mdn;
|
||||
|
||||
|
@ -254,40 +245,40 @@ class Apidoc extends doc.Dartdoc {
|
|||
void docIndexLibrary(LibraryMirror library) {
|
||||
// TODO(rnystrom): Hackish. The IO libraries reference this but we don't
|
||||
// want it in the docs.
|
||||
if (doc.displayName(library) == 'dart:nativewrappers') return;
|
||||
if (displayName(library) == 'dart:nativewrappers') return;
|
||||
super.docIndexLibrary(library);
|
||||
}
|
||||
|
||||
void docLibraryNavigationJson(LibraryMirror library, List libraryList) {
|
||||
// TODO(rnystrom): Hackish. The IO libraries reference this but we don't
|
||||
// want it in the docs.
|
||||
if (doc.displayName(library) == 'dart:nativewrappers') return;
|
||||
if (displayName(library) == 'dart:nativewrappers') return;
|
||||
super.docLibraryNavigationJson(library, libraryList);
|
||||
}
|
||||
|
||||
void docLibrary(LibraryMirror library) {
|
||||
// TODO(rnystrom): Hackish. The IO libraries reference this but we don't
|
||||
// want it in the docs.
|
||||
if (doc.displayName(library) == 'dart:nativewrappers') return;
|
||||
if (displayName(library) == 'dart:nativewrappers') return;
|
||||
super.docLibrary(library);
|
||||
}
|
||||
|
||||
doc.DocComment getLibraryComment(LibraryMirror library) {
|
||||
DocComment getLibraryComment(LibraryMirror library) {
|
||||
return super.getLibraryComment(library);
|
||||
}
|
||||
|
||||
doc.DocComment getTypeComment(TypeMirror type) {
|
||||
DocComment getTypeComment(TypeMirror type) {
|
||||
return _mergeDocs(
|
||||
includeMdnTypeComment(type), super.getTypeComment(type));
|
||||
}
|
||||
|
||||
doc.DocComment getMemberComment(MemberMirror member) {
|
||||
DocComment getMemberComment(MemberMirror member) {
|
||||
return _mergeDocs(
|
||||
includeMdnMemberComment(member), super.getMemberComment(member));
|
||||
}
|
||||
|
||||
doc.DocComment _mergeDocs(doc.MdnComment mdnComment,
|
||||
doc.DocComment fileComment) {
|
||||
DocComment _mergeDocs(MdnComment mdnComment,
|
||||
DocComment fileComment) {
|
||||
// Otherwise, prefer comment from the (possibly generated) Dart file.
|
||||
if (fileComment != null) return fileComment;
|
||||
|
||||
|
@ -333,7 +324,7 @@ class Apidoc extends doc.Dartdoc {
|
|||
}
|
||||
}
|
||||
|
||||
doc.MdnComment lookupMdnComment(Mirror mirror) {
|
||||
MdnComment lookupMdnComment(Mirror mirror) {
|
||||
if (mirror is TypeMirror) {
|
||||
return includeMdnTypeComment(mirror);
|
||||
} else if (mirror is MemberMirror) {
|
||||
|
@ -347,14 +338,13 @@ class Apidoc extends doc.Dartdoc {
|
|||
* Gets the MDN-scraped docs for [type], or `null` if this type isn't
|
||||
* scraped from MDN.
|
||||
*/
|
||||
doc.MdnComment includeMdnTypeComment(TypeMirror type) {
|
||||
MdnComment includeMdnTypeComment(TypeMirror type) {
|
||||
if (_mdnTypeNamesToSkip.contains(type.simpleName)) {
|
||||
print('Skipping MDN type ${type.simpleName}');
|
||||
return null;
|
||||
}
|
||||
|
||||
var typeString = '';
|
||||
if (HTML_LIBRARY_NAMES.contains(doc.displayName(type.library))) {
|
||||
if (HTML_LIBRARY_NAMES.contains(displayName(type.library))) {
|
||||
// If it's an HTML type, try to map it to a base DOM type so we can find
|
||||
// the MDN docs.
|
||||
final domTypes = _diff.htmlTypesToDom[type.qualifiedName];
|
||||
|
@ -381,17 +371,17 @@ class Apidoc extends doc.Dartdoc {
|
|||
if (mdnType['summary'].trim().isEmpty) return null;
|
||||
|
||||
// Remember which MDN page we're using so we can attribute it.
|
||||
return new doc.MdnComment(mdnType['summary'], mdnType['srcUrl']);
|
||||
return new MdnComment(mdnType['summary'], mdnType['srcUrl']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the MDN-scraped docs for [member], or `null` if this type isn't
|
||||
* scraped from MDN.
|
||||
*/
|
||||
doc.MdnComment includeMdnMemberComment(MemberMirror member) {
|
||||
MdnComment includeMdnMemberComment(MemberMirror member) {
|
||||
var library = findLibrary(member);
|
||||
var memberString = '';
|
||||
if (HTML_LIBRARY_NAMES.contains(doc.displayName(library))) {
|
||||
if (HTML_LIBRARY_NAMES.contains(displayName(library))) {
|
||||
// If it's an HTML type, try to map it to a DOM type name so we can find
|
||||
// the MDN docs.
|
||||
final domMembers = _diff.htmlToDom[member.qualifiedName];
|
||||
|
@ -434,7 +424,7 @@ class Apidoc extends doc.Dartdoc {
|
|||
if (mdnMember['help'].trim().isEmpty) return null;
|
||||
|
||||
// Remember which MDN page we're using so we can attribute it.
|
||||
return new doc.MdnComment(mdnMember['help'], mdnType['srcUrl']);
|
||||
return new MdnComment(mdnMember['help'], mdnType['srcUrl']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -50,8 +50,10 @@
|
|||
'apidoc.dart',
|
||||
'--out=<(PRODUCT_DIR)/api_docs',
|
||||
'--version=<!@(["python", "../../tools/print_version.py"])',
|
||||
'--pkg=<(PRODUCT_DIR)/packages/',
|
||||
'--pkg=<(PRODUCT_DIR)/packages',
|
||||
'--mode=static',
|
||||
'--exclude-lib=analyzer-experimental',
|
||||
'--exclude-lib=browser',
|
||||
'--exclude-lib=dartdoc',
|
||||
'--exclude-lib=http',
|
||||
'--exclude-lib=oauth2',
|
||||
|
|
|
@ -8,26 +8,29 @@
|
|||
*/
|
||||
library html_diff;
|
||||
|
||||
import 'dart:io';
|
||||
import 'dart:async';
|
||||
import '../../sdk/lib/html/html_common/metadata.dart';
|
||||
import 'dart:io';
|
||||
|
||||
import 'lib/metadata.dart';
|
||||
|
||||
// TODO(rnystrom): Use "package:" URL (#4968).
|
||||
import '../../sdk/lib/_internal/dartdoc/lib/dartdoc.dart';
|
||||
import '../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirror.dart';
|
||||
import '../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart';
|
||||
import '../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.dart';
|
||||
import '../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirror.dart';
|
||||
import '../../sdk/lib/_internal/dartdoc/lib/dartdoc.dart';
|
||||
import '../../sdk/lib/html/html_common/metadata.dart';
|
||||
|
||||
// TODO(amouravski): There is currently magic that looks at dart:* libraries
|
||||
// rather than the declared library names. This changed due to recent syntax
|
||||
// changes. We should only need to look at the library 'html'.
|
||||
const List<String> HTML_LIBRARY_NAMES = const [
|
||||
'dart:html',
|
||||
'dart:indexed_db',
|
||||
'dart:svg',
|
||||
'dart:web_audio'];
|
||||
const List<String> HTML_DECLARED_NAMES = const [
|
||||
'dart.dom.html',
|
||||
'dart.dom.indexed_db',
|
||||
'dart.dom.svg',
|
||||
'dart.dom.web_audio'];
|
||||
|
||||
|
|
Loading…
Reference in a new issue