Skip to content

Commit

Permalink
Exit early with an error if assets config missing
Browse files Browse the repository at this point in the history
  • Loading branch information
timriley committed Feb 8, 2024
1 parent 0e0c564 commit 0e763e5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Lint/DuplicateBranch:
Lint/EmptyFile:
Exclude:
- 'spec/fixtures/**/*.rb'
Lint/NonLocalExitFromIterator:
Enabled: false
Naming/HeredocDelimiterNaming:
Enabled: false
Naming/MethodParameterName:
Expand Down
17 changes: 13 additions & 4 deletions lib/hanami/cli/commands/app/assets/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ def call(**)
return
end

slices.each do |slice|
unless assets_config(slice)
out.puts "No assets config found for #{slice}. Please create a config/assets.js."
return
end
end

pids = slices_with_assets.map { |slice| fork_child_assets_command(slice) }

Signal.trap("INT") do
Expand Down Expand Up @@ -88,17 +95,19 @@ def slice_assets?(slice)
slice.root.join("assets").directory?
end

# Returns the path to the assets config (`config/assets.js`) for the given slice.
#
# Prefers a config file local to the slice, otherwise falls back to app-level config.
# Returns nil if no config can be found.
#
# @since 2.1.0
# @api private
def assets_config(slice)
config = slice.root.join("config", "assets.js")
return config if config.exist?

config = slice.app.root.join("config", "assets.js")
return config if config.exist?

# TODO: real error
raise "no asset config found"
config if config.exist?
end

# @since 2.1.0
Expand Down
15 changes: 15 additions & 0 deletions spec/unit/hanami/cli/commands/app/assets/compile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,19 @@ def before_prepare
compile_command.call
end
end

describe "missing config/asset.js" do
def before_prepare
write "assets/.keep", ""
FileUtils.rm_f "config/assets.js"
end

it "prints an error message" do
expect(interactive_system_call).not_to receive(:call)

compile_command.call

expect(output).to eq "No assets config found for TestApp::App. Please create a config/assets.js.\n"
end
end
end

0 comments on commit 0e763e5

Please sign in to comment.