Skip to content

Commit

Permalink
Merge branch 'main' into use-js-extension-for-config-assets-file
Browse files Browse the repository at this point in the history
  • Loading branch information
timriley authored Nov 6, 2023
2 parents c8b3294 + 6f91d15 commit c3b9ea5
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 35 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Hanami Command Line Interface
- [Tim Riley] Set `"type": "module"` in package.json, enabling ES modules by default
- [Tim Riley] Rename `config/assets.mjs` to `config/assets.js` (use a plain `.js` file extension)

### Fixed

- [Tim Riley] Use correct helper names in generated app layout

## v2.1.0.rc1 - 2023-11-01

### Added
Expand Down
14 changes: 0 additions & 14 deletions lib/hanami/cli/commands/app/assets/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,6 @@ def cmd_with_args
[config.package_manager_run_command, "assets"]
end

# @since 2.1.0
# @api private
def entry_points
config.entry_points.map do |entry_point|
escape(entry_point)
end.join(" ")
end

# @since 2.1.0
# @api private
def destination
escape(config.destination)
end

# @since 2.1.0
# @api private
def escape(str)
Expand Down
2 changes: 1 addition & 1 deletion lib/hanami/cli/commands/app/assets/compile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def cmd_with_args

if config.subresource_integrity.any?
result << "--"
result << "--sri=#{config.subresource_integrity.join(',')}"
result << "--sri=#{escape(config.subresource_integrity.join(','))}"
end

result
Expand Down
29 changes: 25 additions & 4 deletions lib/hanami/cli/commands/app/generate/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,25 @@ class Action < App::Command
DEFAULT_SKIP_VIEW = false
private_constant :DEFAULT_SKIP_VIEW

DEFAULT_SKIP_TESTS = false
private_constant :DEFAULT_SKIP_TESTS

argument :name, required: true, desc: "Action name"
option :url, required: false, type: :string, desc: "Action URL"
option :http, required: false, type: :string, desc: "Action HTTP method"
# option :format, required: false, type: :string, default: DEFAULT_FORMAT, desc: "Template format"
option :skip_view, required: false, type: :boolean, default: DEFAULT_SKIP_VIEW,
desc: "Skip view and template generation"
option \
:skip_view,
required: false,
type: :boolean,
default: DEFAULT_SKIP_VIEW,
desc: "Skip view and template generation"
option \
:skip_tests,
required: false,
type: :boolean,
default: DEFAULT_SKIP_TESTS,
desc: "Skip test generation"
option :slice, required: false, desc: "Slice name"

