Class: Railpack::Manifest::Sprockets
- Inherits:
-
Object
- Object
- Railpack::Manifest::Sprockets
- Defined in:
- lib/railpack/manifest.rb
Overview
Sprockets manifest generator for Rails < 7. Creates a detailed manifest with digested filenames and asset mappings.
Class Method Summary collapse
Class Method Details
.generate(config) ⇒ Object
45 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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/railpack/manifest.rb', line 45 def self.generate(config) outdir = config['outdir'] return unless outdir && Dir.exist?(outdir) manifest = { 'files' => {}, 'assets' => {} } # Find built assets - Sprockets format Dir.glob("#{outdir}/**/*.{js,css}").each do |file| next unless File.file?(file) relative_path = Pathname.new(file).relative_path_from(Pathname.new(outdir)).to_s # Generate digest for Sprockets format digest = Digest::MD5.file(file).hexdigest logical_path = relative_path # Map logical names (Sprockets style) - only for application files if relative_path.include?('application') && relative_path.end_with?('.js') manifest['assets']['application.js'] = "#{digest}-#{File.basename(relative_path)}" logical_path = 'application.js' elsif relative_path.include?('application') && relative_path.end_with?('.css') manifest['assets']['application.css'] = "#{digest}-#{File.basename(relative_path)}" logical_path = 'application.css' else # For non-application files, still add to files but not to assets mapping logical_path = relative_path end # Add file entry for all files manifest['files']["#{digest}-#{File.basename(relative_path)}"] = { 'logical_path' => logical_path, 'pathname' => relative_path, 'digest' => digest, 'size' => File.size(file), 'mtime' => File.mtime(file).iso8601 } end # Write manifest for Sprockets (Rails < 7) manifest_path = "#{outdir}/.sprockets-manifest-#{Digest::MD5.hexdigest(outdir)}.json" File.write(manifest_path, JSON.pretty_generate(manifest)) Railpack.logger.debug "📄 Generated Sprockets manifest: #{manifest_path}" end |