Skip to content

Commit

Permalink
Simplify analyzer dart command by using a single workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
parlough committed Dec 11, 2024
1 parent a4bbe50 commit b3e6558
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 33 deletions.
1 change: 1 addition & 0 deletions examples/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: examples_workspace
publish_to: none

resolution: workspace
environment:
sdk: ^3.6.0

Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ environment:

workspace:
- tool/dart_site
- examples
- tool/get-dart

dev_dependencies:
dart_site:
Expand Down
47 changes: 14 additions & 33 deletions tool/dart_site/lib/src/commands/analyze_dart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import 'dart:io';

import 'package:args/command_runner.dart';
import 'package:path/path.dart' as path;

import '../utils.dart';

Expand Down Expand Up @@ -35,44 +34,26 @@ final class AnalyzeDartCommand extends Command<int> {
int analyzeDart({
bool verboseLogging = false,
}) {
final directoriesToAnalyze = [
path.join('tool', 'dart_site'),
path.join('examples'),
path.join('tool', 'get-dart'),
];

if (!verboseLogging) {
print('Analyzing code...');
}

for (final directory in directoriesToAnalyze) {
if (verboseLogging) {
print("Analyzing code in '$directory' directory...");
}

if (runPubGetIfNecessary(directory) case final pubGetResult
when pubGetResult != 0) {
return pubGetResult;
}

final dartAnalyzeOutput = Process.runSync(
Platform.executable,
const ['analyze', '.'],
workingDirectory: directory,
);
final dartAnalyzeOutput = Process.runSync(
Platform.executable,
const ['analyze'],
);

if (dartAnalyzeOutput.exitCode != 0) {
final normalOutput = dartAnalyzeOutput.stdout.toString();
final errorOutput = dartAnalyzeOutput.stderr.toString();
if (dartAnalyzeOutput.exitCode != 0) {
final normalOutput = dartAnalyzeOutput.stdout.toString();
final errorOutput = dartAnalyzeOutput.stderr.toString();

stderr.write(normalOutput);
stderr.write(errorOutput);
stderr.writeln("Error: Analysis on '$directory' directory failed.");
return 1;
} else {
if (verboseLogging) {
print("Successfully analyzed code in '$directory' directory!");
}
stderr.write(normalOutput);
stderr.write(errorOutput);
stderr.writeln('Error: Analysis failed.');
return 1;
} else {
if (verboseLogging) {
print('Successfully analyzed Dart code!');
}
}

Expand Down
1 change: 1 addition & 0 deletions tool/get-dart/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: get_dart
publish_to: none

resolution: workspace
environment:
sdk: ^3.6.0

Expand Down

0 comments on commit b3e6558

Please sign in to comment.