Skip to content

Commit

Permalink
Verify analyzer target directory exists
Browse files Browse the repository at this point in the history
  • Loading branch information
freemansoft committed Jul 24, 2023
1 parent a6900e0 commit af6f62d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
16 changes: 16 additions & 0 deletions packages/riverpod_graph/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <path-to-root-dir> -f d2
```
17 changes: 15 additions & 2 deletions packages/riverpod_graph/lib/src/analyze.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Future<void> 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) {
Expand Down Expand Up @@ -88,6 +90,17 @@ Future<void> 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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions packages/riverpod_graph/test/analyze_test.dart
Original file line number Diff line number Diff line change
@@ -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<FileSystemException>())
// );
});

test('returns true if analysis target directory does exist', () {
expect(verifyRootDirectoryExists('.'), true);
});
});
}

0 comments on commit af6f62d

Please sign in to comment.