Class: Shakapacker::Commands
- Inherits:
-
Object
- Object
- Shakapacker::Commands
- Defined in:
- sig/shakapacker/commands.rbs,
lib/shakapacker/commands.rb
Overview
Build operation commands for Shakapacker
Instance Method Summary collapse
-
#bootstrap ⇒ void
Creates the default configuration files and directory structure.
-
#clean(count = 2, age = 3600) ⇒ Boolean
Cleanup old assets in the compile directory.
-
#clobber ⇒ void
Removes all compiled packs.
-
#compile ⇒ Boolean
Compiles all webpack/rspack packs.
-
#compiler ⇒ Compiler
Returns the compiler instance.
-
#config ⇒ Configuration
Returns the configuration object.
- #current_version ⇒ Array[String]
-
#initialize(instance) ⇒ Commands
constructor
Creates a new commands instance.
-
#logger ⇒ ActiveSupport::TaggedLogging
Returns the logger instance.
-
#manifest ⇒ Manifest
Returns the manifest instance.
- #packs ⇒ Array[String]
Constructor Details
#initialize(instance) ⇒ Commands
Creates a new commands instance
4 5 6 |
# File 'sig/shakapacker/commands.rbs', line 4 def initialize(instance) @instance = instance end |
Instance Method Details
#bootstrap ⇒ void
This method returns an undefined value.
Creates the default configuration files and directory structure
13 14 15 |
# File 'sig/shakapacker/commands.rbs', line 13 def bootstrap manifest.refresh end |
#clean(count = 2, age = 3600) ⇒ Boolean
Cleanup old assets in the compile directory
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/shakapacker/commands.rb', line 18 def clean(count = 2, age = 3600) if config.public_output_path.exist? && config.manifest_path.exist? packs .map do |paths| paths.map { |path| [Time.now - File.mtime(path), path] } .sort .reject.with_index do |(file_age, _), index| file_age < age || index < count end .map { |_, path| path } end .flatten .compact .each do |file| if File.file?(file) File.delete(file) logger.info "Removed #{file}" end end end true end |
#clobber ⇒ void
This method returns an undefined value.
Removes all compiled packs
10 11 12 13 |
# File 'sig/shakapacker/commands.rbs', line 10 def clobber config.public_output_path.rmtree if config.public_output_path.exist? config.cache_path.rmtree if config.cache_path.exist? end |
#compile ⇒ Boolean
Compiles all webpack/rspack packs
16 17 18 19 20 |
# File 'sig/shakapacker/commands.rbs', line 16 def compile compiler.compile.tap do |success| manifest.refresh if success end end |
#compiler ⇒ Compiler
Returns the compiler instance
22 |
# File 'sig/shakapacker/commands.rbs', line 22
def compiler: () -> Compiler
|
#config ⇒ Configuration
Returns the configuration object
19 |
# File 'sig/shakapacker/commands.rbs', line 19
def config: () -> Configuration
|
#current_version ⇒ Array[String]
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/shakapacker/commands.rb', line 69 def current_version packs = manifest.refresh.values.map do |value| value = value["src"] if value.is_a?(Hash) next unless value.is_a?(String) File.join(config.root_path, "public", "#{value}*") end.compact Dir.glob(packs).uniq end |
#logger ⇒ ActiveSupport::TaggedLogging
Returns the logger instance
28 |
# File 'sig/shakapacker/commands.rbs', line 28
def logger: () -> ActiveSupport::TaggedLogging
|
#manifest ⇒ Manifest
Returns the manifest instance
25 |
# File 'sig/shakapacker/commands.rbs', line 25
def manifest: () -> Manifest
|
#packs ⇒ Array[String]
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/shakapacker/commands.rb', line 58 def packs all_files = Dir.glob("#{config.public_output_path}/**/*") manifest_config = Dir.glob("#{config.manifest_path}*") packs = all_files - manifest_config - current_version packs.reject { |file| File.directory?(file) }.group_by do |path| base, _, ext = File.basename(path).scan(/(.*)(-[\da-f]+)([.\w]+)/).flatten "#{File.dirname(path)}/#{base}#{ext}" end.values end |