Class: OpalWebpackCompileServer::LoadPathManager

Inherits:
Object
  • Object
show all
Defined in:
lib/opal-webpack-loader/compile_server.rb

Class Method Summary collapse

Class Method Details

.get_load_path_entries(path) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/opal-webpack-loader/compile_server.rb', line 74

def self.get_load_path_entries(path)
  path_entries = []
  return [] unless Dir.exist?(path)
  dir_entries = Dir.entries(path)
  dir_entries.each do |entry|
    next if entry == '.'
    next if entry == '..'
    next unless entry
    absolute_path = File.join(path, entry)
    if File.directory?(absolute_path)
      more_path_entries = get_load_path_entries(absolute_path)
      path_entries.push(*more_path_entries) if more_path_entries.size > 0
    elsif (absolute_path.end_with?('.rb') || absolute_path.end_with?('.js')) && File.file?(absolute_path)
      path_entries.push(absolute_path)
    end
  end
  path_entries
end

.get_load_pathsObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/opal-webpack-loader/compile_server.rb', line 93

def self.get_load_paths
  load_paths = if File.exist?(File.join('bin', 'rails'))
                 %x{
                   bundle exec rails runner "puts (Rails.configuration.respond_to?(:assets) ? (Rails.configuration.assets.paths + Opal.paths).uniq : Opal.paths)"
                 }
               else
                 %x{
                   bundle exec ruby -e 'if File.exist?("app_loader.rb"); require "./app_loader.rb"; else; require "bundler/setup"; Bundler.require; set :run, false if defined? Sinatra; end; puts Opal.paths'
                 }
               end
  if $? == 0
    load_path_lines = load_paths.split("\n")
    load_path_lines.pop if load_path_lines.last == ''

    load_path_entries = []

    cwd = Dir.pwd

    load_path_lines.each do |path|
      next if path.start_with?(cwd)
      more_path_entries = get_load_path_entries(path)
      load_path_entries.push(*more_path_entries) if more_path_entries.size > 0
    end
    cache_obj = { 'opal_load_paths' => load_path_lines, 'opal_load_path_entries' => load_path_entries }
    Dir.mkdir(OpalWebpackCompileServer::OWL_CACHE_DIR) unless Dir.exist?(OpalWebpackCompileServer::OWL_CACHE_DIR)
    File.write(OpalWebpackCompileServer::OWL_LP_CACHE, Oj.dump(cache_obj, {}))
    load_path_lines
  else
    raise 'Error getting load paths!'
    exit(2)
  end
end