diff --git a/packages/riverpod_graph/README.md b/packages/riverpod_graph/README.md index a1702dcaf..af668d1c2 100644 --- a/packages/riverpod_graph/README.md +++ b/packages/riverpod_graph/README.md @@ -8,3 +8,19 @@ The graph generated is generated using [Mermaid](https://mermaid-js.github.io/me Here is graph example, generated from the Flutter Devtool project (which uses Riverpod). ![Devtool graph](../../resources/devtool_graph.jpeg) + +## Generating a graph + +Assuming you are working on `riverpod_graph` in this repo. You can test against other projects with relative references. Generating a graph against the `examples/todos` project would look like: + +``` +cd into the riverpod_graph directory +../riverpod/packages/riverpod_graph$ dart run riverpod_graph:riverpod_graph ../../examples/todos/lib -f d2 +``` + +Assuming you have activated, installed, riverpod_graph in the dart cache: + +``` +cd into the lib directory of the program you wish to analyze +dart run riverpod_graph:riverpod_graph -f d2 +``` diff --git a/packages/riverpod_graph/lib/src/analyze.dart b/packages/riverpod_graph/lib/src/analyze.dart index 0fd6c90a8..6c3889f30 100644 --- a/packages/riverpod_graph/lib/src/analyze.dart +++ b/packages/riverpod_graph/lib/src/analyze.dart @@ -19,6 +19,8 @@ Future analyze( resourceProvider: PhysicalResourceProvider.INSTANCE, ); + verifyRootDirectoryExists(rootDirectory); + // Often one context is returned, but depending on the project structure we // can see multiple contexts. for (final context in collection.contexts) { @@ -88,6 +90,17 @@ Future analyze( } } +/// +///Throws an exception if the directory doesn't exist +/// +bool verifyRootDirectoryExists(String rootDirectory) { + if (!Directory(rootDirectory).existsSync()) { + throw FileSystemException( + 'Requested scanning target directory does not exist $rootDirectory'); + } + return true; +} + /// Output formats supported by riverpod_graph enum SupportFormat { /// Mermaid.js format @@ -156,10 +169,10 @@ flowchart TB style stop1 height:0px; start2[ ] --->|listen| stop2[ ] style start2 height:0px; - style stop2 height:0px; + style stop2 height:0px; start3[ ] ===>|watch| stop3[ ] style start3 height:0px; - style stop3 height:0px; + style stop3 height:0px; end subgraph Type diff --git a/packages/riverpod_graph/test/analyze_test.dart b/packages/riverpod_graph/test/analyze_test.dart new file mode 100644 index 000000000..5a26f7933 --- /dev/null +++ b/packages/riverpod_graph/test/analyze_test.dart @@ -0,0 +1,21 @@ +// ignore_for_file: avoid_types_on_closure_parameters + +import 'dart:io'; + +import 'package:riverpod_graph/src/analyze.dart'; + +import 'package:test/test.dart'; + +void main() { + group('flutter graph analyzer tests', () { + test('throw exception if analysis target directory does not exist', () { + // expect(() => verifyRootDirectoryExists('dogfood'), + // throwsA(isA()) + // ); + }); + + test('returns true if analysis target directory does exist', () { + expect(verifyRootDirectoryExists('.'), true); + }); + }); +}