From 36c09a6cc006b781f5ac9dbad1cb1474811c047a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szikszai=20Guszt=C3=A1v?= Date: Tue, 19 Sep 2023 09:37:08 +0200 Subject: [PATCH 1/2] Prompt installing for dependencies instead of exiting. --- shard.lock | 4 ++++ shard.yml | 3 +++ src/all.cr | 3 ++- src/builder.cr | 4 +--- src/mint_json.cr | 34 ++++++++++++++++------------------ src/reactor.cr | 4 +--- src/test_runner.cr | 4 +--- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/shard.lock b/shard.lock index b66752cf1..89edb8809 100644 --- a/shard.lock +++ b/shard.lock @@ -8,6 +8,10 @@ shards: git: https://github.com/crystal-ameba/ameba.git version: 1.5.0 + ansi-escapes: + git: https://github.com/gtramontina/ansi-escapes.cr.git + version: 1.0.0 + backtracer: git: https://github.com/sija/backtracer.cr.git version: 1.2.2 diff --git a/shard.yml b/shard.yml index f467a323c..7c9d56b3f 100644 --- a/shard.yml +++ b/shard.yml @@ -20,6 +20,9 @@ dependencies: markd: github: icyleaf/markd version: ~> 0.5.0 + ansi-escapes: + github: gtramontina/ansi-escapes.cr + version: ~> 1.0.0 development_dependencies: ameba: diff --git a/src/all.cr b/src/all.cr index 7e99791ce..93e7bbf4b 100644 --- a/src/all.cr +++ b/src/all.cr @@ -1,5 +1,5 @@ require "baked_file_system" -require "ecr" +require "ansi-escapes" require "file_utils" require "colorize" require "markd" @@ -7,6 +7,7 @@ require "kemal" require "uuid" require "html" require "json" +require "ecr" require "xml" MINT_ENV = {} of String => String diff --git a/src/builder.cr b/src/builder.cr index ae2492968..bb8939ca8 100644 --- a/src/builder.cr +++ b/src/builder.cr @@ -8,9 +8,7 @@ module Mint skip_icons = true end - terminal.measure "#{COG} Ensuring dependencies..." do - json.check_dependencies! - end + json.check_dependencies! terminal.measure "#{COG} Clearing the \"#{DIST_DIR}\" directory..." do FileUtils.rm_rf DIST_DIR diff --git a/src/mint_json.cr b/src/mint_json.cr index d9cb10e57..d3c03bb3b 100644 --- a/src/mint_json.cr +++ b/src/mint_json.cr @@ -1173,30 +1173,28 @@ module Mint def check_dependencies! dependencies.each do |dependency| next if dependency_exists?(dependency.name) - error! :mint_json_dependency_not_installed do - block do - text "Not all" - bold "dependencies" - text "in your mint.json file are installed." - end - block do - text "The dependency" - bold dependency.name - text "was expected to be in the" - bold ".mint/packages/#{name}" - text "directory." - end + terminal.puts "#{COG} Ensuring dependencies..." + terminal.puts " ↳ Not all dependencies in your mint.json file are installed." + terminal.puts " Would you like to install them now? (Y/n)" - block do - text "Usually you can fix this by running the" - bold "mint install" - text "command." - end + answer = gets.to_s.downcase + terminal.puts AnsiEscapes::Erase.lines(2) + + if answer == "y" + Installer.new + break + else + terminal.puts "#{WARNING} Missing packages, exiting..." + exit(1) end end end + def terminal + Render::Terminal::STDOUT + end + def dependency_exists?(name : String) Dir.exists?(".mint/packages/#{name}") end diff --git a/src/reactor.cr b/src/reactor.cr index 90098f61f..1d722bd48 100644 --- a/src/reactor.cr +++ b/src/reactor.cr @@ -26,9 +26,7 @@ module Mint end def initialize(@host, @port, @auto_format, @live_reload) - terminal.measure "#{COG} Ensuring dependencies..." do - MintJson.parse_current.check_dependencies! - end + MintJson.parse_current.check_dependencies! workspace = Workspace.current workspace.format = auto_format diff --git a/src/test_runner.cr b/src/test_runner.cr index 21de06bd0..d8b377942 100644 --- a/src/test_runner.cr +++ b/src/test_runner.cr @@ -47,9 +47,7 @@ module Mint end def run : Bool - terminal.measure "#{COG} Ensuring dependencies..." do - MintJson.parse_current.check_dependencies! - end + MintJson.parse_current.check_dependencies! ast = terminal.measure "#{COG} Compiling tests..." do compile_ast.tap do |a| From 3f5d46c1c04aa4e7cf5c73d346c1e6d1fb06f8ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szikszai=20Guszt=C3=A1v?= Date: Tue, 19 Sep 2023 09:44:50 +0200 Subject: [PATCH 2/2] Tweak error message. --- src/mint_json.cr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mint_json.cr b/src/mint_json.cr index d3c03bb3b..aad4d45c4 100644 --- a/src/mint_json.cr +++ b/src/mint_json.cr @@ -1185,8 +1185,8 @@ module Mint Installer.new break else - terminal.puts "#{WARNING} Missing packages, exiting..." - exit(1) + terminal.print "#{WARNING} Missing dependencies..." + raise CliException.new end end end