From 66510daa853ba966788a190315db0165e742276c Mon Sep 17 00:00:00 2001 From: Kilian Schulte Date: Fri, 4 Oct 2024 19:12:45 +0200 Subject: [PATCH] delete dummy index.html file when build is aborted --- .../lib/src/commands/build_command.dart | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/jaspr_cli/lib/src/commands/build_command.dart b/packages/jaspr_cli/lib/src/commands/build_command.dart index af1fd304..373c8e00 100644 --- a/packages/jaspr_cli/lib/src/commands/build_command.dart +++ b/packages/jaspr_cli/lib/src/commands/build_command.dart @@ -80,20 +80,26 @@ class BuildCommand extends BaseCommand with ProxyHelper, FlutterHelper { entryPoint = await getEntryPoint(argResults!['input']); } - if (await dir.exists()) { - await dir.delete(recursive: true); + if (dir.existsSync()) { + dir.deleteSync(recursive: true); } - await webDir.create(recursive: true); + webDir.createSync(recursive: true); var indexHtml = File('web/index.html').absolute; var targetIndexHtml = File('${webDir.path}/index.html').absolute; var dummyIndex = false; var dummyTargetIndex = false; - if (config!.usesFlutter && !await indexHtml.exists()) { + if (config!.usesFlutter && !indexHtml.existsSync()) { dummyIndex = true; dummyTargetIndex = true; - await indexHtml.create(); + indexHtml + ..createSync() + ..writeAsStringSync( + 'This file (web/index.html) should not exist. If you see this message something went wrong during "jaspr build". Simply delete the file.'); + guardResource(() { + if (indexHtml.existsSync()) indexHtml.deleteSync(); + }); } var webResult = _buildWeb(); @@ -210,9 +216,9 @@ class BuildCommand extends BaseCommand with ProxyHelper, FlutterHelper { await flutterResult; if (dummyIndex) { - await indexHtml.delete(); - if (dummyTargetIndex && await targetIndexHtml.exists()) { - await targetIndexHtml.delete(); + if (indexHtml.existsSync()) indexHtml.deleteSync(); + if (dummyTargetIndex && targetIndexHtml.existsSync()) { + targetIndexHtml.deleteSync(); } }