Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions .github/workflows/very_good_cli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ jobs:

steps:
- uses: actions/checkout@v2.3.4
- uses: subosito/flutter-action@v1.5.0

- uses: subosito/flutter-action@v1.5.3

- name: Install Dependencies
run: flutter pub get
Expand All @@ -45,12 +46,30 @@ jobs:
- name: Check Code Coverage
uses: VeryGoodOpenSource/very_good_coverage@v1.1.1

e2e:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2.3.4

- uses: subosito/flutter-action@v1.5.3

- name: Install Dependencies
run: flutter pub get

- name: Run Tests
run: flutter pub run test --run-skipped -t e2e

- name: Check Code Coverage
uses: VeryGoodOpenSource/very_good_coverage@v1.1.1

pana:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2.3.4
- uses: subosito/flutter-action@v1.5.0

- uses: subosito/flutter-action@v1.5.3

- name: Install Dependencies
run: |
Expand Down
2 changes: 2 additions & 0 deletions dart_test.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
tags:
pull-request-only:
skip: "Should only be run during pull request"
e2e:
skip: "End to end tests should be run in parallel with other unit tests"
1 change: 1 addition & 0 deletions lib/src/cli/cli.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:path/path.dart' as p;
import 'package:universal_io/io.dart';

part 'dart_cli.dart';
part 'flutter_cli.dart';

/// Abstraction for running commands via command-line.
Expand Down
19 changes: 19 additions & 0 deletions lib/src/cli/dart_cli.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
part of 'cli.dart';

/// Dart CLI
class Dart {
/// Determine whether dart is installed
static Future<bool> installed() async {
try {
await _Cmd.run('dart', []);
return true;
} catch (_) {
return false;
}
}

/// Apply all fixes (`dart fix --apply`).
static Future<void> applyFixes() {
return _Cmd.run('dart', ['fix', '--apply']);
}
}
38 changes: 35 additions & 3 deletions lib/src/templates/template.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,21 @@ class DartPkgTemplate extends Template {
await Flutter.pubGet(cwd: outputDir.path);
installDependenciesDone();
}
final isDartInstalled = await Dart.installed();
if (isDartInstalled) {
final applyFixesDone = logger.progress(
'Running "dart fix --apply" in ${outputDir.path}',
);
await Dart.applyFixes();
applyFixesDone();
}
_logSummary(logger);
}

void _logSummary(Logger logger) {
logger
..info('\n')
..alert('Created a Very Good Dart package! 🦄')
..alert('Created a Very Good Dart Package! 🦄')
..info('\n');
}
}
Expand All @@ -84,13 +92,21 @@ class FlutterPkgTemplate extends Template {
await Flutter.packagesGet(cwd: outputDir.path);
installDependenciesDone();
}
final isDartInstalled = await Dart.installed();
if (isDartInstalled) {
final applyFixesDone = logger.progress(
'Running "dart fix --apply" in ${outputDir.path}',
);
await Dart.applyFixes();
applyFixesDone();
}
_logSummary(logger);
}

void _logSummary(Logger logger) {
logger
..info('\n')
..alert('Created a Very Good Flutter package! 🦄')
..alert('Created a Very Good Flutter Package! 🦄')
..info('\n');
}
}
Expand All @@ -117,13 +133,21 @@ class FlutterPluginTemplate extends Template {
await Flutter.packagesGet(cwd: outputDir.path, recursive: true);
installDependenciesDone();
}
final isDartInstalled = await Dart.installed();
if (isDartInstalled) {
final applyFixesDone = logger.progress(
'Running "dart fix --apply" in ${outputDir.path}',
);
await Dart.applyFixes();
applyFixesDone();
}
_logSummary(logger);
}

