Class: Hanami::CLI::Commands::App::Assets::Command Private

Inherits:
Command show all
Defined in:
lib/hanami/cli/commands/app/assets/command.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Base class for assets commands.

Finds slices with assets present (anything in an assets/ dir), then forks a child process for each slice to run the assets command (config/assets.js) for the slice.

Prefers the slice's own config/assets.js if present, otherwise falls back to the app-level file.

Passes --path and --dest arguments to this command to compile assets for the given slice only and save them into a dedicated directory (public/assets/ for the app, public/[slice_name]/ for slices).

See Also:

Since:

  • 2.1.0

Direct Known Subclasses

Compile, Watch

Constant Summary

Constants inherited from Command

Command::ACTION_SEPARATOR

Instance Method Summary collapse

Methods inherited from Command

#app, #database, #database_config, inherited, #measure, #run_command

Methods inherited from Hanami::CLI::Command

new

Constructor Details

#initialize(out:, err:, config: app.config.assets, system_call: InteractiveSystemCall.new(out: out, err: err, exit_after: false), **opts) ⇒ Command

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Command.

Since:

  • 2.1.0



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/hanami/cli/commands/app/assets/command.rb', line 32

def initialize(
  out:, err:,
  config: app.config.assets,
  system_call: InteractiveSystemCall.new(out: out, err: err, exit_after: false),
  **opts
)
  super(out: out, err: err, **opts)

  @config = config
  @system_call = system_call
end

Instance Method Details

#callObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.1.0



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/hanami/cli/commands/app/assets/command.rb', line 46

def call(**)
  slices = slices_with_assets

  if slices.empty?
    out.puts "No assets found."
    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
    pids.each do |pid|
      Process.kill("INT", pid)
    end
  end

  Process.waitall
end