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/ruby_import.rb,
lib/isomorfeus/asset_manager/view_helper.rb,
lib/isomorfeus/asset_manager/rack_middleware.rb,
lib/isomorfeus/asset_manager/server_socket_processor.rb

Defined Under Namespace

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

Constant Summary collapse

VERSION =
'0.14.4'
@@app_common_imports =
false
@@app_web_imports =
false
@@app_ssr_imports =
false

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAssetManager

Returns a new instance of AssetManager.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/isomorfeus/asset_manager.rb', line 42

def initialize
  Isomorfeus.set_node_paths

  @tmpdir = 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

  @context = ExecJS.permissive_compile(init_js)

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

Class Method Details

.add_app_importsObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/isomorfeus/asset_manager.rb', line 7

def self.add_app_imports
  imports_path = File.expand_path(File.join(Isomorfeus.app_root, 'imports'))
  if Dir.exist?(imports_path)
    unless @@app_common_imports
      common_imports_file = File.join(imports_path, 'common.js')
      if File.exist?(common_imports_file)
        Isomorfeus.add_common_js_import(common_imports_file)
        @@app_common_imports = true
      end
    end
    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
    unless @@app_ssr_imports
      ssr_imports_file = File.join(imports_path, 'ssr.js')
      if File.exist?(ssr_imports_file)
        Isomorfeus.add_ssr_js_import(ssr_imports_file)
        @@app_ssr_imports
      end
    end
  end
end

.last_updatedObject



34
35
36
# File 'lib/isomorfeus/asset_manager.rb', line 34

def self.last_updated
  @last_updated
end

.last_updated=(l) ⇒ Object



38
39
40
# File 'lib/isomorfeus/asset_manager.rb', line 38

def self.last_updated=(l)
  @last_updated = l
end

Instance Method Details

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



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/isomorfeus/asset_manager.rb', line 58

def transition(asset_key, asset, analyze: false)
  return if !Isomorfeus.development? && asset.bundled?
  asset.mutex.synchronize do
    return if !Isomorfeus.development? && asset.bundled?
    return if Isomorfeus.development? && asset.bundled? && (self.class.last_updated.nil? || (asset.mtime > self.class.last_updated))
    asset.touch
    build_ruby_and_save(asset_key, asset)
    save_imports(asset_key, asset)
    run_esbuild(asset_key, asset, analyze)
    asset.bundle = bundled_asset(asset_key)
    asset.bundle_map = bundled_asset_map(asset_key) unless Isomorfeus.production?
    asset.css = bundled_css(asset_key)
    asset.css_map = bundled_css_map(asset_key) unless Isomorfeus.production?
  end
end