Skip to content

Commit d7e6ea5

Browse files
authored
Implement new combined dartdoc option class (#1666)
* Squash commits * Windows drive letters :-( * Forgot a slash * Canonicalization missed one spot. * One more capitalization problem * Review comments
1 parent 3b0bc62 commit d7e6ea5

File tree

10 files changed

+1199
-61
lines changed

10 files changed

+1199
-61
lines changed

bin/dartdoc.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ main(List<String> arguments) async {
200200
]);
201201
}
202202

203-
DartDocConfig config = new DartDocConfig.fromParameters(
203+
DartdocConfig config = new DartdocConfig.fromParameters(
204204
addCrossdart: args['add-crossdart'],
205205
autoIncludeDependencies: args['auto-include-dependencies'],
206206
dropTextFrom: dropTextFrom,
@@ -230,20 +230,20 @@ main(List<String> arguments) async {
230230
verboseWarnings: args['verbose-warnings'],
231231
);
232232

233-
DartDoc dartdoc =
234-
await DartDoc.withDefaultGenerators(config, outputDir, packageMeta);
233+
Dartdoc dartdoc =
234+
await Dartdoc.withDefaultGenerators(config, outputDir, packageMeta);
235235

236236
dartdoc.onCheckProgress.listen(logProgress);
237237
await Chain.capture(() async {
238238
await runZoned(() async {
239-
DartDocResults results = await dartdoc.generateDocs();
239+
DartdocResults results = await dartdoc.generateDocs();
240240
logInfo('Success! Docs generated into ${results.outDir.absolute.path}');
241241
},
242242
zoneSpecification: new ZoneSpecification(
243243
print: (Zone self, ZoneDelegate parent, Zone zone, String line) =>
244244
logPrint(line)));
245245
}, onError: (e, Chain chain) {
246-
if (e is DartDocFailure) {
246+
if (e is DartdocFailure) {
247247
stderr.writeln('\nGeneration failed: ${e}.');
248248
exit(1);
249249
} else {

lib/dartdoc.dart

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Future<List<Generator>> _initGenerators(String url, String relCanonicalPrefix,
6565

6666
/// Generates Dart documentation for all public Dart libraries in the given
6767
/// directory.
68-
class DartDoc extends PackageBuilder {
68+
class Dartdoc extends PackageBuilder {
6969
final List<Generator> generators;
7070
final Directory outputDir;
7171
final Set<String> writtenFiles = new Set();
@@ -74,13 +74,13 @@ class DartDoc extends PackageBuilder {
7474
final StreamController<String> _onCheckProgress =
7575
new StreamController(sync: true);
7676

77-
DartDoc._(DartDocConfig config, this.generators, this.outputDir,
77+
Dartdoc._(DartdocConfig config, this.generators, this.outputDir,
7878
PackageMeta packageMeta)
7979
: super(config, packageMeta);
8080

8181
/// An asynchronous factory method that builds Dartdoc's file writers
82-
/// and returns a DartDoc object with them.
83-
static withDefaultGenerators(DartDocConfig config, Directory outputDir,
82+
/// and returns a Dartdoc object with them.
83+
static withDefaultGenerators(DartdocConfig config, Directory outputDir,
8484
PackageMeta packageMeta) async {
8585
var generators = await _initGenerators(
8686
config.hostedUrl, config.relCanonicalPrefix,
@@ -92,12 +92,12 @@ class DartDoc extends PackageBuilder {
9292
for (var generator in generators) {
9393
generator.onFileCreated.listen(logProgress);
9494
}
95-
return new DartDoc._(config, generators, outputDir, packageMeta);
95+
return new Dartdoc._(config, generators, outputDir, packageMeta);
9696
}
9797

98-
factory DartDoc.withoutGenerators(
99-
DartDocConfig config, Directory outputDir, PackageMeta packageMeta) {
100-
return new DartDoc._(config, [], outputDir, packageMeta);
98+
factory Dartdoc.withoutGenerators(
99+
DartdocConfig config, Directory outputDir, PackageMeta packageMeta) {
100+
return new Dartdoc._(config, [], outputDir, packageMeta);
101101
}
102102

103103
Stream<String> get onCheckProgress => _onCheckProgress.stream;
@@ -145,19 +145,19 @@ class DartDoc extends PackageBuilder {
145145

146146
if (errors.isNotEmpty) {
147147
int len = errors.length;
148-
throw new DartDocFailure(
148+
throw new DartdocFailure(
149149
"encountered ${len} analysis error${len == 1 ? '' : 's'}");
150150
}
151151
}
152152

153153
PackageGraph packageGraph;
154154

155-
/// Generate DartDoc documentation.
155+
/// Generate Dartdoc documentation.
156156
///
157-
/// [DartDocResults] is returned if dartdoc succeeds. [DartDocFailure] is
157+
/// [DartdocResults] is returned if dartdoc succeeds. [DartdocFailure] is
158158
/// thrown if dartdoc fails in an expected way, for example if there is an
159159
/// analysis error in the code.
160-
Future<DartDocResults> generateDocs() async {
160+
Future<DartdocResults> generateDocs() async {
161161
Stopwatch _stopwatch = new Stopwatch()..start();
162162
double seconds;
163163
packageGraph = await buildPackageGraph();
@@ -193,15 +193,15 @@ class DartDoc extends PackageBuilder {
193193
"in ${seconds.toStringAsFixed(1)} seconds");
194194

195195
if (packageGraph.publicLibraries.isEmpty) {
196-
throw new DartDocFailure(
196+
throw new DartdocFailure(
197197
"dartdoc could not find any libraries to document. Run `pub get` and try again.");
198198
}
199199

200200
if (packageGraph.packageWarningCounter.errorCount > 0) {
201-
throw new DartDocFailure("dartdoc encountered errors while processing");
201+
throw new DartdocFailure("dartdoc encountered errors while processing");
202202
}
203203

204-
return new DartDocResults(packageMeta, packageGraph, outputDir);
204+
return new DartdocResults(packageMeta, packageGraph, outputDir);
205205
}
206206

207207
/// Warn on file paths.
@@ -421,22 +421,22 @@ class DartDoc extends PackageBuilder {
421421

422422
/// This class is returned if dartdoc fails in an expected way (for instance, if
423423
/// there is an analysis error in the library).
424-
class DartDocFailure {
424+
class DartdocFailure {
425425
final String message;
426426

427-
DartDocFailure(this.message);
427+
DartdocFailure(this.message);
428428

429429
@override
430430
String toString() => message;
431431
}
432432

433-
/// The results of a [DartDoc.generateDocs] call.
434-
class DartDocResults {
433+
/// The results of a [Dartdoc.generateDocs] call.
434+
class DartdocResults {
435435
final PackageMeta packageMeta;
436436
final PackageGraph packageGraph;
437437
final Directory outDir;
438438

439-
DartDocResults(this.packageMeta, this.packageGraph, this.outDir);
439+
DartdocResults(this.packageMeta, this.packageGraph, this.outDir);
440440
}
441441

442442
class _Error implements Comparable<_Error> {

lib/src/config.dart

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
/// Legacy dartdoc configuration library. TODO(jcollins-g): merge with [DartdocOption].
56
library dartdoc.config;
67

78
import 'dart:io';
@@ -25,7 +26,7 @@ String _resolveTildePath(String originalPath) {
2526
return pathLib.join(homeDir, originalPath.substring(2));
2627
}
2728

28-
class DartDocConfig {
29+
class DartdocConfig {
2930
final bool addCrossdart;
3031
final bool autoIncludeDependencies;
3132
final List<String> dropTextFrom;
@@ -50,7 +51,7 @@ class DartDocConfig {
5051
final bool showWarnings;
5152
final bool validateLinks;
5253
final bool verboseWarnings;
53-
DartDocConfig._(
54+
DartdocConfig._(
5455
this.addCrossdart,
5556
this.autoIncludeDependencies,
5657
this.dropTextFrom,
@@ -77,13 +78,13 @@ class DartDocConfig {
7778
this.verboseWarnings,
7879
) {
7980
if (sdkDir == null || !sdkDir.existsSync()) {
80-
throw new DartDocFailure("Error: unable to locate the Dart SDK.");
81+
throw new DartdocFailure("Error: unable to locate the Dart SDK.");
8182
}
8283

8384
footerFilePaths = footerFilePaths.map((p) => _resolveTildePath(p)).toList();
8485
for (String footerFilePath in footerFilePaths) {
8586
if (!new File(footerFilePath).existsSync()) {
86-
throw new DartDocFailure(
87+
throw new DartdocFailure(
8788
"fatal error: unable to locate footer file: ${footerFilePath}.");
8889
}
8990
}
@@ -92,21 +93,21 @@ class DartDocConfig {
9293
footerTextFilePaths.map((p) => _resolveTildePath(p)).toList();
9394
for (String footerTextFilePath in footerTextFilePaths) {
9495
if (!new File(footerTextFilePath).existsSync()) {
95-
throw new DartDocFailure(
96+
throw new DartdocFailure(
9697
"fatal error: unable to locate footer-text file: ${footerTextFilePath}.");
9798
}
9899
}
99100

100101
headerFilePaths = headerFilePaths.map((p) => _resolveTildePath(p)).toList();
101102
for (String headerFilePath in headerFilePaths) {
102103
if (!new File(headerFilePath).existsSync()) {
103-
throw new DartDocFailure(
104+
throw new DartdocFailure(
104105
"fatal error: unable to locate header file: ${headerFilePath}.");
105106
}
106107
}
107108
}
108109

109-
factory DartDocConfig.fromParameters({
110+
factory DartdocConfig.fromParameters({
110111
bool addCrossdart: false,
111112
bool autoIncludeDependencies: false,
112113
List<String> dropTextFrom,
@@ -132,7 +133,7 @@ class DartDocConfig {
132133
bool validateLinks: true,
133134
bool verboseWarnings: true,
134135
}) {
135-
return new DartDocConfig._(
136+
return new DartdocConfig._(
136137
addCrossdart,
137138
autoIncludeDependencies,
138139
dropTextFrom ?? const <String>[],

0 commit comments

Comments
 (0)