From 5bcb016ffac688e417e04020f8e203d3c4cc47ef Mon Sep 17 00:00:00 2001 From: Gillian <72627535+buijs-dev@users.noreply.github.com> Date: Fri, 10 May 2024 20:10:41 +0200 Subject: [PATCH] Check init and add library results during project create task and (re)throw exception if it fails. --- lib/src/cli/task_project_create.dart | 11 ++- lib/src/cli/task_project_init.dart | 4 +- test/src/systemtest/e2e_test.dart | 112 +++++++++++++-------------- 3 files changed, 67 insertions(+), 60 deletions(-) diff --git a/lib/src/cli/task_project_create.dart b/lib/src/cli/task_project_create.dart index a4a1fb1..b9bc0a3 100644 --- a/lib/src/cli/task_project_create.dart +++ b/lib/src/cli/task_project_create.dart @@ -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 diff --git a/lib/src/cli/task_project_init.dart b/lib/src/cli/task_project_init.dart index a3b1c86..14a5124 100644 --- a/lib/src/cli/task_project_init.dart +++ b/lib/src/cli/task_project_init.dart @@ -112,11 +112,11 @@ Future _producerInit( Future _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()) { diff --git a/test/src/systemtest/e2e_test.dart b/test/src/systemtest/e2e_test.dart index 88ddf6b..3930c27 100644 --- a/test/src/systemtest/e2e_test.dart +++ b/test/src/systemtest/e2e_test.dart @@ -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(