Skip to content

Commit

Permalink
Consolidate scripts to kradle:
Browse files Browse the repository at this point in the history
- Remove consumer script
- Remove producer script
- Add kradle script
- Remove script name from tasks
- Remove dependencies from tasks
- Update GH workflow to create native executable
  • Loading branch information
buijs-dev committed Apr 22, 2024
1 parent e5a9227 commit c4c27f4
Show file tree
Hide file tree
Showing 37 changed files with 914 additions and 1,475 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/native_executable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ jobs:
- name: Install dependencies
run: dart pub get
- name: Build executable
run: dart compile exe bin/kradle.dart -o ./kradlew
run: dart compile exe bin/kradle.dart -o kradlew
- uses: actions/upload-artifact@v4
with:
name: kradlew
path: ./kradlew.exe
name: kradlew-${{ matrix.os }}-${{ matrix.version }}
path: kradlew.exe
47 changes: 0 additions & 47 deletions bin/consumer.dart

This file was deleted.

31 changes: 24 additions & 7 deletions bin/kradle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import "dart:io";

import "package:args/command_runner.dart";
import "package:klutter/klutter.dart";
import "package:klutter/src/cli/context.dart";

/// Run kradle tasks.
Future<void> main(List<String> args) async {
Expand All @@ -34,12 +35,28 @@ Future<void> main(List<String> args) async {
"""
.ok);

final pathToRoot = Directory.current.absolutePath;
final result = await execute(
script: ScriptName.kradle,
pathToRoot: pathToRoot,
arguments: args,
);
if (args.isEmpty) {
// TODO start interactive mode
return;
}

print(result);
final arguments = [...args];
final firstArgument = arguments.removeAt(0);
final taskName = firstArgument.toTaskNameOrNull;
final taskOptions = toTaskOptionsOrNull(arguments);
if (firstArgument.toLowerCase() == "help") {
print(displayKradlewHelpText);
} else if (taskName == null) {
print("received unknown task name: $firstArgument");
print("use kradlew help for more information");
} else if (taskOptions == null) {
print("received invalid task options: $args");
print("use kradlew help for more information");
} else {
print(await execute(Context(
workingDirectory: Directory.current,
taskName: taskName,
taskOptions: taskOptions,
)));
}
}
47 changes: 0 additions & 47 deletions bin/producer.dart

This file was deleted.

75 changes: 25 additions & 50 deletions lib/src/cli/cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,80 +49,55 @@
library cli;

import "../common/utilities.dart";
import "command.dart";
import "input.dart";
import "task.dart";
import "context.dart";
import "task_service.dart" as service;

export "command.dart";
export "input.dart";
export "option.dart";
export "task.dart";
export "task_comparator.dart";
export "task_consumer_add.dart";
export "task_consumer_init.dart";
export "task_kradle_build.dart";
export "task_kradle_clean_cache.dart";
export "task_kradle_create.dart";
export "task_producer_get_flutter.dart";
export "task_producer_init.dart";
export "task_add.dart";
export "task_build.dart";
export "task_clean_cache.dart";
export "task_get_flutter.dart";
export "task_project_create.dart";
export "task_project_init.dart";
export "task_result.dart";
export "task_service.dart";

/// Main entrypoint for executing Klutter command line tasks.
Future<String> execute({
required ScriptName script,
required String pathToRoot,
required List<String> arguments,
}) async {
/// Parse user input to a Command.
final command = Command.from(
arguments: arguments,
script: script,
);

Future<String> execute(Context context) async {
/// Retrieve all tasks for the specified command.
///
/// Set is empty if command is null or task processing failed.
final tasks = command == null ? <Task>{} : service.tasksOrEmptyList(command);
final task = service.toTask(context);

/// When there are no tasks then the user input is incorrect.
///
/// Stop processing and print list of available tasks.
if (tasks.isEmpty) {
if (task == null) {
return """
|KLUTTER: Received invalid command.
|
|${service.printTasksAsCommands}
|${service.displayKradlewHelpText}
"""
.format
.nok;
}

/// Process all the given tasks.
else {
final s = command!.scriptName.name;
final t = command.taskName.name;
var o = "";

command.options.forEach((key, value) {
o += " ${key.name}=$value";
});
final t = context.taskName.name;
var o = "";

for (final task in tasks) {
final result = await task.execute(pathToRoot);
context.taskOptions.forEach((key, value) {
o += " ${key.name}=$value";
});

/// Stop executing tasks when one has failed.
if (!result.isOk) {
return """
|KLUTTER: ${result.message}
|KLUTTER: Task '$s $t$o' finished unsuccessfully."""
.format
.nok;
}
}

return "KLUTTER: Task '$s $t$o' finished successful.".format.ok;
}
final result = await task.execute(context);
return result.isOk
? "KLUTTER: Task '$t$o' finished successful.".format.ok
: """
|KLUTTER: ${result.message}
|KLUTTER: Task '$t$o' finished unsuccessfully."""
.format
.nok;
}

/// Output log message to console.
Expand Down
Loading

0 comments on commit c4c27f4

Please sign in to comment.