Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prompt installing for dependencies instead of exiting. #671

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion src/all.cr
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
require "baked_file_system"
require "ecr"
require "ansi-escapes"
require "file_utils"
require "colorize"
require "markd"
require "kemal"
require "uuid"
require "html"
require "json"
require "ecr"
require "xml"

MINT_ENV = {} of String => String
Expand Down
4 changes: 1 addition & 3 deletions src/builder.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 16 additions & 18 deletions src/mint_json.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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.print "#{WARNING} Missing dependencies..."
raise CliException.new
end
end
end

def terminal
Render::Terminal::STDOUT
end

def dependency_exists?(name : String)
Dir.exists?(".mint/packages/#{name}")
end
Expand Down
4 changes: 1 addition & 3 deletions src/reactor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/test_runner.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down