@@ -10,8 +10,9 @@ library dartdoc;
10
10
11
11
import 'dart:async' ;
12
12
import 'dart:convert' ;
13
- import 'dart:io' ;
13
+ import 'dart:io' show exitCode, stderr ;
14
14
15
+ import 'package:analyzer/file_system/file_system.dart' ;
15
16
import 'package:dartdoc/src/dartdoc_options.dart' ;
16
17
import 'package:dartdoc/src/generator/empty_generator.dart' ;
17
18
import 'package:dartdoc/src/generator/generator.dart' ;
@@ -41,17 +42,19 @@ const String dartdocVersion = packageVersion;
41
42
/// Helper class that consolidates option contexts for instantiating generators.
42
43
class DartdocGeneratorOptionContext extends DartdocOptionContext
43
44
with GeneratorContext {
44
- DartdocGeneratorOptionContext (DartdocOptionSet optionSet, Directory dir)
45
- : super (optionSet, dir);
45
+ DartdocGeneratorOptionContext (
46
+ DartdocOptionSet optionSet, Folder dir, ResourceProvider resourceProvider)
47
+ : super (optionSet, dir, resourceProvider);
46
48
}
47
49
48
50
class DartdocFileWriter implements FileWriter {
49
51
final String outputDir;
52
+ ResourceProvider resourceProvider;
50
53
final Map <String , Warnable > _fileElementMap = {};
51
54
@override
52
55
final Set <String > writtenFiles = {};
53
56
54
- DartdocFileWriter (this .outputDir);
57
+ DartdocFileWriter (this .outputDir, this .resourceProvider );
55
58
56
59
@override
57
60
void write (String filePath, Object content,
@@ -73,10 +76,11 @@ class DartdocFileWriter implements FileWriter {
73
76
}
74
77
_fileElementMap[outFile] = element;
75
78
76
- var file = File (path.join (outputDir, outFile));
79
+ var file = resourceProvider
80
+ .getFile (resourceProvider.pathContext.join (outputDir, outFile));
77
81
var parent = file.parent;
78
- if (! parent.existsSync () ) {
79
- parent.createSync (recursive : true );
82
+ if (! parent.exists ) {
83
+ parent.create ( );
80
84
}
81
85
82
86
if (content is String ) {
@@ -100,14 +104,16 @@ class Dartdoc {
100
104
final PackageBuilder packageBuilder;
101
105
final DartdocOptionContext config;
102
106
final Set <String > writtenFiles = {};
103
- Directory outputDir;
107
+ Folder outputDir;
104
108
105
109
// Fires when the self checks make progress.
106
110
final StreamController <String > _onCheckProgress =
107
111
StreamController (sync : true );
108
112
109
113
Dartdoc ._(this .config, this .generator, this .packageBuilder) {
110
- outputDir = Directory (config.output)..createSync (recursive: true );
114
+ outputDir = config.resourceProvider
115
+ .getFolder (config.resourceProvider.pathContext.absolute (config.output))
116
+ ..create ();
111
117
}
112
118
113
119
/// An asynchronous factory method that builds Dartdoc's file writers
@@ -182,9 +188,9 @@ class Dartdoc {
182
188
final generator = this .generator;
183
189
if (generator != null ) {
184
190
// Create the out directory.
185
- if (! outputDir.existsSync ()) outputDir.createSync (recursive : true );
191
+ if (! outputDir.exists) outputDir.create ( );
186
192
187
- var writer = DartdocFileWriter (outputDir.path);
193
+ var writer = DartdocFileWriter (outputDir.path, config.resourceProvider );
188
194
await generator.generate (packageGraph, writer);
189
195
190
196
writtenFiles.addAll (writer.writtenFiles);
@@ -225,15 +231,16 @@ class Dartdoc {
225
231
throw DartdocFailure (
226
232
'dartdoc encountered $errorCount errors while processing.' );
227
233
}
228
- logInfo (
229
- 'Success! Docs generated into ${dartdocResults .outDir .absolute .path }' );
234
+ var outDirPath = config.resourceProvider.pathContext
235
+ .absolute (dartdocResults.outDir.path);
236
+ logInfo ('Success! Docs generated into $outDirPath ' );
230
237
return dartdocResults;
231
238
} finally {
232
239
// Clear out any cached tool snapshots and temporary directories.
233
240
// ignore: unawaited_futures
234
- SnapshotCache .instance.dispose ();
241
+ SnapshotCache .instance? .dispose ();
235
242
// ignore: unawaited_futures
236
- ToolTempFileTracker .instance.dispose ();
243
+ ToolTempFileTracker .instance? .dispose ();
237
244
}
238
245
}
239
246
@@ -289,35 +296,43 @@ class Dartdoc {
289
296
var staticAssets = path.joinAll ([normalOrigin, 'static-assets' , '' ]);
290
297
var indexJson = path.joinAll ([normalOrigin, 'index.json' ]);
291
298
var foundIndexJson = false ;
292
- for (var f in Directory (normalOrigin).listSync (recursive: true )) {
293
- if (f is Directory ) {
294
- continue ;
295
- }
296
- var fullPath = path.normalize (f.path);
297
- if (fullPath.startsWith (staticAssets)) {
298
- continue ;
299
- }
300
- if (fullPath == indexJson) {
301
- foundIndexJson = true ;
302
- _onCheckProgress.add (fullPath);
303
- continue ;
304
- }
305
- if (visited.contains (fullPath)) continue ;
306
- var relativeFullPath = path.relative (fullPath, from: normalOrigin);
307
- if (! writtenFiles.contains (relativeFullPath)) {
308
- // This isn't a file we wrote (this time); don't claim we did.
309
- _warn (packageGraph, PackageWarning .unknownFile, fullPath, normalOrigin);
310
- } else {
311
- // Error messages are orphaned by design and do not appear in the search
312
- // index.
313
- if (< String > ['__404error.html' , 'categories.json' ].contains (fullPath)) {
314
- _warn (packageGraph, PackageWarning .orphanedFile, fullPath,
315
- normalOrigin);
299
+
300
+ void checkDirectory (Folder dir) {
301
+ for (var f in dir.getChildren ()) {
302
+ if (f is Folder ) {
303
+ checkDirectory (f);
304
+ continue ;
305
+ }
306
+ var fullPath = path.normalize (f.path);
307
+ if (fullPath.startsWith (staticAssets)) {
308
+ continue ;
316
309
}
310
+ if (path.equals (fullPath, indexJson)) {
311
+ foundIndexJson = true ;
312
+ _onCheckProgress.add (fullPath);
313
+ continue ;
314
+ }
315
+ if (visited.contains (fullPath)) continue ;
316
+ var relativeFullPath = path.relative (fullPath, from: normalOrigin);
317
+ if (! writtenFiles.contains (relativeFullPath)) {
318
+ // This isn't a file we wrote (this time); don't claim we did.
319
+ _warn (
320
+ packageGraph, PackageWarning .unknownFile, fullPath, normalOrigin);
321
+ } else {
322
+ // Error messages are orphaned by design and do not appear in the search
323
+ // index.
324
+ if (< String > ['__404error.html' , 'categories.json' ]
325
+ .contains (fullPath)) {
326
+ _warn (packageGraph, PackageWarning .orphanedFile, fullPath,
327
+ normalOrigin);
328
+ }
329
+ }
330
+ _onCheckProgress.add (fullPath);
317
331
}
318
- _onCheckProgress.add (fullPath);
319
332
}
320
333
334
+ checkDirectory (config.resourceProvider.getFolder (normalOrigin));
335
+
321
336
if (! foundIndexJson) {
322
337
_warn (packageGraph, PackageWarning .brokenLink, indexJson, normalOrigin);
323
338
_onCheckProgress.add (indexJson);
@@ -327,8 +342,8 @@ class Dartdoc {
327
342
// This is extracted to save memory during the check; be careful not to hang
328
343
// on to anything referencing the full file and doc tree.
329
344
Tuple2 <Iterable <String >, String > _getStringLinksAndHref (String fullPath) {
330
- var file = File ('$fullPath ' );
331
- if (! file.existsSync () ) {
345
+ var file = config.resourceProvider. getFile ('$fullPath ' );
346
+ if (! file.exists ) {
332
347
return null ;
333
348
}
334
349
// TODO(srawlins): It is possible that instantiating an HtmlParser using
@@ -353,8 +368,8 @@ class Dartdoc {
353
368
PackageGraph packageGraph, String origin, Set <String > visited) {
354
369
var fullPath = path.joinAll ([origin, 'index.json' ]);
355
370
var indexPath = path.joinAll ([origin, 'index.html' ]);
356
- var file = File ('$fullPath ' );
357
- if (! file.existsSync () ) {
371
+ var file = config.resourceProvider. getFile ('$fullPath ' );
372
+ if (! file.exists ) {
358
373
return null ;
359
374
}
360
375
var decoder = JsonDecoder ();
@@ -519,7 +534,7 @@ class DartdocFailure {
519
534
class DartdocResults {
520
535
final PackageMeta packageMeta;
521
536
final PackageGraph packageGraph;
522
- final Directory outDir;
537
+ final Folder outDir;
523
538
524
539
DartdocResults (this .packageMeta, this .packageGraph, this .outDir);
525
540
}
0 commit comments