Skip to content

Commit

Permalink
Check init and add library results during project create task and (re…
Browse files Browse the repository at this point in the history
…)throw exception if it fails.
  • Loading branch information
buijs-dev committed May 10, 2024

Verified

This commit was signed with the committer’s verified signature.
johnbillion John Blackbourn
1 parent 482ea2b commit 5bcb016
Showing 3 changed files with 67 additions and 60 deletions.
11 changes: 9 additions & 2 deletions lib/src/cli/task_project_create.dart
Original file line number Diff line number Diff line change
@@ -124,13 +124,20 @@ class CreateProject extends Task {
TaskOption.flutter: flutterSDK,
});

await ProjectInit().execute(initContext);
final init = await ProjectInit().execute(initContext);
if(!init.isOk) {
throw KlutterException(init.message ?? "project init failed");
}

final addContext = context.copyWith(taskOptions: {
TaskOption.root: exampleFolder.absolutePath,
TaskOption.lib: name,
});

await AddLibrary().execute(addContext);
final addLibrary = await AddLibrary().execute(addContext);
if(!addLibrary.isOk) {
throw KlutterException(addLibrary.message ?? "adding library to example project failed");
}

exampleFolder
..deleteTestFolder
4 changes: 2 additions & 2 deletions lib/src/cli/task_project_init.dart
Original file line number Diff line number Diff line change
@@ -112,11 +112,11 @@ Future<void> _producerInit(
Future<Directory> _downloadResourcesZipOrThrow() async {
final zip = Directory.systemTemp.resolveFile("resources.zip")
..maybeDelete
..createSync(recursive: true);
..maybeCreate;

final target = Directory.systemTemp.resolveDirectory("resources_unpacked")
..maybeDelete
..createSync(recursive: true);
..maybeCreate;

await download(_resourceZipUrl, zip);
if (zip.existsSync()) {
112 changes: 56 additions & 56 deletions test/src/systemtest/e2e_test.dart
Original file line number Diff line number Diff line change
@@ -75,62 +75,62 @@ void main() {
"Plugin should be created in: '${producerPlugin.absolute.path}'");

/// Gradle files should be copied to root folder.
// final gradlew = File("${producerPlugin.absolutePath}/gradlew".normalize);
// expect(gradlew.existsSync(),
// true,
// reason: "${gradlew.absolutePath} should exist");
// expect(
// File("${producerPlugin.absolutePath}/gradlew.bat".normalize)
// .existsSync(),
// true,
// reason: "root/gradlew.bat should exist");
// expect(
// File("${producerPlugin.absolutePath}/gradle.properties".normalize)
// .existsSync(),
// true,
// reason: "root/gradle.properties should exist");
// expect(
// File("${producerPlugin.absolutePath}/gradle/wrapper/gradle-wrapper.jar"
// .normalize)
// .existsSync(),
// true,
// reason: "root/gradle/wrapper/gradle-wrapper.jar should exist");
// expect(
// File("${producerPlugin.absolutePath}/gradle/wrapper/gradle-wrapper.properties"
// .normalize)
// .existsSync(),
// true,
// reason: "root/gradle/wrapper/gradle-wrapper.properties should exist");
//
// /// Gradle files should be copied to android folder.
// expect(
// File("${producerPlugin.absolutePath}/android/gradlew".normalize)
// .existsSync(),
// true,
// reason: "root/gradlew should exist");
// expect(
// File("${producerPlugin.absolutePath}/android/gradlew.bat".normalize)
// .existsSync(),
// true,
// reason: "root/gradlew.bat should exist");
// expect(
// File("${producerPlugin.absolutePath}/android/gradle.properties"
// .normalize)
// .existsSync(),
// true,
// reason: "root/gradle.properties should exist");
// expect(
// File("${producerPlugin.absolutePath}/android/gradle/wrapper/gradle-wrapper.jar"
// .normalize)
// .existsSync(),
// true,
// reason: "root/gradle/wrapper/gradle-wrapper.jar should exist");
// expect(
// File("${producerPlugin.absolutePath}/android/gradle/wrapper/gradle-wrapper.properties"
// .normalize)
// .existsSync(),
// true,
// reason: "root/gradle/wrapper/gradle-wrapper.properties should exist");
final gradlew = File("${producerPlugin.absolutePath}/gradlew".normalize);
expect(gradlew.existsSync(),
true,
reason: "${gradlew.absolutePath} should exist");
expect(
File("${producerPlugin.absolutePath}/gradlew.bat".normalize)
.existsSync(),
true,
reason: "root/gradlew.bat should exist");
expect(
File("${producerPlugin.absolutePath}/gradle.properties".normalize)
.existsSync(),
true,
reason: "root/gradle.properties should exist");
expect(
File("${producerPlugin.absolutePath}/gradle/wrapper/gradle-wrapper.jar"
.normalize)
.existsSync(),
true,
reason: "root/gradle/wrapper/gradle-wrapper.jar should exist");
expect(
File("${producerPlugin.absolutePath}/gradle/wrapper/gradle-wrapper.properties"
.normalize)
.existsSync(),
true,
reason: "root/gradle/wrapper/gradle-wrapper.properties should exist");

/// Gradle files should be copied to android folder.
expect(
File("${producerPlugin.absolutePath}/android/gradlew".normalize)
.existsSync(),
true,
reason: "root/gradlew should exist");
expect(
File("${producerPlugin.absolutePath}/android/gradlew.bat".normalize)
.existsSync(),
true,
reason: "root/gradlew.bat should exist");
expect(
File("${producerPlugin.absolutePath}/android/gradle.properties"
.normalize)
.existsSync(),
true,
reason: "root/gradle.properties should exist");
expect(
File("${producerPlugin.absolutePath}/android/gradle/wrapper/gradle-wrapper.jar"
.normalize)
.existsSync(),
true,
reason: "root/gradle/wrapper/gradle-wrapper.jar should exist");
expect(
File("${producerPlugin.absolutePath}/android/gradle/wrapper/gradle-wrapper.properties"
.normalize)
.existsSync(),
true,
reason: "root/gradle/wrapper/gradle-wrapper.properties should exist");

/// Root build.gradle file should be created.
expect(

0 comments on commit 5bcb016

Please sign in to comment.