# rubocop:disable Layout/LineLength
Expand Down Expand Up @@ -60,8 +73,16 @@ def initialize(fs: Hanami::CLI::Files.new, inflector: Dry::Inflector.new,

# @since 2.0.0
# @api private
def call(name:, url: nil, http: nil, format: DEFAULT_FORMAT, skip_view: DEFAULT_SKIP_VIEW, slice: nil,
context: nil, **)
def call(
name:,
url: nil,
http: nil,
format: DEFAULT_FORMAT,
skip_view: DEFAULT_SKIP_VIEW,
skip_tests: DEFAULT_SKIP_TESTS, # rubocop:disable Lint/UnusedMethodArgument
slice: nil,
context: nil, **
)
slice = inflector.underscore(Shellwords.shellescape(slice)) if slice
name = naming.action_name(name)
*controller, action = name.split(ACTION_SEPARATOR)
Expand Down
11 changes: 10 additions & 1 deletion lib/hanami/cli/commands/app/generate/part.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,17 @@ module Generate
# @since 2.1.0
# @api private
class Part < App::Command
DEFAULT_SKIP_TESTS = false
private_constant :DEFAULT_SKIP_TESTS

argument :name, required: true, desc: "Part name"
option :slice, required: false, desc: "Slice name"
option \
:skip_tests,
required: false,
type: :boolean,
default: DEFAULT_SKIP_TESTS,
desc: "Skip test generation"

example [
%(book (MyApp::Views::Parts::Book)),
Expand All @@ -36,7 +45,7 @@ def initialize(

# @since 2.0.0
# @api private
def call(name:, slice: nil, **)
def call(name:, slice: nil, skip_tests: DEFAULT_SKIP_TESTS, **) # rubocop:disable Lint/UnusedMethodArgument
slice = inflector.underscore(Shellwords.shellescape(slice)) if slice

generator.call(app.namespace, name, slice)
Expand Down
2 changes: 1 addition & 1 deletion lib/hanami/cli/generators/app/slice/app_layout.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%= humanized_app_name %> - <%= humanized_slice_name %></title>
<%- if bundled_assets? -%>
<%%= favicon %>
<%%= favicon_tag %>
<%= stylesheet_erb_tag %>
<%- end -%>
</head>
Expand Down
4 changes: 2 additions & 2 deletions lib/hanami/cli/generators/app/slice_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ def humanized_slice_name
# @since 2.1.0
# @api private
def stylesheet_erb_tag
%(<%= css "#{slice}/app" %>)
%(<%= stylesheet_tag "#{slice}/app" %>)
end

# @since 2.1.0
# @api private
def javascript_erb_tag
%(<%= js "#{slice}/app" %>)
%(<%= javascript_tag "#{slice}/app" %>)
end

private
Expand Down
6 changes: 3 additions & 3 deletions lib/hanami/cli/generators/gem/app/app_layout.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%= humanized_app_name %></title>
<%- if generate_assets? -%>
<%%= favicon %>
<%%= css "app" %>
<%%= favicon_tag %>
<%%= stylesheet_tag "app" %>
<%- end -%>
</head>
<body>
<%%= yield %>
<%- if generate_assets? -%>
<%%= js "app" %>
<%%= javascript_tag "app" %>
<%- end -%>
</body>
</html>
6 changes: 3 additions & 3 deletions lib/hanami/cli/generators/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Version
# @since 2.0.0
# @api private
def self.version
return Hanami::VERSION if defined?(Hanami::VERSION)
return Hanami::VERSION if Hanami.const_defined?(:VERSION)

Hanami::CLI::VERSION
end
Expand All @@ -32,7 +32,7 @@ def self.npm_package_requirement
if prerelease?
result = result
.sub(/\.(alpha|beta|rc)/, '-\1')
.sub(/(alpha|beta|rc)(.+)\.(.+)$/, '\1.\2')
.sub(/(alpha|beta|rc)(\d+)(?:\.\d+)?\Z/, '\1.\2')
end

"^#{result}"
Expand All @@ -41,7 +41,7 @@ def self.npm_package_requirement
# @since 2.0.0
# @api private
def self.prerelease?
version =~ /alpha|beta|rc/
version.match?(/alpha|beta|rc/)
end

# @example
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/hanami/cli/commands/app/generate/slice_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ module Helpers
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>#{inflector.humanize(app)} - #{inflector.humanize(slice)}</title>
<%= favicon %>
<%= css "#{slice}/app" %>
<%= favicon_tag %>
<%= stylesheet_tag "#{slice}/app" %>
</head>
<body>
<%= yield %>
<%= js "#{slice}/app" %>
<%= javascript_tag "#{slice}/app" %>
</body>
</html>
ERB
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/hanami/cli/commands/gem/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,12 @@ module Helpers
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>#{inflector.humanize(app)}</title>
<%= favicon %>
<%= css "app" %>
<%= favicon_tag %>
<%= stylesheet_tag "app" %>
</head>
<body>
<%= yield %>
<%= js "app" %>
<%= javascript_tag "app" %>
</body>
</html>
ERB
Expand Down
104 changes: 104 additions & 0 deletions spec/unit/hanami/cli/generators/version_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# frozen_string_literal: true

RSpec.describe Hanami::CLI::Generators::Version do
describe ".version" do
context "when Hanami::VERSION is defined" do
it "returns Hanami::VERSION" do
stub_const("Hanami::VERSION", "2.0.0")
expect(described_class.version).to eq("2.0.0")
end
end

context "when Hanami::VERSION is NOT defined" do
before do
allow(Hanami).to receive(:const_defined?).with(:VERSION).and_return(false)
end

xit "returns Hanami::CLI::VERSION" do
stub_const("Hanami::CLI::VERSION", "2.0.1")
expect(described_class.version).to eq("2.0.1")
end
end
end

describe ".gem_requirement" do
context "when prerelease version" do
before do
allow(described_class).to receive(:prerelease?).and_return(true)
allow(described_class).to receive(:prerelease_version).and_return("2.0.0.alpha")
end

it "returns the prerelease version requirement" do
expect(described_class.gem_requirement).to eq("~> 2.0.0.alpha")
end
end

context "when stable version" do
before do
allow(described_class).to receive(:prerelease?).and_return(false)
allow(described_class).to receive(:stable_version).and_return("2.0")
end

it "returns the stable version requirement" do
expect(described_class.gem_requirement).to eq("~> 2.0")
end
end
end

describe ".npm_package_requirement" do
context "when prerelease version" do
it "formats the alpha version string for npm" do
allow(described_class).to receive(:version).and_return("2.1.0.alpha8.1")
expect(described_class.npm_package_requirement).to eq("^2.1.0-alpha.8")
end

it "formats the beta version string for npm" do
allow(described_class).to receive(:version).and_return("2.1.0.beta2")
expect(described_class.npm_package_requirement).to eq("^2.1.0-beta.2")
end

it "formats the rc version string for npm" do
allow(described_class).to receive(:version).and_return("2.1.0.rc1")
expect(described_class.npm_package_requirement).to eq("^2.1.0-rc.1")
end
end

context "when stable version" do
it "formats the stable version string for npm" do
allow(described_class).to receive(:version).and_return("2.1.0")
expect(described_class.npm_package_requirement).to eq("^2.1.0")
end

it "formats the stable version string (with tiny patch) for npm" do
allow(described_class).to receive(:version).and_return("2.1.0.1")
expect(described_class.npm_package_requirement).to eq("^2.1.0.1")
end
end
end

describe ".prerelease?" do
it "returns true for prerelease version" do
allow(described_class).to receive(:version).and_return("2.1.0.beta2.1")
expect(described_class.prerelease?).to be true
end

it "returns false for stable version" do
allow(described_class).to receive(:version).and_return("2.1.0")
expect(described_class.prerelease?).to be false
end
end

describe ".stable_version" do
it "returns the major and minor version" do
allow(described_class).to receive(:version).and_return("2.1.0")
expect(described_class.stable_version).to eq("2.1")
end
end

describe ".prerelease_version" do
it "returns the version without the last digit group" do
allow(described_class).to receive(:version).and_return("2.0.0.alpha8.1")
expect(described_class.prerelease_version).to eq("2.0.0.alpha")
end
end
end

0 comments on commit c3b9ea5

Please sign in to comment.