Generate DartDoc documentation.
DartDocResults is returned if dartdoc succeeds. DartDocFailure is thrown if dartdoc fails in an expected way, for example if there is an analysis error in the code. Any other exception can be throw if there is an unexpected failure.
Source
Future<DartDocResults> generateDocs() async { _stopwatch = new Stopwatch()..start(); List<String> files = packageMeta.isSdk ? const [] : findFilesToDocumentInPackage(rootDir.path).toList(); // TODO(jcollins-g): seems like most of this belongs in the Package constructor List<LibraryElement> libraries = _parseLibraries(files, includeExternals); if (includes != null && includes.isNotEmpty) { Iterable knownLibraryNames = libraries.map((l) => l.name); Set notFound = new Set.from(includes).difference(new Set.from(knownLibraryNames)); if (notFound.isNotEmpty) { throw 'Did not find: [${notFound.join(', ')}] in ' 'known libraries: [${knownLibraryNames.join(', ')}]'; } libraries.removeWhere((lib) => !includes.contains(lib.name)); } else { // remove excluded libraries excludes.forEach((pattern) { libraries.removeWhere((lib) { return lib.name.startsWith(pattern) || lib.name == pattern; }); }); } PackageWarningOptions warningOptions = new PackageWarningOptions(); // TODO(jcollins-g): explode this into detailed command line options. if (config != null && config.showWarnings) { for (PackageWarning kind in PackageWarning.values) { warningOptions.warn(kind); } } Package package; if (config != null && config.autoIncludeDependencies) { package = Package.withAutoIncludedDependencies( libraries, packageMeta, warningOptions); libraries = package.libraries.map((l) => l.element).toList(); // remove excluded libraries again, in case they are picked up through // dependencies. excludes.forEach((pattern) { libraries.removeWhere((lib) { return lib.name.startsWith(pattern) || lib.name == pattern; }); }); } package = new Package(libraries, packageMeta, warningOptions); // Go through docs of every model element in package to prebuild the macros index // TODO(jcollins-g): move index building into a cached-on-demand generation // like most other bits in [Package]. package.allCanonicalModelElements.forEach((m) => m.documentation); // Create the out directory. if (!outputDir.existsSync()) outputDir.createSync(recursive: true); for (var generator in generators) { await generator.generate(package, outputDir); writtenFiles.addAll(generator.writtenFiles.map(path.normalize)); } verifyLinks(package, outputDir.path); int warnings = package.packageWarningCounter.warningCount; int errors = package.packageWarningCounter.errorCount; if (warnings == 0 && errors == 0) { print("\nno issues found"); } else { print("\nfound ${warnings} ${pluralize('warning', warnings)} " "and ${errors} ${pluralize('error', errors)}"); } double seconds = _stopwatch.elapsedMilliseconds / 1000.0; print( "\ndocumented ${package.libraries.length} librar${package.libraries.length == 1 ? 'y' : 'ies'} " "in ${seconds.toStringAsFixed(1)} seconds"); if (package.libraries.isEmpty) { throw new DartDocFailure( "dartdoc could not find any libraries to document. Run `pub get` and try again."); } if (package.packageWarningCounter.errorCount > 0) { throw new DartDocFailure("dartdoc encountered errors while processing"); } return new DartDocResults(packageMeta, package, outputDir); }