Class: Isomorfeus::AssetManager

Inherits:
Object
  • Object
show all
Defined in:
lib/isomorfeus/asset_manager.rb,
lib/isomorfeus/asset_manager/asset.rb,
lib/isomorfeus/asset_manager/version.rb,
lib/isomorfeus/asset_manager/js_import.rb,
lib/isomorfeus/asset_manager/portfolio.rb,
lib/isomorfeus/asset_manager/node_asset.rb,
lib/isomorfeus/asset_manager/ruby_import.rb,
lib/isomorfeus/asset_manager/view_helper.rb,
lib/isomorfeus/asset_manager/browser_asset.rb,
lib/isomorfeus/asset_manager/rack_middleware.rb,
lib/isomorfeus/asset_manager/server_socket_processor.rb

Defined Under Namespace

Modules: ViewHelper Classes: Asset, BrowserAsset, JsImport, NodeAsset, Portfolio, RackMiddleware, RubyImport, ServerSocketProcessor

Constant Summary collapse

VERSION =
'0.19.7'
@@app_web_imports =
false

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAssetManager

Returns a new instance of AssetManager.



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/isomorfeus/asset_manager.rb', line 18

def initialize
  Isomorfeus.set_node_paths

  @tmpdir = File.expand_path(Isomorfeus.asset_manager_tmpdir)
  @imports_path = File.join(@tmpdir, 'imports')
  @output_path = File.join(@tmpdir, 'output')
  FileUtils.mkdir_p(@imports_path)
  FileUtils.mkdir_p(@output_path)
  @server_path = File.join(Isomorfeus.app_root, 'server')
  self.class.add_app_imports

  init_hmr_listener if Isomorfeus.development? && !Isomorfeus.hmr_listener
end

Class Method Details

.add_app_importsObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/isomorfeus/asset_manager.rb', line 5

def self.add_app_imports
  imports_path = File.expand_path(File.join(Isomorfeus.app_root, 'imports'))
  if Dir.exist?(imports_path)
    unless @@app_web_imports
      web_imports_file = File.join(imports_path, 'web.js')
      if File.exist?(web_imports_file)
        Isomorfeus.add_web_js_import(web_imports_file)
        @@app_web_imports = true
      end
    end
  end
end

Instance Method Details

#transition(asset_key, asset, analyze: false) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/isomorfeus/asset_manager.rb', line 32

def transition(asset_key, asset, analyze: false)
  return if asset.bundled?
  asset.mutex.synchronize do
    return if asset.bundled?
    start = Time.now
    print "Isomorfeus Asset Manager bundling #{asset_key}#{analyze ? ':' : ' ...'}"
    asset.touch
    asset_name = asset_key[0..-4]
    asset.build_ruby_and_save(asset_key, asset_name, @imports_path)
    entry = asset.save_entry(asset_key, asset_name, @imports_path)
    run_esbuild(entry, asset_key, asset, analyze)
    asset.bundle_css(asset_name, @output_path) if asset.browser?
    asset.bundle_js(asset_key, asset_name, @imports_path, @output_path)
    if !Isomorfeus.production? && asset.browser?
      asset.bundle_css_map(asset_name, @output_path)
      asset.bundle_js_map(asset_key, @output_path)
    end
    asset.bundled!
    puts "#{'bundling' if analyze} took #{Time.now - start}s"
  end
end