Skip to content

Commit 6b42ea2

Browse files
committed
Add evaluate api for dart test
1 parent c08fe83 commit 6b42ea2

File tree

9 files changed

+38
-14
lines changed

9 files changed

+38
-14
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Preview the health and quality of a Dart/Flutter package before publish.
1414

1515
Install `pana_html` with pub.
1616
```dart
17-
pub global activate pana
1817
pub global activate pana_html
1918
```
2019

cli/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 0.1.3
2+
- Add api for dart test;
3+
14
## 0.1.2
25
- Add options to control local server and strict mode;
36
- Fix resource path;

cli/bin/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:pana_html/pana_html.dart' as cli;
22

3+
/// cli entry point
34
void main(List<String> arguments) {
45
cli.main(arguments);
56
}

cli/example/main.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import 'package:pana_html/cli.dart' as cli;
1+
import 'package:pana_html/pana_html.dart' as cli;
22

33
void main(List<String> args) {
44
print('call pana_html');
5-
cli.main(arguments);
5+
cli.evaluate(['--no-web', '--strict']);
66
}

cli/lib/pana_html.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
import 'dart:async';
22
import 'dart:io';
33

4+
import 'package:pana_html/src/result.dart';
5+
46
import 'src/runner.dart';
57

8+
/// entry point of application
69
Future<void> main(List<String> args) async {
7-
var runner = ProjectRunner(args);
8-
var result = await runner.evaluate();
10+
var result = await evaluate(args);
911
var state = result.success ? 'success' : 'failed';
1012
print('Evaluate:$state, ${result.message}');
11-
if(!result.success){
13+
if (!result.success) {
1214
exit(1);
1315
}
1416
}
17+
18+
/// run project evaluation
19+
/// args example: ['--no-web', '--strict']
20+
Future<EvaluateResult> evaluate(List<String> args) async {
21+
return ProjectRunner(args).evaluate();
22+
}

cli/lib/src/result.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
/// Result bean
22
class EvaluateResult {
3+
/// text message.
34
final String message;
5+
6+
/// evaluate state.
47
final bool success;
58

6-
EvaluateResult({this.message, this.success});
9+
/// url of local server.
10+
final String url;
11+
12+
/// New instance
13+
EvaluateResult({this.message, this.success, this.url});
714
}

cli/lib/src/runner.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class ProjectRunner {
3535
negatable: false,
3636
help: 'Print this usage information.');
3737

38+
/// Construct a runner according to the cli parameters
3839
ProjectRunner(this.args) {
3940
var argResults = _parser.parse(args);
4041
_webServer = argResults['web'];
@@ -90,8 +91,9 @@ class ProjectRunner {
9091
if (json != null) {
9192
print('analyze completed');
9293
}
94+
var url = '';
9395
if (_webServer) {
94-
await _genHtml(result);
96+
url = await _genHtml(result);
9597
}
9698
var scores = json['scores'];
9799
var health = scores != null ? scores['health'] : 0;
@@ -102,19 +104,21 @@ class ProjectRunner {
102104
return EvaluateResult(
103105
success: false,
104106
message: 'health:$health, maintenance=$maintenance',
107+
url: url,
105108
);
106109
}
107110
}
108111

109112
return EvaluateResult(
110113
success: true,
111114
message: 'health:$health, maintenance=$maintenance',
115+
url: url,
112116
);
113117
}
114118
}
115119

116120
/// generate html report and deploy as local service
117-
Future<void> _genHtml(String result) async {
121+
Future<String> _genHtml(String result) async {
118122
var exist = await Directory('pana_visual').exists();
119123
if (!exist) {
120124
Directory('pana_visual').createSync();
@@ -123,6 +127,7 @@ Future<void> _genHtml(String result) async {
123127
// update data.json
124128
var dataFile = join('pana_visual', 'assets', 'assets', 'data.json');
125129
File(dataFile).writeAsStringSync(result);
126-
await serve('pana_visual');
130+
var url = await serve('pana_visual');
127131
print('Terminate as you like');
132+
return url;
128133
}

cli/lib/src/static_file_server.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'dart:io';
33
import 'package:http_server/http_server.dart';
44

55
/// static file server
6-
void serve(String root) async {
6+
Future<String> serve(String root) async {
77
var staticFiles = VirtualDirectory(root);
88
staticFiles.allowDirectoryListing = true;
99
staticFiles.directoryHandler = (dir, request) {
@@ -15,6 +15,7 @@ void serve(String root) async {
1515
server.listen((event) {
1616
staticFiles.serveRequest(event);
1717
});
18-
print('Pana report are served at http://127.0.0.1:${server.port}#/home');
19-
// await server.forEach(staticFiles.serveRequest);
18+
var url = 'http://127.0.0.1:${server.port}#/home';
19+
print('Pana report are served at $url');
20+
return url;
2021
}

cli/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: pana_html
22
description: Preview the health and quality of a Dart/Flutter package before publish.
3-
version: 0.1.2
3+
version: 0.1.3
44
homepage: https://github.com/hacktons/pana_visual
55

66
environment:

0 commit comments

Comments
 (0)