diff --git a/.github/workflows/dcdg-ci.yml b/.github/workflows/dcdg-ci.yml new file mode 100644 index 0000000..2c8d127 --- /dev/null +++ b/.github/workflows/dcdg-ci.yml @@ -0,0 +1,24 @@ +name: DCDG CI + +on: [push, pull_request] + +jobs: + check: + runs-on: ubuntu-20.04 + container: + image: glesica/dcdg_build + volumes: + - ${{ github.workspace }}:/code + steps: + - uses: actions/checkout@v1 + - run: ./tool/check.sh + + check-format: + runs-on: ubuntu-20.04 + container: + image: glesica/dcdg_build + volumes: + - ${{ github.workspace }}:/code + steps: + - uses: actions/checkout@v1 + - run: ./tool/format.sh diff --git a/.travis.yml b/.travis.yml index ef1db65..260fb4d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: dart dart: - - 2.2.0 + - 2.12.0 - stable - dev script: diff --git a/Dockerfile_build b/Dockerfile_build new file mode 100644 index 0000000..5079555 --- /dev/null +++ b/Dockerfile_build @@ -0,0 +1,7 @@ +FROM google/dart:2.12 AS build +RUN apt-get -q update && \ + apt-get -y install make && \ + rm -rf /var/lib/apt/lists/* && \ + mkdir -p /code +VOLUME /code +WORKDIR /code diff --git a/USAGE.txt b/USAGE.txt index 8fdb967..1df8755 100644 --- a/USAGE.txt +++ b/USAGE.txt @@ -2,41 +2,32 @@ Usage: dcdg [options] -b, --builder= Builder to use to construct a class diagram (defaults to "plantuml") - -e, --exclude= Class / type names to exclude, can be a regular expression - --exclude-private= Exclude private entities (field, method, class, or all) - --exclude-has-a Exclude has-a / aggregation relationships from the diagram output - --exclude-is-a Exclude is-a / extension relationships from the diagram output - --exported-only Include only classes exported from the Dart package - --has-a= Include only classes with a has-a relationship to any of the named classes - --is-a= Include only classes with an is-a relationship to any of the named classes - -h, --help Show usage information -i, --include= Class / type names to include, can be a regular expression - -o, --output= File to which output should be written (stdout if omitted) (defaults to "") - -p, --package= Path to the root of the Dart package to scan (defaults to ".") - -s, --search-path= Directory relative to the package root to search for classes + (defaults to "lib") +-v, --version Show the version number and exit Available builders: * plantuml - PlantUML builder that attempts to be feature-complete diff --git a/bin/dcdg.dart b/bin/dcdg.dart index 38683ab..253e58f 100644 --- a/bin/dcdg.dart +++ b/bin/dcdg.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'dart:io'; import 'package:dcdg/dcdg.dart'; +import 'package:dcdg/src/command_line.dart'; import 'package:path/path.dart' as path; Future main(Iterable arguments) async { @@ -12,16 +13,22 @@ Future main(Iterable arguments) async { exit(0); } + if (config.shouldShowVersion) { + print(makeVersion()); + exit(0); + } + // TODO: Move validation to the Configuration itself for easier testing if (config.builder == null) { outputError('Builder "${config.builderName}" was not found'); exit(1); } + final builder = config.builder!; final pubspec = File(path.join(config.packagePath, 'pubspec.yaml')); if (!pubspec.existsSync()) { - outputError('No Dart package found at ${config.packagePath}'); + outputError('No Dart package found at "${config.packagePath}"'); exit(1); } @@ -32,7 +39,7 @@ Future main(Iterable arguments) async { ); buildDiagram( - builder: config.builder, + builder: builder, classElements: classes, excludeHasA: config.excludeHasA, excludeIsA: config.excludeIsA, @@ -46,11 +53,11 @@ Future main(Iterable arguments) async { ); if (config.outputPath == '') { - config.builder.printContent(print); + builder.printContent(print); } else { final outFile = File(config.outputPath); try { - config.builder.writeContent(outFile); + builder.writeContent(outFile); } on FileSystemException catch (exception) { outputError( 'Failed writing to file ${exception.path} (${exception.osError})', @@ -61,7 +68,7 @@ Future main(Iterable arguments) async { } } -void outputError(String message, [Exception exception]) { +void outputError(String message, [Exception? exception]) { stderr.writeln('Error: $message'); if (exception != null) { stderr.writeln(exception.toString()); diff --git a/example/dcdg.png b/example/dcdg.png index 3235ef1..d90e472 100644 Binary files a/example/dcdg.png and b/example/dcdg.png differ diff --git a/example/dcdg.puml b/example/dcdg.puml index ebbbf9b..bbbdea5 100644 --- a/example/dcdg.puml +++ b/example/dcdg.puml @@ -1,23 +1,7 @@ @startuml set namespaceSeparator :: -class "dcdg::src::diagram_visitor.dart::DiagramVisitor" { - +bool hasA() - +bool isA() - +bool shouldInclude() - +bool shouldIncludeClass() - +bool shouldIncludeField() - +bool shouldIncludeHasA() - +bool shouldIncludeIsA() - +bool shouldIncludeMethod() - +void visitClassElement() - +void visitFieldElement() - +void visitMethodElement() -} - -"analyzer::dart::element::visitor.dart::RecursiveElementVisitor" <|-- "dcdg::src::diagram_visitor.dart::DiagramVisitor" - -class "dcdg::src::builders::dot_builder.dart::DotBuilder" { +class "dcdg::src::builders::plant_uml_builder.dart::PlantUmlBuilder" { +void addAggregation() +void addField() +void addInterface() @@ -27,13 +11,14 @@ class "dcdg::src::builders::dot_builder.dart::DotBuilder" { +void beginClass() +void endClass() +String namespacedTypeName() + +String getVisibility() +void printContent() +void writeContent() } -"dcdg::src::builders::diagram_builder.dart::DiagramBuilder" <|-- "dcdg::src::builders::dot_builder.dart::DotBuilder" +"dcdg::src::builders::diagram_builder.dart::DiagramBuilder" <|-- "dcdg::src::builders::plant_uml_builder.dart::PlantUmlBuilder" -class "dcdg::src::builders::plant_uml_builder.dart::PlantUmlBuilder" { +class "dcdg::src::builders::dot_builder.dart::DotBuilder" { +void addAggregation() +void addField() +void addInterface() @@ -43,12 +28,11 @@ class "dcdg::src::builders::plant_uml_builder.dart::PlantUmlBuilder" { +void beginClass() +void endClass() +String namespacedTypeName() - +String getVisibility() +void printContent() +void writeContent() } -"dcdg::src::builders::diagram_builder.dart::DiagramBuilder" <|-- "dcdg::src::builders::plant_uml_builder.dart::PlantUmlBuilder" +"dcdg::src::builders::diagram_builder.dart::DiagramBuilder" <|-- "dcdg::src::builders::dot_builder.dart::DotBuilder" abstract class "dcdg::src::builders::diagram_builder.dart::DiagramBuilder" { +void addAggregation() @@ -82,8 +66,17 @@ class "dcdg::src::builders::nomnoml_builder.dart::NomnomlBuilder" { "dcdg::src::builders::diagram_builder.dart::DiagramBuilder" <|-- "dcdg::src::builders::nomnoml_builder.dart::NomnomlBuilder" +class "dcdg::src::builder_factories.dart::BuilderFactory" { + +DiagramBuilder Function() callback + +String description + +String name + +String toString() +} + +"dcdg::src::builder_factories.dart::BuilderFactory" o-- "dcdg::src::builder_factories.dart::DiagramBuilder Function()" + abstract class "dcdg::src::configuration.dart::Configuration" { - +DiagramBuilder builder + +DiagramBuilder? builder +String builderName +Iterable excludeExpressions +bool excludeHasA @@ -101,10 +94,10 @@ abstract class "dcdg::src::configuration.dart::Configuration" { +bool shouldShowHelp } -"dcdg::src::configuration.dart::Configuration" o-- "dcdg::src::builders::diagram_builder.dart::DiagramBuilder" +"dcdg::src::configuration.dart::Configuration" o-- "dcdg::src::builders::diagram_builder.dart::DiagramBuilder?" class "dcdg::src::configuration.dart::ConfigurationImpl" { - +DiagramBuilder builder + +DiagramBuilder? builder +String builderName +Iterable excludeExpressions +bool excludeHasA @@ -122,17 +115,24 @@ class "dcdg::src::configuration.dart::ConfigurationImpl" { +bool shouldShowHelp } -"dcdg::src::configuration.dart::ConfigurationImpl" o-- "dcdg::src::builders::diagram_builder.dart::DiagramBuilder" +"dcdg::src::configuration.dart::ConfigurationImpl" o-- "dcdg::src::builders::diagram_builder.dart::DiagramBuilder?" "dcdg::src::configuration.dart::Configuration" <|-- "dcdg::src::configuration.dart::ConfigurationImpl" -class "dcdg::src::builder_factories.dart::BuilderFactory" { - +() → DiagramBuilder callback - +String description - +String name - +String toString() +class "dcdg::src::diagram_visitor.dart::DiagramVisitor" { + +bool hasA() + +bool isA() + +bool shouldInclude() + +bool shouldIncludeClass() + +bool shouldIncludeField() + +bool shouldIncludeHasA() + +bool shouldIncludeIsA() + +bool shouldIncludeMethod() + +void visitClassElement() + +void visitFieldElement() + +void visitMethodElement() } -"dcdg::src::builder_factories.dart::BuilderFactory" o-- "dcdg::src::builder_factories.dart::() → DiagramBuilder" +"analyzer::dart::element::visitor.dart::RecursiveElementVisitor" <|-- "dcdg::src::diagram_visitor.dart::DiagramVisitor" class "dcdg::src::class_element_collector.dart::ClassElementCollector" { +Iterable classElements @@ -140,7 +140,7 @@ class "dcdg::src::class_element_collector.dart::ClassElementCollector" { +void visitExportElement() } -"analyzer::dart::element::visitor.dart::RecursiveElementVisitor" <|-- "dcdg::src::class_element_collector.dart::ClassElementCollector" +"analyzer::dart::element::visitor.dart::RecursiveElementVisitor" <|-- "dcdg::src::class_element_collector.dart::ClassElementCollector" @enduml \ No newline at end of file diff --git a/lib/src/build_diagram.dart b/lib/src/build_diagram.dart index 2c6028b..228ee15 100644 --- a/lib/src/build_diagram.dart +++ b/lib/src/build_diagram.dart @@ -1,22 +1,21 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:dcdg/src/builders/diagram_builder.dart'; import 'package:dcdg/src/diagram_visitor.dart'; -import 'package:meta/meta.dart'; /// Build a diagram using the given builder from the given class /// elements. void buildDiagram({ - @required DiagramBuilder builder, - @required Iterable classElements, - bool excludeHasA, - bool excludeIsA, - bool excludePrivateClasses, - bool excludePrivateFields, - bool excludePrivateMethods, - Iterable excludes, - Iterable hasA, - Iterable includes, - Iterable isA, + required DiagramBuilder builder, + required Iterable classElements, + required bool excludeHasA, + required bool excludeIsA, + required bool excludePrivateClasses, + required bool excludePrivateFields, + required bool excludePrivateMethods, + required Iterable excludes, + required Iterable hasA, + required Iterable includes, + required Iterable isA, }) { final visitor = DiagramVisitor( onAggregateField: builder.addAggregation, diff --git a/lib/src/builder_factories.dart b/lib/src/builder_factories.dart index e20f689..408d9c5 100644 --- a/lib/src/builder_factories.dart +++ b/lib/src/builder_factories.dart @@ -2,7 +2,6 @@ import 'package:dcdg/src/builders/dot_builder.dart'; import 'package:dcdg/src/builders/nomnoml_builder.dart'; import 'package:dcdg/src/builders/plant_uml_builder.dart'; import 'package:dcdg/src/builders/diagram_builder.dart'; -import 'package:meta/meta.dart'; /// A collection of available builders parameterized in different ways /// for different use-cases. @@ -37,9 +36,9 @@ class BuilderFactory { final String name; BuilderFactory({ - @required this.callback, - @required this.description, - @required this.name, + required this.callback, + required this.description, + required this.name, }); @override @@ -48,4 +47,7 @@ class BuilderFactory { Iterable availableBuilders() => _factories.values; -DiagramBuilder getBuilder(String name) => _factories[name]?.callback(); +DiagramBuilder? getBuilder(String name) { + final factory = _factories[name]; + return factory?.callback(); +} diff --git a/lib/src/builders/diagram_builder.dart b/lib/src/builders/diagram_builder.dart index 5af0637..adfc912 100644 --- a/lib/src/builders/diagram_builder.dart +++ b/lib/src/builders/diagram_builder.dart @@ -20,7 +20,7 @@ abstract class DiagramBuilder { void endClass(ClassElement element); - void printContent(void printer(String content)); + void printContent(void Function(String content) printer); void writeContent(File file); } diff --git a/lib/src/builders/dot_builder.dart b/lib/src/builders/dot_builder.dart index ce5a2ae..7004955 100644 --- a/lib/src/builders/dot_builder.dart +++ b/lib/src/builders/dot_builder.dart @@ -5,7 +5,7 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:dcdg/src/builders/diagram_builder.dart'; class DotBuilder implements DiagramBuilder { - String _currentClass; + String? _currentClass; final List _lines = [ 'strict digraph {', @@ -59,7 +59,7 @@ class DotBuilder implements DiagramBuilder { } String namespacedTypeName(Element element) { - final namespace = element.library.identifier + final namespace = element.library?.identifier .replaceFirst('package:', '') .replaceFirst('dart:', ''); final className = element.name; @@ -68,11 +68,7 @@ class DotBuilder implements DiagramBuilder { @override void printContent(void Function(String content) printer) { - final content = ([] - ..addAll(_lines) - ..add('') - ..add('}')) - .join('\n'); + final content = ([..._lines, '', '}']).join('\n'); printer(content); } diff --git a/lib/src/builders/nomnoml_builder.dart b/lib/src/builders/nomnoml_builder.dart index c5969e0..be3a914 100644 --- a/lib/src/builders/nomnoml_builder.dart +++ b/lib/src/builders/nomnoml_builder.dart @@ -6,15 +6,15 @@ import 'package:dcdg/dcdg.dart'; import 'package:dcdg/src/builders/type_name.dart'; class NomnomlBuilder implements DiagramBuilder { - String _currentClass; + String? _currentClass; - List _lines = []; + final List _lines = []; - List _fields = []; + final List _fields = []; - List _methods = []; + final List _methods = []; - Set _relationships = {}; + final Set _relationships = {}; @override void addAggregation(FieldElement element) { @@ -106,7 +106,8 @@ class NomnomlBuilder implements DiagramBuilder { final visibilityPrefix = getVisibility(element); final staticPrefix = element.isStatic ? '' : ''; final methodName = element.name; - final methodType = element.returnType.name; + final methodType = + element.returnType.getDisplayString(withNullability: true); return ' $staticPrefix$visibilityPrefix$methodType $methodName()'; }).join(';\n')); } @@ -118,12 +119,16 @@ class NomnomlBuilder implements DiagramBuilder { } String getVisibility(Element element) { - return element.isPrivate ? '-' : element.hasProtected ? '#' : '+'; + return element.isPrivate + ? '-' + : element.hasProtected + ? '#' + : '+'; } @override void printContent(void Function(String content) printer) { - final content = ([]..addAll(_lines)).join('\n'); + final content = ([..._lines]).join('\n'); printer(content); } diff --git a/lib/src/builders/plant_uml_builder.dart b/lib/src/builders/plant_uml_builder.dart index ac0337c..6f221b5 100644 --- a/lib/src/builders/plant_uml_builder.dart +++ b/lib/src/builders/plant_uml_builder.dart @@ -8,7 +8,7 @@ import 'package:dcdg/src/constants.dart'; import 'package:dcdg/src/builders/diagram_builder.dart'; class PlantUmlBuilder implements DiagramBuilder { - String _currentClass; + String? _currentClass; final List _lines = [ '@startuml', @@ -45,7 +45,7 @@ class PlantUmlBuilder implements DiagramBuilder { final visibilityPrefix = getVisibility(element); final staticPrefix = element.isStatic ? '{static} ' : ''; final name = element.name; - final type = element.returnType.name; + final type = element.returnType.getDisplayString(withNullability: true); _lines.add(' $staticPrefix$visibilityPrefix$type $name()'); } @@ -87,16 +87,16 @@ class PlantUmlBuilder implements DiagramBuilder { '"${typeNamespace(element)}${typeName(element)}"'; String getVisibility(Element element) { - return element.isPrivate ? '-' : element.hasProtected ? '#' : '+'; + return element.isPrivate + ? '-' + : element.hasProtected + ? '#' + : '+'; } @override - void printContent(void printer(String content)) { - final content = ([] - ..addAll(_lines) - ..add('') - ..add('@enduml')) - .join('\n'); + void printContent(void Function(String content) printer) { + final content = ([..._lines, '', '@enduml']).join('\n'); printer(content); } diff --git a/lib/src/builders/type_name.dart b/lib/src/builders/type_name.dart index 481a12a..6afd4cb 100644 --- a/lib/src/builders/type_name.dart +++ b/lib/src/builders/type_name.dart @@ -8,11 +8,11 @@ String typeName(final Element element) { } if (element is FieldElement) { - return element.type.displayName; + return element.type.getDisplayString(withNullability: true); } if (element is TypeDefiningElement) { - return element.type.displayName; + return element.displayName; } return element.displayName; diff --git a/lib/src/builders/type_namespace.dart b/lib/src/builders/type_namespace.dart index dd9e0d8..9fa87d3 100644 --- a/lib/src/builders/type_namespace.dart +++ b/lib/src/builders/type_namespace.dart @@ -3,15 +3,15 @@ import 'package:dcdg/src/constants.dart'; /// Build a namespace for the given element based on the definition /// of its type. -String typeNamespace(final Element element, {String separator}) { - LibraryElement library = element.library; +String typeNamespace(final Element element, {String? separator}) { + var library = element.library; if (element is FieldElement) { - library = element.type.element.library; + library = element.type.element?.library; } separator = separator ?? namespaceSeparator; - final namespace = library.identifier + final namespace = library?.identifier .replaceFirst('package:', '') .replaceFirst('dart:', 'dart::') .split('/') diff --git a/lib/src/class_element_collector.dart b/lib/src/class_element_collector.dart index d717ea4..39b1b14 100644 --- a/lib/src/class_element_collector.dart +++ b/lib/src/class_element_collector.dart @@ -14,8 +14,8 @@ class ClassElementCollector extends RecursiveElementVisitor { final bool _exportOnly; ClassElementCollector({ - bool exportedOnly, - }) : _exportOnly = exportedOnly ?? false; + bool exportedOnly = false, + }) : _exportOnly = exportedOnly; Iterable get classElements => _classElements; @@ -30,8 +30,8 @@ class ClassElementCollector extends RecursiveElementVisitor { return; } - final Set _hiddenNames = {}; - final Set _shownNames = {}; + final _hiddenNames = {}; + final _shownNames = {}; for (final combinator in element.combinators) { if (combinator is HideElementCombinator) { @@ -46,7 +46,7 @@ class ClassElementCollector extends RecursiveElementVisitor { final collector = ClassElementCollector( exportedOnly: _exportOnly, ); - element.exportedLibrary.accept(collector); + element.exportedLibrary?.accept(collector); bool shouldInclude(ClassElement element) { if (_shownNames.isEmpty && _hiddenNames.isEmpty) { diff --git a/lib/src/command_line.dart b/lib/src/command_line.dart index c5c5b2c..46700be 100644 --- a/lib/src/command_line.dart +++ b/lib/src/command_line.dart @@ -1,5 +1,6 @@ import 'package:args/args.dart'; import 'package:dcdg/src/builder_factories.dart'; +import 'package:dcdg/src/version.dart'; const builderOption = 'builder'; const excludeOption = 'exclude'; @@ -14,6 +15,7 @@ const isAOption = 'is-a'; const outputPathOption = 'output'; const packagePathOption = 'package'; const searchPathOption = 'search-path'; +const versionOption = 'version'; final argParser = ArgParser(usageLineLength: 80) ..addOption( @@ -48,6 +50,7 @@ final argParser = ArgParser(usageLineLength: 80) exportedOnlyOption, help: 'Include only classes exported from the Dart package', negatable: false, + defaultsTo: false, ) ..addMultiOption( hasAOption, @@ -66,6 +69,7 @@ final argParser = ArgParser(usageLineLength: 80) abbr: 'h', help: 'Show usage information', negatable: false, + defaultsTo: false, ) ..addMultiOption( includeOption, @@ -92,7 +96,14 @@ final argParser = ArgParser(usageLineLength: 80) abbr: 's', help: 'Directory relative to the package root to search for classes', valueHelp: 'DIR', - defaultsTo: null, + defaultsTo: 'lib', + ) + ..addFlag( + versionOption, + abbr: 'v', + help: 'Show the version number and exit', + negatable: false, + defaultsTo: false, ); /// Return a string that contains the usage and help information @@ -113,3 +124,8 @@ Note: If both excludes and includes are supplied, types that are in both lists will be removed from the includes list and then the includes list will be applied as usual.'''; } + +/// Return the version string we show on --version. +String makeVersion() { + return 'dcdg $version'; +} diff --git a/lib/src/configuration.dart b/lib/src/configuration.dart index eff3dd1..1fcd002 100644 --- a/lib/src/configuration.dart +++ b/lib/src/configuration.dart @@ -2,12 +2,11 @@ import 'package:args/args.dart'; import 'package:dcdg/src/builder_factories.dart'; import 'package:dcdg/src/command_line.dart'; import 'package:dcdg/src/builders/diagram_builder.dart'; -import 'package:meta/meta.dart'; /// A full configuration to allow fetching classes and running /// a builder against a Dart package. abstract class Configuration { - DiagramBuilder get builder; + DiagramBuilder? get builder; String get builderName; @@ -39,6 +38,8 @@ abstract class Configuration { bool get shouldShowHelp; + bool get shouldShowVersion; + factory Configuration.fromArgResults(ArgResults results) { final excludePrivateValues = results[excludePrivateOption] as Iterable; @@ -75,18 +76,19 @@ abstract class Configuration { excludePrivateClasses: excludePrivateClasses, excludePrivateFields: excludePrivateFields, excludePrivateMethods: excludePrivateMethods, - exportedOnly: results[exportedOnlyOption], + exportedOnly: results[exportedOnlyOption]!, hasAExpressions: hasAExpressions, includeExpressions: includeExpressions, isAExpressions: isAExpressions, - outputPath: results[outputPathOption], - packagePath: results[packagePathOption], - searchPath: results[searchPathOption], - shouldShowHelp: results[helpOption], + outputPath: results[outputPathOption]!, + packagePath: results[packagePathOption]!, + searchPath: results[searchPathOption]!, + shouldShowHelp: results[helpOption]!, + shouldShowVersion: results[versionOption]!, ); } - factory Configuration.fromCommandLine(List arguments) { + factory Configuration.fromCommandLine(Iterable arguments) { final results = argParser.parse(arguments); return Configuration.fromArgResults(results); } @@ -94,7 +96,7 @@ abstract class Configuration { class ConfigurationImpl implements Configuration { @override - final DiagramBuilder builder; + final DiagramBuilder? builder; @override final String builderName; @@ -141,22 +143,26 @@ class ConfigurationImpl implements Configuration { @override final bool shouldShowHelp; + @override + final bool shouldShowVersion; + ConfigurationImpl({ - @required this.builder, - @required this.builderName, - @required this.excludeExpressions, - @required this.excludeHasA, - @required this.excludeIsA, - @required this.excludePrivateClasses, - @required this.excludePrivateFields, - @required this.excludePrivateMethods, - @required this.exportedOnly, - @required this.hasAExpressions, - @required this.includeExpressions, - @required this.isAExpressions, - @required this.outputPath, - @required this.packagePath, - @required this.searchPath, - @required this.shouldShowHelp, + required this.builder, + required this.builderName, + required this.excludeExpressions, + required this.excludeHasA, + required this.excludeIsA, + required this.excludePrivateClasses, + required this.excludePrivateFields, + required this.excludePrivateMethods, + required this.exportedOnly, + required this.hasAExpressions, + required this.includeExpressions, + required this.isAExpressions, + required this.outputPath, + required this.packagePath, + required this.searchPath, + required this.shouldShowHelp, + required this.shouldShowVersion, }); } diff --git a/lib/src/diagram_visitor.dart b/lib/src/diagram_visitor.dart index f42a674..d983b78 100644 --- a/lib/src/diagram_visitor.dart +++ b/lib/src/diagram_visitor.dart @@ -1,16 +1,11 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:analyzer/dart/element/visitor.dart'; -import 'package:meta/meta.dart'; typedef OnElementHandler = void Function(T element); typedef OnTypeHandler = void Function(T element); -void _defaultOnClass(ClassElement element) { - throw StateError('No onStartClass was provided'); -} - void _noopHandler(_) {} class DiagramVisitor extends RecursiveElementVisitor { @@ -49,52 +44,46 @@ class DiagramVisitor extends RecursiveElementVisitor { final OnTypeHandler _onSuperType; DiagramVisitor({ - @required OnElementHandler onBeginClass, - bool excludeHasA, - bool excludeIsA, - bool excludePrivateClasses, - bool excludePrivateFields, - bool excludePrivateMethods, - Iterable excludes, - Iterable hasA, - Iterable includes, - Iterable isA, - OnElementHandler onAggregateField, - OnElementHandler onField, - OnElementHandler onEndClass, - OnTypeHandler onInterface, - OnElementHandler onMethod, - OnTypeHandler onMixin, - OnTypeHandler onSuper, - }) : _excludeHasA = excludeHasA ?? false, - _excludeIsA = excludeIsA ?? false, - _excludePrivateClasses = excludePrivateClasses ?? false, - _excludePrivateFields = excludePrivateFields ?? false, - _excludePrivateMethods = excludePrivateMethods ?? false, - _excludes = excludes ?? const [], - _hasA = hasA ?? const [], - _includes = includes ?? const [], - _isA = isA ?? const [], - _onAggregateFieldElement = onAggregateField ?? _noopHandler, - _onBeginClassElement = onBeginClass ?? _defaultOnClass, - _onEndClassElement = onEndClass ?? _noopHandler, - _onFieldElement = onField ?? _noopHandler, - _onInterfaceType = onInterface ?? _noopHandler, - _onMethodElement = onMethod ?? _noopHandler, - _onMixinType = onMixin ?? _noopHandler, - _onSuperType = onSuper ?? _noopHandler; + required OnElementHandler onBeginClass, + bool excludeHasA = false, + bool excludeIsA = false, + bool excludePrivateClasses = false, + bool excludePrivateFields = false, + bool excludePrivateMethods = false, + Iterable excludes = const [], + Iterable hasA = const [], + Iterable includes = const [], + Iterable isA = const [], + OnElementHandler onAggregateField = _noopHandler, + OnElementHandler onField = _noopHandler, + OnElementHandler onEndClass = _noopHandler, + OnTypeHandler onInterface = _noopHandler, + OnElementHandler onMethod = _noopHandler, + OnTypeHandler onMixin = _noopHandler, + OnTypeHandler onSuper = _noopHandler, + }) : _excludeHasA = excludeHasA, + _excludeIsA = excludeIsA, + _excludePrivateClasses = excludePrivateClasses, + _excludePrivateFields = excludePrivateFields, + _excludePrivateMethods = excludePrivateMethods, + _excludes = excludes, + _hasA = hasA, + _includes = includes, + _isA = isA, + _onAggregateFieldElement = onAggregateField, + _onBeginClassElement = onBeginClass, + _onEndClassElement = onEndClass, + _onFieldElement = onField, + _onInterfaceType = onInterface, + _onMethodElement = onMethod, + _onMixinType = onMixin, + _onSuperType = onSuper; /// Whether the given class contains a field whose type matches /// one of those provided in the `hasA` constructor parameter. bool hasA(ClassElement element) { for (final field in element.fields) { - final typeName = field.type.name; - - if (typeName == null) { - // Some types, like typedefs, don't have a string - // representation that we can use. - continue; - } + final typeName = field.type.element?.name ?? ''; if (_hasA.any((r) => r.hasMatch(typeName))) { return true; @@ -109,22 +98,27 @@ class DiagramVisitor extends RecursiveElementVisitor { /// constructor parameter. bool isA(ClassElement element) { // - InterfaceType current = element.type; - while (current != null) { + var current = element.thisType; + while (true) { // - if (_isA.any((r) => r.hasMatch(current.name))) { + if (_isA.any((r) => r.hasMatch(current.element.name))) { return true; } - current = current.superclass; + final superclass = current.superclass; + if (superclass == null) { + break; + } + + current = superclass; } for (final needle in _isA) { - if (element.interfaces.any((i) => needle.hasMatch(i.name))) { + if (element.interfaces.any((i) => needle.hasMatch(i.element.name))) { return true; } - if (element.mixins.any((m) => needle.hasMatch(m.name))) { + if (element.mixins.any((m) => needle.hasMatch(m.element.name))) { return true; } } @@ -136,11 +130,11 @@ class DiagramVisitor extends RecursiveElementVisitor { /// and `excludes` lists alone, assuming it isn't excluded for /// any other reason. bool shouldInclude(Element element) { - if (_excludes.any((r) => r.hasMatch(element.name))) { + if (_excludes.any((r) => r.hasMatch(element.name ?? ''))) { return false; } - if (_includes.any((r) => r.hasMatch(element.name))) { + if (_includes.any((r) => r.hasMatch(element.name ?? ''))) { return true; } @@ -212,17 +206,16 @@ class DiagramVisitor extends RecursiveElementVisitor { // TODO: Apply regex filters if (!_excludeIsA) { final superType = element.supertype; - final hasSuper = superType != null; - final superIsObject = superType?.isObject == true; - final isPrivate = superType?.element?.isPrivate == true; - if (hasSuper && + final superIsObject = superType?.isDartCoreObject == true; + final isPrivate = superType?.element.isPrivate == true; + if (superType != null && !superIsObject && !(_excludePrivateClasses && isPrivate)) { _onSuperType(superType); } for (final mixinType in element.mixins) { - if (mixinType.isObject) { + if (mixinType.isDartCoreObject) { continue; } @@ -234,7 +227,7 @@ class DiagramVisitor extends RecursiveElementVisitor { } for (final interfaceType in element.interfaces) { - if (interfaceType.isObject) { + if (interfaceType.isDartCoreObject) { continue; } @@ -270,16 +263,15 @@ class DiagramVisitor extends RecursiveElementVisitor { // statically, and those that are built-in. if (type.isDartAsyncFuture || type.isDartAsyncFutureOr || + type.isDartCoreObject || type.isDynamic || - type.isObject || - type.isUndefined || type.isVoid) { return; } // We ignore things in dart:core because they're everywhere // and we generally don't care about them. - if (type.element.library.isDartCore) { + if (type.element?.library?.isDartCore == true) { return; } @@ -287,6 +279,7 @@ class DiagramVisitor extends RecursiveElementVisitor { } } + @override void visitMethodElement(MethodElement element) { if (!shouldIncludeMethod(element)) { return; diff --git a/lib/src/find_class_elements.dart b/lib/src/find_class_elements.dart index 0764952..414509b 100644 --- a/lib/src/find_class_elements.dart +++ b/lib/src/find_class_elements.dart @@ -3,17 +3,17 @@ import 'dart:io'; import 'package:analyzer/dart/analysis/analysis_context_collection.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:dcdg/src/class_element_collector.dart'; -import 'package:meta/meta.dart'; import 'package:path/path.dart' as path; /// Fetch and return the desired class elements from the package /// rooted at the given path. Future> findClassElements({ - @required String packagePath, - bool exportedOnly, - String searchPath, + required String packagePath, + required bool exportedOnly, + required String searchPath, }) async { - String makePackageSubPath(String part0, [String part1]) => path.normalize( + String makePackageSubPath(String part0, [String part1 = '']) => + path.normalize( path.absolute( path.join( packagePath, @@ -31,7 +31,7 @@ Future> findClassElements({ ], ); - final dartFiles = Directory(makePackageSubPath(searchPath ?? 'lib')) + final dartFiles = Directory(makePackageSubPath(searchPath)) .listSync(recursive: true) .where((file) => path.extension(file.path) == '.dart') .where((file) => !exportedOnly || !file.path.contains('lib/src/')); @@ -44,8 +44,8 @@ Future> findClassElements({ final context = contextCollection.contextFor(filePath); final unitResult = await context.currentSession.getResolvedUnit(filePath); - if (!unitResult.isPart) { - unitResult.libraryElement.accept(collector); + if (unitResult?.isPart == false) { + unitResult?.libraryElement.accept(collector); } } diff --git a/lib/src/version.dart b/lib/src/version.dart new file mode 100644 index 0000000..1a1a3ec --- /dev/null +++ b/lib/src/version.dart @@ -0,0 +1 @@ +const version = '3.0.0'; diff --git a/pubspec.lock b/pubspec.lock index c08d624..f1e05c4 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,376 +1,334 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + url: "https://pub.dartlang.org" + source: hosted + version: "17.0.0" analyzer: dependency: "direct main" description: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "0.36.4" + version: "1.1.0" args: dependency: "direct main" description: name: args url: "https://pub.dartlang.org" source: hosted - version: "1.5.2" + version: "2.0.0" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.4.0" + version: "2.5.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "2.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "1.2.0" + cli_util: + dependency: transitive + description: + name: cli_util + url: "https://pub.dartlang.org" + source: hosted + version: "0.3.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.12" + version: "1.15.0" convert: dependency: transitive description: name: convert url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" + version: "3.0.0" coverage: dependency: transitive description: name: coverage url: "https://pub.dartlang.org" source: hosted - version: "0.13.3+3" + version: "0.15.2" crypto: dependency: transitive description: name: crypto url: "https://pub.dartlang.org" source: hosted - version: "2.1.4" - csslib: + version: "3.0.0" + file: dependency: transitive description: - name: csslib + name: file url: "https://pub.dartlang.org" source: hosted - version: "0.16.1" - front_end: - dependency: transitive - description: - name: front_end - url: "https://pub.dartlang.org" - source: hosted - version: "0.1.19" + version: "6.1.0" glob: dependency: transitive description: name: glob url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" - html: - dependency: transitive - description: - name: html - url: "https://pub.dartlang.org" - source: hosted - version: "0.14.0+3" - http: - dependency: transitive - description: - name: http - url: "https://pub.dartlang.org" - source: hosted - version: "0.12.0+2" + version: "2.0.0" http_multi_server: dependency: transitive description: name: http_multi_server url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.2.0" http_parser: dependency: transitive description: name: http_parser url: "https://pub.dartlang.org" source: hosted - version: "3.1.3" + version: "3.1.4" io: dependency: transitive description: name: io url: "https://pub.dartlang.org" source: hosted - version: "0.3.3" + version: "0.3.5" js: dependency: transitive description: name: js url: "https://pub.dartlang.org" source: hosted - version: "0.6.1+1" - kernel: - dependency: transitive - description: - name: kernel - url: "https://pub.dartlang.org" - source: hosted - version: "0.3.19" + version: "0.6.3" logging: dependency: transitive description: name: logging url: "https://pub.dartlang.org" source: hosted - version: "0.11.3+2" + version: "0.11.4" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.6" + version: "0.12.10" meta: dependency: "direct main" description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.8" + version: "1.3.0" mime: dependency: transitive description: name: mime url: "https://pub.dartlang.org" source: hosted - version: "0.9.6+3" - mockito: - dependency: "direct dev" - description: - name: mockito - url: "https://pub.dartlang.org" - source: hosted - version: "4.1.1" - multi_server_socket: - dependency: transitive - description: - name: multi_server_socket - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.2" - node_interop: - dependency: transitive - description: - name: node_interop - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.3" - node_io: - dependency: transitive - description: - name: node_io - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.1+2" + version: "1.0.0" node_preamble: dependency: transitive description: name: node_preamble url: "https://pub.dartlang.org" source: hosted - version: "1.4.8" + version: "1.4.13" package_config: dependency: transitive description: name: package_config url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" - package_resolver: - dependency: transitive - description: - name: package_resolver - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.10" + version: "2.0.0" path: dependency: "direct main" description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.4" + version: "1.8.0" pedantic: dependency: "direct dev" description: name: pedantic url: "https://pub.dartlang.org" source: hosted - version: "1.9.0" + version: "1.11.0" pool: dependency: transitive description: name: pool url: "https://pub.dartlang.org" source: hosted - version: "1.4.0" + version: "1.5.0" pub_semver: dependency: transitive description: name: pub_semver url: "https://pub.dartlang.org" source: hosted - version: "1.4.2" + version: "2.0.0" shelf: dependency: transitive description: name: shelf url: "https://pub.dartlang.org" source: hosted - version: "0.7.5" + version: "0.7.9" shelf_packages_handler: dependency: transitive description: name: shelf_packages_handler url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "2.0.1" shelf_static: dependency: transitive description: name: shelf_static url: "https://pub.dartlang.org" source: hosted - version: "0.2.8" + version: "0.2.9+2" shelf_web_socket: dependency: transitive description: name: shelf_web_socket url: "https://pub.dartlang.org" source: hosted - version: "0.2.3" + version: "0.2.4+1" source_map_stack_trace: dependency: transitive description: name: source_map_stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.1.5" + version: "2.1.0" source_maps: dependency: transitive description: name: source_maps url: "https://pub.dartlang.org" source: hosted - version: "0.10.8" + version: "0.10.10" source_span: dependency: transitive description: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.5.5" + version: "1.8.1" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.9.3" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" test: dependency: "direct dev" description: name: test url: "https://pub.dartlang.org" source: hosted - version: "1.9.4" + version: "1.16.5" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.11" + version: "0.2.19" test_core: dependency: transitive description: name: test_core url: "https://pub.dartlang.org" source: hosted - version: "0.2.15" + version: "0.3.15" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.3.0" vm_service: dependency: transitive description: name: vm_service url: "https://pub.dartlang.org" source: hosted - version: "2.1.3" + version: "4.2.0" watcher: dependency: transitive description: name: watcher url: "https://pub.dartlang.org" source: hosted - version: "0.9.7+13" + version: "1.0.0" web_socket_channel: dependency: transitive description: name: web_socket_channel url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" + webkit_inspection_protocol: + dependency: transitive + description: + name: webkit_inspection_protocol + url: "https://pub.dartlang.org" + source: hosted + version: "0.7.5" yaml: dependency: transitive description: name: yaml url: "https://pub.dartlang.org" source: hosted - version: "2.2.0" + version: "3.1.0" sdks: - dart: ">=2.6.0 <3.0.0" + dart: ">=2.12.0 <3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 4f675bc..4b4565a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,22 +1,21 @@ name: dcdg description: A tool to automatically generate class diagrams (like UML) from a Dart package. -version: 2.0.1 +version: 3.0.0 homepage: https://github.com/glesica/dcdg.dart author: George Lesica executables: dcdg: environment: - sdk: '>=2.6.0 <3.0.0' + sdk: '>=2.12.0 <3.0.0' dependencies: - analyzer: ^0.36.0 - args: ^1.5.0 + analyzer: ^1.1.0 + args: ^2.0.0 meta: ^1.0.0 path: ^1.4.0 dev_dependencies: - mockito: ^4.0.0 pedantic: ^1.0.0 test: ^1.0.0 diff --git a/test/fixtures/aggregation/lib/aggregation.dart b/test/fixtures/aggregation/lib/aggregation.dart index dc59acb..d6b492e 100644 --- a/test/fixtures/aggregation/lib/aggregation.dart +++ b/test/fixtures/aggregation/lib/aggregation.dart @@ -3,11 +3,13 @@ class Foo0 {} class Foo1 {} class Bar { - Foo0 foo; + Foo0 foo = Foo0(); - Foo1 _foo; + // ignore: unused_field + Foo1 _foo = Foo1(); - int integer; + int integer = 0; - bool _boolean; + // ignore: unused_field + bool _boolean = false; } diff --git a/test/fixtures/aggregation/pubspec.lock b/test/fixtures/aggregation/pubspec.lock index a93d2e7..63f6b73 100644 --- a/test/fixtures/aggregation/pubspec.lock +++ b/test/fixtures/aggregation/pubspec.lock @@ -1,166 +1,166 @@ # Generated by pub -# See https://www.dartlang.org/tools/pub/glossary#lockfile +# See https://dart.dev/tools/pub/glossary#lockfile packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + url: "https://pub.dartlang.org" + source: hosted + version: "17.0.0" analyzer: dependency: transitive description: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "0.36.3" + version: "1.1.0" args: dependency: transitive description: name: args url: "https://pub.dartlang.org" source: hosted - version: "1.5.1" + version: "2.0.0" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.2.0" + version: "2.5.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "1.2.0" + cli_util: + dependency: transitive + description: + name: cli_util + url: "https://pub.dartlang.org" + source: hosted + version: "0.3.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" + version: "1.15.0" convert: dependency: transitive description: name: convert url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" + version: "3.0.0" crypto: dependency: transitive description: name: crypto url: "https://pub.dartlang.org" source: hosted - version: "2.0.6" - csslib: - dependency: transitive - description: - name: csslib - url: "https://pub.dartlang.org" - source: hosted - version: "0.16.0" + version: "3.0.0" dcdg: dependency: "direct dev" description: path: "../../.." relative: true source: path - version: "2.0.0" - front_end: + version: "3.0.0" + file: dependency: transitive description: - name: front_end + name: file url: "https://pub.dartlang.org" source: hosted - version: "0.1.18" + version: "6.1.0" glob: dependency: transitive description: name: glob url: "https://pub.dartlang.org" source: hosted - version: "1.1.7" - html: - dependency: transitive - description: - name: html - url: "https://pub.dartlang.org" - source: hosted - version: "0.14.0+2" - kernel: - dependency: transitive - description: - name: kernel - url: "https://pub.dartlang.org" - source: hosted - version: "0.3.18" + version: "2.0.0" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.7" + version: "1.3.0" package_config: dependency: transitive description: name: package_config url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "2.0.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.2" + version: "1.8.0" + pedantic: + dependency: transitive + description: + name: pedantic + url: "https://pub.dartlang.org" + source: hosted + version: "1.11.0" pub_semver: dependency: transitive description: name: pub_semver url: "https://pub.dartlang.org" source: hosted - version: "1.4.2" + version: "2.0.0" source_span: dependency: transitive description: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.5.5" + version: "1.8.1" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.3.0" watcher: dependency: transitive description: name: watcher url: "https://pub.dartlang.org" source: hosted - version: "0.9.7+10" + version: "1.0.0" yaml: dependency: transitive description: name: yaml url: "https://pub.dartlang.org" source: hosted - version: "2.1.15" + version: "3.1.0" sdks: - dart: ">=2.2.0 <3.0.0" + dart: ">=2.12.0 <3.0.0" diff --git a/test/fixtures/aggregation/pubspec.yaml b/test/fixtures/aggregation/pubspec.yaml index d9363aa..f999a16 100644 --- a/test/fixtures/aggregation/pubspec.yaml +++ b/test/fixtures/aggregation/pubspec.yaml @@ -1,5 +1,7 @@ name: aggregation_fixture description: A test fixture with aggregations +environment: + sdk: '>=2.12.0 <3.0.0' dev_dependencies: dcdg: path: ../../../ diff --git a/test/fixtures/exports/pubspec.lock b/test/fixtures/exports/pubspec.lock index a93d2e7..63f6b73 100644 --- a/test/fixtures/exports/pubspec.lock +++ b/test/fixtures/exports/pubspec.lock @@ -1,166 +1,166 @@ # Generated by pub -# See https://www.dartlang.org/tools/pub/glossary#lockfile +# See https://dart.dev/tools/pub/glossary#lockfile packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + url: "https://pub.dartlang.org" + source: hosted + version: "17.0.0" analyzer: dependency: transitive description: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "0.36.3" + version: "1.1.0" args: dependency: transitive description: name: args url: "https://pub.dartlang.org" source: hosted - version: "1.5.1" + version: "2.0.0" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.2.0" + version: "2.5.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "1.2.0" + cli_util: + dependency: transitive + description: + name: cli_util + url: "https://pub.dartlang.org" + source: hosted + version: "0.3.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" + version: "1.15.0" convert: dependency: transitive description: name: convert url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" + version: "3.0.0" crypto: dependency: transitive description: name: crypto url: "https://pub.dartlang.org" source: hosted - version: "2.0.6" - csslib: - dependency: transitive - description: - name: csslib - url: "https://pub.dartlang.org" - source: hosted - version: "0.16.0" + version: "3.0.0" dcdg: dependency: "direct dev" description: path: "../../.." relative: true source: path - version: "2.0.0" - front_end: + version: "3.0.0" + file: dependency: transitive description: - name: front_end + name: file url: "https://pub.dartlang.org" source: hosted - version: "0.1.18" + version: "6.1.0" glob: dependency: transitive description: name: glob url: "https://pub.dartlang.org" source: hosted - version: "1.1.7" - html: - dependency: transitive - description: - name: html - url: "https://pub.dartlang.org" - source: hosted - version: "0.14.0+2" - kernel: - dependency: transitive - description: - name: kernel - url: "https://pub.dartlang.org" - source: hosted - version: "0.3.18" + version: "2.0.0" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.7" + version: "1.3.0" package_config: dependency: transitive description: name: package_config url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "2.0.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.2" + version: "1.8.0" + pedantic: + dependency: transitive + description: + name: pedantic + url: "https://pub.dartlang.org" + source: hosted + version: "1.11.0" pub_semver: dependency: transitive description: name: pub_semver url: "https://pub.dartlang.org" source: hosted - version: "1.4.2" + version: "2.0.0" source_span: dependency: transitive description: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.5.5" + version: "1.8.1" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.3.0" watcher: dependency: transitive description: name: watcher url: "https://pub.dartlang.org" source: hosted - version: "0.9.7+10" + version: "1.0.0" yaml: dependency: transitive description: name: yaml url: "https://pub.dartlang.org" source: hosted - version: "2.1.15" + version: "3.1.0" sdks: - dart: ">=2.2.0 <3.0.0" + dart: ">=2.12.0 <3.0.0" diff --git a/test/fixtures/exports/pubspec.yaml b/test/fixtures/exports/pubspec.yaml index d5f16e4..14b1d9b 100644 --- a/test/fixtures/exports/pubspec.yaml +++ b/test/fixtures/exports/pubspec.yaml @@ -1,5 +1,7 @@ name: exports_fixture description: A test fixture with exports +environment: + sdk: '>=2.12.0 <3.0.0' dev_dependencies: dcdg: path: ../../../ diff --git a/test/fixtures/inheritance/pubspec.lock b/test/fixtures/inheritance/pubspec.lock index a93d2e7..63f6b73 100644 --- a/test/fixtures/inheritance/pubspec.lock +++ b/test/fixtures/inheritance/pubspec.lock @@ -1,166 +1,166 @@ # Generated by pub -# See https://www.dartlang.org/tools/pub/glossary#lockfile +# See https://dart.dev/tools/pub/glossary#lockfile packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + url: "https://pub.dartlang.org" + source: hosted + version: "17.0.0" analyzer: dependency: transitive description: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "0.36.3" + version: "1.1.0" args: dependency: transitive description: name: args url: "https://pub.dartlang.org" source: hosted - version: "1.5.1" + version: "2.0.0" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.2.0" + version: "2.5.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "1.2.0" + cli_util: + dependency: transitive + description: + name: cli_util + url: "https://pub.dartlang.org" + source: hosted + version: "0.3.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" + version: "1.15.0" convert: dependency: transitive description: name: convert url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" + version: "3.0.0" crypto: dependency: transitive description: name: crypto url: "https://pub.dartlang.org" source: hosted - version: "2.0.6" - csslib: - dependency: transitive - description: - name: csslib - url: "https://pub.dartlang.org" - source: hosted - version: "0.16.0" + version: "3.0.0" dcdg: dependency: "direct dev" description: path: "../../.." relative: true source: path - version: "2.0.0" - front_end: + version: "3.0.0" + file: dependency: transitive description: - name: front_end + name: file url: "https://pub.dartlang.org" source: hosted - version: "0.1.18" + version: "6.1.0" glob: dependency: transitive description: name: glob url: "https://pub.dartlang.org" source: hosted - version: "1.1.7" - html: - dependency: transitive - description: - name: html - url: "https://pub.dartlang.org" - source: hosted - version: "0.14.0+2" - kernel: - dependency: transitive - description: - name: kernel - url: "https://pub.dartlang.org" - source: hosted - version: "0.3.18" + version: "2.0.0" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.7" + version: "1.3.0" package_config: dependency: transitive description: name: package_config url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "2.0.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.2" + version: "1.8.0" + pedantic: + dependency: transitive + description: + name: pedantic + url: "https://pub.dartlang.org" + source: hosted + version: "1.11.0" pub_semver: dependency: transitive description: name: pub_semver url: "https://pub.dartlang.org" source: hosted - version: "1.4.2" + version: "2.0.0" source_span: dependency: transitive description: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.5.5" + version: "1.8.1" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.3.0" watcher: dependency: transitive description: name: watcher url: "https://pub.dartlang.org" source: hosted - version: "0.9.7+10" + version: "1.0.0" yaml: dependency: transitive description: name: yaml url: "https://pub.dartlang.org" source: hosted - version: "2.1.15" + version: "3.1.0" sdks: - dart: ">=2.2.0 <3.0.0" + dart: ">=2.12.0 <3.0.0" diff --git a/test/fixtures/inheritance/pubspec.yaml b/test/fixtures/inheritance/pubspec.yaml index 8125a8c..bfb3ebd 100644 --- a/test/fixtures/inheritance/pubspec.yaml +++ b/test/fixtures/inheritance/pubspec.yaml @@ -1,5 +1,7 @@ name: inheritance_fixture description: A test fixture with inheritance +environment: + sdk: '>=2.12.0 <3.0.0' dev_dependencies: dcdg: path: ../../../ diff --git a/test/fixtures/simple/lib/external.dart b/test/fixtures/simple/lib/external.dart index 31dfe42..0287234 100644 --- a/test/fixtures/simple/lib/external.dart +++ b/test/fixtures/simple/lib/external.dart @@ -1,7 +1,10 @@ class PublicExternalPublic { + // ignore: unused_field dynamic _privateExternalFieldPrivate; + // ignore: unused_element void _privateExternalMethodPrivate() {} } +// ignore: unused_element class _PrivateExternalPrivate {} diff --git a/test/fixtures/simple/lib/src/internal.dart b/test/fixtures/simple/lib/src/internal.dart index b55dfd9..1771ce0 100644 --- a/test/fixtures/simple/lib/src/internal.dart +++ b/test/fixtures/simple/lib/src/internal.dart @@ -2,4 +2,5 @@ part 'part.dart'; class PublicInternalPublic {} +// ignore: unused_element class _PrivateInternalPrivate {} diff --git a/test/fixtures/simple/lib/src/part.dart b/test/fixtures/simple/lib/src/part.dart index b2834c1..353abf3 100644 --- a/test/fixtures/simple/lib/src/part.dart +++ b/test/fixtures/simple/lib/src/part.dart @@ -2,4 +2,5 @@ part of 'internal.dart'; class PublicPartInternalPartPublic {} +// ignore: unused_element class _PrivatePartInternalPartPrivate {} diff --git a/test/fixtures/simple/pubspec.lock b/test/fixtures/simple/pubspec.lock index a93d2e7..63f6b73 100644 --- a/test/fixtures/simple/pubspec.lock +++ b/test/fixtures/simple/pubspec.lock @@ -1,166 +1,166 @@ # Generated by pub -# See https://www.dartlang.org/tools/pub/glossary#lockfile +# See https://dart.dev/tools/pub/glossary#lockfile packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + url: "https://pub.dartlang.org" + source: hosted + version: "17.0.0" analyzer: dependency: transitive description: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "0.36.3" + version: "1.1.0" args: dependency: transitive description: name: args url: "https://pub.dartlang.org" source: hosted - version: "1.5.1" + version: "2.0.0" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.2.0" + version: "2.5.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "1.2.0" + cli_util: + dependency: transitive + description: + name: cli_util + url: "https://pub.dartlang.org" + source: hosted + version: "0.3.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" + version: "1.15.0" convert: dependency: transitive description: name: convert url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" + version: "3.0.0" crypto: dependency: transitive description: name: crypto url: "https://pub.dartlang.org" source: hosted - version: "2.0.6" - csslib: - dependency: transitive - description: - name: csslib - url: "https://pub.dartlang.org" - source: hosted - version: "0.16.0" + version: "3.0.0" dcdg: dependency: "direct dev" description: path: "../../.." relative: true source: path - version: "2.0.0" - front_end: + version: "3.0.0" + file: dependency: transitive description: - name: front_end + name: file url: "https://pub.dartlang.org" source: hosted - version: "0.1.18" + version: "6.1.0" glob: dependency: transitive description: name: glob url: "https://pub.dartlang.org" source: hosted - version: "1.1.7" - html: - dependency: transitive - description: - name: html - url: "https://pub.dartlang.org" - source: hosted - version: "0.14.0+2" - kernel: - dependency: transitive - description: - name: kernel - url: "https://pub.dartlang.org" - source: hosted - version: "0.3.18" + version: "2.0.0" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.7" + version: "1.3.0" package_config: dependency: transitive description: name: package_config url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "2.0.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.2" + version: "1.8.0" + pedantic: + dependency: transitive + description: + name: pedantic + url: "https://pub.dartlang.org" + source: hosted + version: "1.11.0" pub_semver: dependency: transitive description: name: pub_semver url: "https://pub.dartlang.org" source: hosted - version: "1.4.2" + version: "2.0.0" source_span: dependency: transitive description: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.5.5" + version: "1.8.1" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.3.0" watcher: dependency: transitive description: name: watcher url: "https://pub.dartlang.org" source: hosted - version: "0.9.7+10" + version: "1.0.0" yaml: dependency: transitive description: name: yaml url: "https://pub.dartlang.org" source: hosted - version: "2.1.15" + version: "3.1.0" sdks: - dart: ">=2.2.0 <3.0.0" + dart: ">=2.12.0 <3.0.0" diff --git a/test/fixtures/simple/pubspec.yaml b/test/fixtures/simple/pubspec.yaml index 8e81533..58ffe3b 100644 --- a/test/fixtures/simple/pubspec.yaml +++ b/test/fixtures/simple/pubspec.yaml @@ -1,5 +1,7 @@ name: simple_fixture description: A simple test fixture +environment: + sdk: '>=2.12.0 <3.0.0' dev_dependencies: dcdg: path: ../../../ diff --git a/test/fixtures/subdir/pubspec.lock b/test/fixtures/subdir/pubspec.lock index a93d2e7..63f6b73 100644 --- a/test/fixtures/subdir/pubspec.lock +++ b/test/fixtures/subdir/pubspec.lock @@ -1,166 +1,166 @@ # Generated by pub -# See https://www.dartlang.org/tools/pub/glossary#lockfile +# See https://dart.dev/tools/pub/glossary#lockfile packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + url: "https://pub.dartlang.org" + source: hosted + version: "17.0.0" analyzer: dependency: transitive description: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "0.36.3" + version: "1.1.0" args: dependency: transitive description: name: args url: "https://pub.dartlang.org" source: hosted - version: "1.5.1" + version: "2.0.0" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.2.0" + version: "2.5.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "1.2.0" + cli_util: + dependency: transitive + description: + name: cli_util + url: "https://pub.dartlang.org" + source: hosted + version: "0.3.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" + version: "1.15.0" convert: dependency: transitive description: name: convert url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" + version: "3.0.0" crypto: dependency: transitive description: name: crypto url: "https://pub.dartlang.org" source: hosted - version: "2.0.6" - csslib: - dependency: transitive - description: - name: csslib - url: "https://pub.dartlang.org" - source: hosted - version: "0.16.0" + version: "3.0.0" dcdg: dependency: "direct dev" description: path: "../../.." relative: true source: path - version: "2.0.0" - front_end: + version: "3.0.0" + file: dependency: transitive description: - name: front_end + name: file url: "https://pub.dartlang.org" source: hosted - version: "0.1.18" + version: "6.1.0" glob: dependency: transitive description: name: glob url: "https://pub.dartlang.org" source: hosted - version: "1.1.7" - html: - dependency: transitive - description: - name: html - url: "https://pub.dartlang.org" - source: hosted - version: "0.14.0+2" - kernel: - dependency: transitive - description: - name: kernel - url: "https://pub.dartlang.org" - source: hosted - version: "0.3.18" + version: "2.0.0" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.7" + version: "1.3.0" package_config: dependency: transitive description: name: package_config url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "2.0.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.2" + version: "1.8.0" + pedantic: + dependency: transitive + description: + name: pedantic + url: "https://pub.dartlang.org" + source: hosted + version: "1.11.0" pub_semver: dependency: transitive description: name: pub_semver url: "https://pub.dartlang.org" source: hosted - version: "1.4.2" + version: "2.0.0" source_span: dependency: transitive description: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.5.5" + version: "1.8.1" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.3.0" watcher: dependency: transitive description: name: watcher url: "https://pub.dartlang.org" source: hosted - version: "0.9.7+10" + version: "1.0.0" yaml: dependency: transitive description: name: yaml url: "https://pub.dartlang.org" source: hosted - version: "2.1.15" + version: "3.1.0" sdks: - dart: ">=2.2.0 <3.0.0" + dart: ">=2.12.0 <3.0.0" diff --git a/test/fixtures/subdir/pubspec.yaml b/test/fixtures/subdir/pubspec.yaml index de523c1..bcf4b31 100644 --- a/test/fixtures/subdir/pubspec.yaml +++ b/test/fixtures/subdir/pubspec.yaml @@ -1,5 +1,7 @@ name: subdir_fixture description: A test fixture with a subdirectory +environment: + sdk: '>=2.12.0 <3.0.0' dev_dependencies: dcdg: path: ../../../ diff --git a/test/functional/utils.dart b/test/functional/utils.dart index cf678d4..d626fc8 100644 --- a/test/functional/utils.dart +++ b/test/functional/utils.dart @@ -38,6 +38,7 @@ ProcessResult runWith(Iterable arguments, String against) => '--trace', 'run', 'dcdg', - ]..addAll(arguments), + ...arguments, + ], workingDirectory: against, ); diff --git a/test/unit/diagram_visitor_test.dart b/test/unit/diagram_visitor_test.dart index adeb550..e5cd6ef 100644 --- a/test/unit/diagram_visitor_test.dart +++ b/test/unit/diagram_visitor_test.dart @@ -1,8 +1,9 @@ -import 'package:analyzer/dart/element/element.dart'; -import 'package:dcdg/src/diagram_visitor.dart'; -import 'package:mockito/mockito.dart'; import 'package:test/test.dart'; +import 'package:dcdg/src/diagram_visitor.dart'; + +import 'fakes.dart'; + void main() { group('DiagramVisitor', () { group('shouldInclude', () { @@ -11,7 +12,7 @@ void main() { final visitor = DiagramVisitor( onBeginClass: (_) {}, ); - final element = MockElement('A'); + final element = FakeElement('A'); expect(visitor.shouldInclude(element), isTrue); }); @@ -20,7 +21,7 @@ void main() { onBeginClass: (_) {}, includes: [RegExp('A')], ); - final element = MockElement('A'); + final element = FakeElement('A'); expect(visitor.shouldInclude(element), isTrue); }); @@ -29,7 +30,7 @@ void main() { onBeginClass: (_) {}, excludes: [RegExp('B')], ); - final element = MockElement('A'); + final element = FakeElement('A'); expect(visitor.shouldInclude(element), isTrue); }); @@ -39,7 +40,7 @@ void main() { excludes: [RegExp('B')], includes: [RegExp('A')], ); - final element = MockElement('A'); + final element = FakeElement('A'); expect(visitor.shouldInclude(element), isTrue); }); }); @@ -50,7 +51,7 @@ void main() { onBeginClass: (_) {}, excludes: [RegExp('A')], ); - final element = MockElement('A'); + final element = FakeElement('A'); expect(visitor.shouldInclude(element), isFalse); }); @@ -60,7 +61,7 @@ void main() { excludes: [RegExp('A')], includes: [RegExp('B')], ); - final element = MockElement('A'); + final element = FakeElement('A'); expect(visitor.shouldInclude(element), isFalse); }); @@ -69,7 +70,7 @@ void main() { onBeginClass: (_) {}, includes: [RegExp('B')], ); - final element = MockElement('A'); + final element = FakeElement('A'); expect(visitor.shouldInclude(element), isFalse); }); @@ -79,19 +80,10 @@ void main() { excludes: [RegExp('B')], includes: [RegExp('C')], ); - final element = MockElement('A'); + final element = FakeElement('A'); expect(visitor.shouldInclude(element), isFalse); }); }); }); }); } - -class MockElement extends Mock implements Element { - final String _name; - - MockElement(this._name); - - @override - String get name => _name; -} diff --git a/test/unit/fakes.dart b/test/unit/fakes.dart new file mode 100644 index 0000000..fb0c1fa --- /dev/null +++ b/test/unit/fakes.dart @@ -0,0 +1,24 @@ +import 'package:analyzer/dart/element/element.dart'; + +class FakeElement implements Element { + @override + final LibraryElement? library; + + @override + final String? name; + + FakeElement(this.name, [this.library]); + + @override + dynamic noSuchMethod(_) {} +} + +class FakeLibraryElement implements LibraryElement { + @override + final String identifier; + + FakeLibraryElement(this.identifier); + + @override + dynamic noSuchMethod(_) {} +} diff --git a/test/unit/type_namespace_test.dart b/test/unit/type_namespace_test.dart index e10e7b5..ac9c927 100644 --- a/test/unit/type_namespace_test.dart +++ b/test/unit/type_namespace_test.dart @@ -1,24 +1,16 @@ -import 'package:analyzer/dart/element/element.dart'; +import 'package:test/test.dart'; + import 'package:dcdg/src/builders/type_namespace.dart'; import 'package:dcdg/src/constants.dart'; -import 'package:mockito/mockito.dart'; -import 'package:test/test.dart'; + +import 'fakes.dart'; void main() { group('typeNamespace', () { - Element element; - LibraryElement library; - - setUp(() { - element = MockElement(); - library = MockLibraryElement(); - - when(element.name).thenReturn('class'); - when(element.library).thenReturn(library); - }); - test('should concatenate package and class name', () { - when(library.identifier).thenReturn('package:pkg/entry.dart'); + final library = FakeLibraryElement('package:pkg/entry.dart'); + final element = FakeElement('class', library); + final namespace = typeNamespace(element); expect( namespace, @@ -31,7 +23,9 @@ void main() { }); test('should convert a dart:core prefix to dart::core', () { - when(library.identifier).thenReturn('dart:core/entry.dart'); + final library = FakeLibraryElement('dart:core/entry.dart'); + final element = FakeElement('class', library); + final namespace = typeNamespace(element); expect( namespace, @@ -45,7 +39,9 @@ void main() { }); test('should allow a custom namespace separator', () { - when(library.identifier).thenReturn('package:pkg/entry.dart'); + final library = FakeLibraryElement('package:pkg/entry.dart'); + final element = FakeElement('class', library); + final separator = '+'; final namespace = typeNamespace(element, separator: separator); expect( @@ -59,7 +55,3 @@ void main() { }); }); } - -class MockElement extends Mock implements Element {} - -class MockLibraryElement extends Mock implements LibraryElement {} diff --git a/tool/binary.sh b/tool/binary.sh new file mode 100755 index 0000000..7a7e7f1 --- /dev/null +++ b/tool/binary.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +set -e + +mkdir -p build/ +PLATFORM=$(uname -s | tr '[:upper:]' '[:lower:]') +dart2native -o "build/dcdg-$PLATFORM" bin/dcdg.dart diff --git a/tool/check.sh b/tool/check.sh index 6bce49d..9cc7790 100755 --- a/tool/check.sh +++ b/tool/check.sh @@ -1,3 +1,4 @@ #!/bin/sh +pub get pub run test -j 1 $@ diff --git a/tool/docker.sh b/tool/docker.sh new file mode 100755 index 0000000..72b4441 --- /dev/null +++ b/tool/docker.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +set -e + +docker build -f Dockerfile_build -t glesica/dcdg_build:latest . +docker push glesica/dcdg_build:latest diff --git a/tool/docs.sh b/tool/docs.sh index d4c714e..70b6300 100755 --- a/tool/docs.sh +++ b/tool/docs.sh @@ -1,9 +1,13 @@ #!/bin/sh +set -e + +# Update the version number in Dart based on the pubspec +awk '/version: / {print "const version = " "'\''" $2 "'\''" ";"}' pubspec.yaml > lib/src/version.dart + # Generate example outputs pub run dcdg -o example/dcdg.puml --exclude-private=field,method plantuml example/dcdg.puml # Add the --help contents to a text file pub run dcdg --help > USAGE.txt -