findFilesToDocumentInPackage method

Stream<String> findFilesToDocumentInPackage(
  1. String basePackageDir,
  2. {@required bool autoIncludeDependencies,
  3. bool filterExcludes = true}
)

Given a package name, explore the directory and pull out all top level library files in the "lib" directory to document.

Implementation

Stream<String> findFilesToDocumentInPackage(String basePackageDir,
    {@required bool autoIncludeDependencies,
    bool filterExcludes = true}) async* {
  var packageDirs = {basePackageDir};

  if (autoIncludeDependencies) {
    var info = await packageConfigProvider
        .findPackageConfig(resourceProvider.getFolder(basePackageDir));
    for (var package in info.packages) {
      if (!filterExcludes || !config.exclude.contains(package.name)) {
        packageDirs.add(_pathContext.dirname(
            _pathContext.fromUri(info[package.name].packageUriRoot)));
      }
    }
  }

  var sep = _pathContext.separator;
  for (var packageDir in packageDirs) {
    var packageLibDir = _pathContext.join(packageDir, 'lib');
    var packageLibSrcDir = _pathContext.join(packageLibDir, 'src');
    // To avoid analyzing package files twice, only files with paths not
    // containing '/packages' will be added. The only exception is if the file
    // to analyze already has a '/package' in its path.
    for (var lib
        in _listDir(packageDir, recursive: true, listDir: _packageDirList)) {
      if (lib.endsWith('.dart') &&
          (!lib.contains('${sep}packages$sep') ||
              packageDir.contains('${sep}packages$sep'))) {
        // Only include libraries within the lib dir that are not in 'lib/src'.
        if (_pathContext.isWithin(packageLibDir, lib) &&
            !_pathContext.isWithin(packageLibSrcDir, lib)) {
          // Only add the file if it does not contain 'part of'.
          var contents = resourceProvider.getFile(lib).readAsStringSync();

          if (contents.startsWith('part of ') ||
              contents.contains('\npart of ')) {
            // NOOP: it's a part file.
          } else {
            yield lib;
          }
        }
      }
    }
  }
}