Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add include/exclude to supported config options #1700

Merged
merged 5 commits into from
May 29, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ Unrecognized options will be ignored. Supported options:

* **categoryOrder**: Specify the order of categories, below, for display in the sidebar and
the package page.
* **include**: Specify a list of library names to generate docs for, ignoring all others.
* **exclude**: Specify a list of library names to avoid generating docs for,
overriding any specified in include.
* **linkTo**: For other packages depending on this one, if this map is defined those packages
will use the settings here to control how hyperlinks to the package are generated.
This will override the default for packages hosted on pub.dartlang.org.
Expand All @@ -133,12 +136,10 @@ as POSIX paths. Dartdoc will convert POSIX paths automatically on Windows.
* **ambiguousReexportScorerMinConfidence**: The ambiguous reexport scorer will emit a warning if
it is not at least this confident. Default: 0.1
* **examplePathPrefix**: Specify the prefix for the example paths, defaulting to the project root.
* **exclude**: Specify a list of library names to avoid generating docs for, ignoring all others.
* **favicon**: A path to a favicon for the generated docs.
* **footer**: A list of paths to footer files containing HTML text.
* **footerText**: A list of paths to text files for optional text next to the package name and version
* **header**: A list of paths to header files containing HTML text.
* **include**: Specify a list of library names to generate docs for, ignoring all others.
* **includeExternal**: Specify a list of library filenames to add to the list of documented libraries.

### Categories
Expand Down
5 changes: 2 additions & 3 deletions bin/dartdoc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ main(List<String> arguments) async {
createGeneratorOptions,
]);

DartdocProgramOptionContext config =
new DartdocProgramOptionContext(optionSet, Directory.current);

