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
1 parent 482ea2b commit 22ade61
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 71 deletions.
12 changes: 10 additions & 2 deletions lib/src/cli/task_project_create.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,21 @@ 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
Expand Down
23 changes: 11 additions & 12 deletions lib/src/cli/task_project_init.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,21 @@ Future<void> _producerInit(

/// Download [_resourceZipUrl] and return the unzipped directory.
Future<Directory> _downloadResourcesZipOrThrow() async {
final zip = Directory.systemTemp.resolveFile("resources.zip")
..maybeDelete
..createSync(recursive: true);

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

..maybeCreate
..verifyDirectoryExists;
final zip = target.resolveFile("resources.zip")
..maybeDelete
..maybeCreate
..verifyFileExists;
await download(_resourceZipUrl, zip);
if (zip.existsSync()) {
await unzip(zip, target);
zip.deleteSync();
}
await unzip(zip, target);
zip.deleteSync();
target.verifyDirectoryExists;

if (!target.existsSync()) {
throw const KlutterException("Failed to download resources");
if(target.isEmpty) {
throw const KlutterException("Failed to download resources (no content found)");
}

return target;
Expand Down
2 changes: 2 additions & 0 deletions lib/src/common/utilities.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ extension FileUtil on FileSystemEntity {
ifNotExists((fse) {
if (fse is Directory) {
fse.createSync(recursive: true);
} else if (fse is File) {
fse.createSync(recursive: true);
}
});
return this;
Expand Down
135 changes: 78 additions & 57 deletions test/src/systemtest/e2e_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,27 @@ void main() {
reason: "can't run a task without a project",
);

final downloadFlutterResult = await run(["get", "flutter=3.10.6"]);
expect(
downloadFlutterResult.contains(
"Task 'TaskName.get flutter=3.10.6' finished successful"),
true,
reason: downloadFlutterResult);

final temp = Directory.systemTemp.resolveDirectory("foo")
..maybeDelete
..maybeCreate;
final cache = temp.kradleCache;
final cachedSdks = cache
.listSync()
.where((fte) => fte.path.contains("3.10.6"))
.toList();

expect(cachedSdks.isNotEmpty, true, reason: "there should be a cached flutter SDK");
final cachedSdk = Directory(cachedSdks.first.absolutePath);
expect(cachedSdk.existsSync(), true, reason: "the cached sdk should exist");
expect(cachedSdk.isEmpty, false, reason: "the cached sdk should not be empty");

/// Create Flutter plugin project.
final createResult = await createFlutterPlugin(
organisation: organisation,
Expand All @@ -69,68 +90,68 @@ void main() {
.absolutePath,
);

expect(createResult.contains("finished successful"), true);
expect(createResult.contains("finished successful"), true,
reason: createResult);
expect(producerPlugin.existsSync(), true,
reason:
"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(
Expand Down

0 comments on commit 22ade61

Please sign in to comment.