void _logSummary(Logger logger) {
logger
..info('\n')
..alert('Created a Very Good Flutter plugin! 🦄')
..alert('Created a Very Good Flutter Plugin! 🦄')
..info('\n');
}
}
Expand All @@ -150,6 +174,14 @@ class CoreTemplate extends Template {
await Flutter.packagesGet(cwd: outputDir.path);
installDependenciesDone();
}
final isDartInstalled = await Dart.installed();
if (isDartInstalled) {
final applyFixesDone = logger.progress(
'Running "dart fix --apply" in ${outputDir.path}',
);
await Dart.applyFixes();
applyFixesDone();
}
_logSummary(logger);
}

Expand Down
13 changes: 13 additions & 0 deletions test/e2e_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@Tags(['e2e'])
import 'package:io/io.dart';
import 'package:mason/mason.dart';
import 'package:mocktail/mocktail.dart';
Expand Down Expand Up @@ -56,6 +57,10 @@ void main() {
);
expect(result, equals(ExitCode.success.code));

await untilCalled(
() => logger.alert('Created a Very Good Dart Package! 🦄'),
);

final formatResult = await Process.run(
'flutter',
['format', '--set-exit-if-changed', '.'],
Expand Down Expand Up @@ -104,6 +109,10 @@ void main() {
);
expect(result, equals(ExitCode.success.code));

await untilCalled(
() => logger.alert('Created a Very Good Flutter Package! 🦄'),
);

final formatResult = await Process.run(
'flutter',
['format', '--set-exit-if-changed', '.'],
Expand Down Expand Up @@ -152,6 +161,10 @@ void main() {
);
expect(result, equals(ExitCode.success.code));

await untilCalled(
() => logger.alert('Created a Very Good Flutter App! 🦄'),
);

final formatResult = await Process.run(
'flutter',
['format', '--set-exit-if-changed', '.'],
Expand Down
18 changes: 18 additions & 0 deletions test/src/cli/dart_cli_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'package:test/test.dart';
import 'package:very_good_cli/src/cli/cli.dart';

void main() {
group('Dart', () {
group('.installed', () {
test('returns true when dart is installed', () {
expectLater(Dart.installed(), completion(isTrue));
});
});

group('.applyFixes', () {
test('completes normally', () {
expectLater(Dart.applyFixes(), completes);
});
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ name: example
''';

void main() {
group('Flutter CLI', () {
group('packages get', () {
group('Flutter', () {
group('.packagesGet', () {
test('throws when there is no pubspec.yaml', () {
expectLater(
Flutter.packagesGet(cwd: Directory.systemTemp.path),
Expand Down Expand Up @@ -59,7 +59,7 @@ void main() {
});
});

group('pub get', () {
group('.pubGet', () {
test('throws when there is no pubspec.yaml', () {
expectLater(
Flutter.pubGet(cwd: Directory.systemTemp.path),
Expand Down
6 changes: 3 additions & 3 deletions test/src/commands/create_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ void main() {
getPackagesMsg: 'Running "flutter pub get" in .tmp',
templateName: 'dart_pkg',
expectedBundle: dartPackageBundle,
expectedLogSummary: 'Created a Very Good Dart package! 🦄',
expectedLogSummary: 'Created a Very Good Dart Package! 🦄',
);
});

Expand All @@ -513,7 +513,7 @@ void main() {
getPackagesMsg: 'Running "flutter packages get" in .tmp',
templateName: 'flutter_pkg',
expectedBundle: flutterPackageBundle,
expectedLogSummary: 'Created a Very Good Flutter package! 🦄',
expectedLogSummary: 'Created a Very Good Flutter Package! 🦄',
);
});

Expand All @@ -522,7 +522,7 @@ void main() {
getPackagesMsg: 'Running "flutter packages get" in .tmp',
templateName: 'flutter_plugin',
expectedBundle: flutterPluginBundle,
expectedLogSummary: 'Created a Very Good Flutter plugin! 🦄',
expectedLogSummary: 'Created a Very Good Flutter Plugin! 🦄',
);
});
});
Expand Down