Skip to content

Commit

Permalink
Add gradle and flutter wrapper tasks to kradle script.
Browse files Browse the repository at this point in the history
  • Loading branch information
buijs-dev committed May 13, 2024
1 parent d259ffd commit 3b20bd0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
39 changes: 37 additions & 2 deletions lib/src/cli/runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,50 @@

import "dart:io";

import "../common/common.dart";
import "cli.dart";
import "context.dart";

/// Run the user command.
Future<String> run(List<String> args, [TaskService? taskServiceOrNull]) async {
Future<String> run(
List<String> args, {
Directory? workingDirectoryOrNull,
TaskService? taskServiceOrNull,
Executor? executor,
GetFlutterSDK? getFlutterSDK,
}) async {
final arguments = [...args];
final firstArgument = arguments.removeAt(0);
final taskName = firstArgument.toTaskNameOrNull;
final context = toContextOrNull(Directory.current, arguments);
final workingDirectory = workingDirectoryOrNull ?? Directory.current;
if (taskName == TaskName.gradle) {
print("executing gradle task...");
final gradlew =
workingDirectory.resolveFile("gradlew").verifyFileExists.absolutePath;
(executor ?? Executor())
..workingDirectory = workingDirectory
..arguments = arguments
..executable = gradlew
..run();
return "finished executing gradle task";
}

if (taskName == TaskName.flutter) {
print("executing flutter task...");
final flutterTask = getFlutterSDK ?? GetFlutterSDK();
final flutterResult =
await flutterTask.executeOrThrow(Context(workingDirectory, {}));
final flutter =
flutterResult.resolveFile("flutter/bin/flutter".normalize).absolutePath;
(executor ?? Executor())
..workingDirectory = workingDirectory
..arguments = arguments
..executable = flutter
..run();
return "finished executing flutter task";
}

final context = toContextOrNull(workingDirectory, arguments);
final taskService = taskServiceOrNull ?? TaskService();
if (firstArgument.toLowerCase() == "help") {
return taskService.displayKradlewHelpText;
Expand Down
2 changes: 1 addition & 1 deletion test/src/cli/runner_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void main() {
});

test("Verify invalid arguments are handled", () async {
final output = await run(["gradle", "blabla"]);
final output = await run(["create", "blabla"]);
expect(output.contains("received invalid task options: [blabla]"), true,
reason: output);
});
Expand Down
13 changes: 12 additions & 1 deletion test/src/systemtest/e2e_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void main() {
final help = await run([
"create",
"root=${Directory.systemTemp.absolutePath}",
], FakeTaskService());
], taskServiceOrNull: FakeTaskService());
expect(help.contains("Usage: kradlew <command> [option=value]"), true);

/// Run a Klutter task without an existing Flutter project
Expand Down Expand Up @@ -82,6 +82,11 @@ void main() {
expect(cachedSdk.isEmpty, false,
reason: "the cached sdk should not be empty");

/// Run flutter doctor to check flutter task
final flutterDoctor = await run(["flutter", "doctor"]);
expect(flutterDoctor.contains("finished executing flutter task"), true,
reason: flutterDoctor);

/// Create Flutter plugin project.
final createResult = await createKlutterPlugin(
organisation: organisation,
Expand Down Expand Up @@ -176,6 +181,12 @@ void main() {
true,
reason: "android/klutter/build.gradle.kts should exist");

/// Run gradlew tasks to check gradlew works
final gradlewTasks = await run(["gradle", "--help"],
workingDirectoryOrNull: producerPlugin);
expect(gradlewTasks.contains("finished executing gradle task"), true,
reason: gradlewTasks);

/// IOS/Klutter folder should be created.
expect(
Directory("${producerPlugin.absolutePath}/ios/Klutter".normalize)
Expand Down

0 comments on commit 3b20bd0

Please sign in to comment.