try {
optionSet.parseArguments(arguments);
} on FormatException catch (e) {
Expand All @@ -63,6 +60,8 @@ main(List<String> arguments) async {
_printVersionAndExit(optionSet.argParser);
}

DartdocProgramOptionContext config =
new DartdocProgramOptionContext(optionSet, null);
startLogging(config);

Directory outputDir = new Directory(config.output);
Expand Down
12 changes: 10 additions & 2 deletions lib/src/dartdoc_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -883,9 +883,17 @@ class DartdocOptionContext {
// TODO(jcollins-g): Allow passing in structured data to initialize a
// [DartdocOptionContext]'s arguments instead of having to parse strings
// via optionSet.
/// If [entity] is null, assume this is the initialization case and use
/// the inputDir flag to determine the context.
DartdocOptionContext(this.optionSet, FileSystemEntity entity) {
context = new Directory(pathLib
.canonicalize(entity is File ? entity.parent.path : entity.path));
if (entity == null) {
String inputDir = optionSet['inputDir'].valueAt(Directory.current) ??
Directory.current.path;
context = new Directory(inputDir);
} else {
context = new Directory(pathLib
.canonicalize(entity is File ? entity.parent.path : entity.path));
}
}

/// Build a DartdocOptionContext from an analyzer element (using its source
Expand Down
3 changes: 2 additions & 1 deletion lib/src/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5763,7 +5763,8 @@ class PackageBuilder {
if (config.include.isNotEmpty) {
Iterable knownLibraryNames = libraries.map((l) => l.name);
Set notFound = new Set.from(config.include)
.difference(new Set.from(knownLibraryNames));
.difference(new Set.from(knownLibraryNames))
.difference(new Set.from(config.exclude));
if (notFound.isNotEmpty) {
throw 'Did not find: [${notFound.join(', ')}] in '
'known libraries: [${knownLibraryNames.join(', ')}]';
Expand Down
75 changes: 45 additions & 30 deletions test/dartdoc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'dart:io';

import 'package:dartdoc/dartdoc.dart';
import 'package:dartdoc/src/model.dart';
import 'package:dartdoc/src/package_meta.dart';
import 'package:path/path.dart' as pathLib;
import 'package:test/test.dart';

Expand All @@ -28,24 +27,51 @@ void main() {
delete(tempDir);
});

Future<DartdocGeneratorOptionContext> generatorContextFromArgvTemp(
List<String> argv) async {
return await generatorContextFromArgv(argv..addAll(outputParam));
Future<Dartdoc> buildDartdoc(
List<String> argv, Directory packageRoot) async {
return await Dartdoc.withDefaultGenerators(await generatorContextFromArgv(
argv..addAll(['--input', packageRoot.path])..addAll(outputParam)));
}

group('include/exclude parameters', () {
test('with config file', () async {
Dartdoc dartdoc = await buildDartdoc([], testPackageImportExport);
DartdocResults results = await dartdoc.generateDocs();
PackageGraph p = results.packageGraph;
expect(p.localPublicLibraries.map((l) => l.name),
orderedEquals(['explicitly_included', 'more_included']));
});

test('with include command line argument', () async {
Dartdoc dartdoc = await buildDartdoc(
['--include', 'another_included'], testPackageImportExport);
DartdocResults results = await dartdoc.generateDocs();
PackageGraph p = results.packageGraph;
expect(p.localPublicLibraries.length, equals(1));
expect(p.localPublicLibraries.first.name, equals('another_included'));
});

test('with exclude command line argument', () async {
Dartdoc dartdoc = await buildDartdoc(
['--exclude', 'more_included'], testPackageImportExport);
DartdocResults results = await dartdoc.generateDocs();
PackageGraph p = results.packageGraph;
expect(p.localPublicLibraries.length, equals(1));
expect(
p.localPublicLibraries.first.name, equals('explicitly_included'));
});
});

test('package without version produces valid semver in docs', () async {
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(
await generatorContextFromArgvTemp(
['--input', testPackageMinimumDir.path]));
Dartdoc dartdoc = await buildDartdoc([], testPackageMinimumDir);
DartdocResults results = await dartdoc.generateDocs();
PackageGraph p = results.packageGraph;
assert(p.version == '0.0.0-unknown');
expect(p.version, equals('0.0.0-unknown'));
});

test('basic interlinking test', () async {
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(
await generatorContextFromArgvTemp(
['--input', testPackageDir.path, '--link-to-remote']));
Dartdoc dartdoc =
await buildDartdoc(['--link-to-remote'], testPackageDir);
DartdocResults results = await dartdoc.generateDocs();
PackageGraph p = results.packageGraph;
Package tuple = p.publicPackages.firstWhere((p) => p.name == 'tuple');
Expand Down Expand Up @@ -73,8 +99,7 @@ void main() {

test('generate docs for ${pathLib.basename(testPackageDir.path)} works',
() async {
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(
await generatorContextFromArgvTemp(['--input', testPackageDir.path]));
Dartdoc dartdoc = await buildDartdoc([], testPackageDir);

DartdocResults results = await dartdoc.generateDocs();
expect(results.packageGraph, isNotNull);
Expand All @@ -88,9 +113,7 @@ void main() {

test('generate docs for ${pathLib.basename(testPackageBadDir.path)} fails',
() async {
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(
await generatorContextFromArgvTemp(
['--input', testPackageBadDir.path]));
Dartdoc dartdoc = await buildDartdoc([], testPackageBadDir);

try {
await dartdoc.generateDocs();
Expand All @@ -101,9 +124,7 @@ void main() {
});

test('generate docs for a package that does not have a readme', () async {
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(
await generatorContextFromArgvTemp(
['--input', testPackageWithNoReadme.path]));
Dartdoc dartdoc = await buildDartdoc([], testPackageWithNoReadme);

DartdocResults results = await dartdoc.generateDocs();
expect(results.packageGraph, isNotNull);
Expand All @@ -116,9 +137,8 @@ void main() {
});

test('generate docs including a single library', () async {
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(
await generatorContextFromArgvTemp(
['--input', testPackageDir.path, '--include', 'fake']));
Dartdoc dartdoc =
await buildDartdoc(['--include', 'fake'], testPackageDir);

DartdocResults results = await dartdoc.generateDocs();
expect(results.packageGraph, isNotNull);
Expand All @@ -131,9 +151,8 @@ void main() {
});

test('generate docs excluding a single library', () async {
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(
await generatorContextFromArgvTemp(
['--input', testPackageDir.path, '--exclude', 'fake']));
Dartdoc dartdoc =
await buildDartdoc(['--exclude', 'fake'], testPackageDir);

DartdocResults results = await dartdoc.generateDocs();
expect(results.packageGraph, isNotNull);
Expand All @@ -147,11 +166,7 @@ void main() {
});

test('generate docs for package with embedder yaml', () async {
PackageMeta meta = new PackageMeta.fromDir(testPackageWithEmbedderYaml);
if (meta.needsPubGet) meta.runPubGet();
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(
await generatorContextFromArgvTemp(
['--input', testPackageWithEmbedderYaml.path]));
Dartdoc dartdoc = await buildDartdoc([], testPackageWithEmbedderYaml);

DartdocResults results = await dartdoc.generateDocs();
expect(results.packageGraph, isNotNull);
Expand Down
7 changes: 5 additions & 2 deletions test/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@ final Directory testPackageWithEmbedderYaml =
new Directory('testing/test_package_embedder_yaml');
final Directory testPackageWithNoReadme =
new Directory('testing/test_package_small');
final Directory testPackageImportExport =
new Directory('testing/test_package_include_exclude');

/// Convenience factory to build a [DartdocGeneratorOptionContext] and associate
/// it with a [DartdocOptionSet] based on the current working directory.
/// it with a [DartdocOptionSet] based on the current working directory and/or
/// the '--input' flag.
Future<DartdocGeneratorOptionContext> generatorContextFromArgv(
List<String> argv) async {
DartdocOptionSet optionSet = await DartdocOptionSet.fromOptionGenerators(
'dartdoc', [createDartdocOptions, createGeneratorOptions]);
optionSet.parseArguments(argv);
return new DartdocGeneratorOptionContext(optionSet, Directory.current);
return new DartdocGeneratorOptionContext(optionSet, null);
}

/// Convenience factory to build a [DartdocOptionContext] and associate it with a
Expand Down
4 changes: 4 additions & 0 deletions testing/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*/doc/api/
*/ios
*/pubspec.lock
*/.packages
2 changes: 0 additions & 2 deletions testing/test_package/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion testing/test_package_bad/.gitignore

This file was deleted.

3 changes: 0 additions & 3 deletions testing/test_package_flutter_plugin/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion testing/test_package_imported/.gitignore

This file was deleted.

6 changes: 6 additions & 0 deletions testing/test_package_include_exclude/bin/included.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/// This is a libraryish thing in the wrong place.
library included;

void main() {
print('hello, world');
}
5 changes: 5 additions & 0 deletions testing/test_package_include_exclude/bin/not_included.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
library not_included;

void main() {
print('another binary not included');
}
3 changes: 3 additions & 0 deletions testing/test_package_include_exclude/dartdoc_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dartdoc:
include: ['explicitly_included', 'more_included']
exclude: ['excluded']
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
library another_included;
1 change: 1 addition & 0 deletions testing/test_package_include_exclude/lib/excluded.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
library excluded;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
library explicitly_included;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
library more_included;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
library not_explicitly_included;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
library included_under_src;
2 changes: 2 additions & 0 deletions testing/test_package_include_exclude/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name: test_package_include_exclude
version: 0.0.1
2 changes: 0 additions & 2 deletions testing/test_package_minimum/.gitignore

This file was deleted.