Module: EmberCli

Defined in:
lib/ember_cli.rb

Class Method Summary collapse

Class Method Details

.assetsObject



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
33
34
35
36
37
38
39
# File 'lib/ember_cli.rb', line 8

def self.assets
  @assets ||=
    begin
      assets = %w[
        discourse.js
        admin.js
        wizard.js
        ember_jquery.js
        markdown-it-bundle.js
        start-discourse.js
        vendor.js
      ]
      assets +=
        Dir.glob("app/assets/javascripts/discourse/scripts/*.js").map { |f| File.basename(f) }

      if workbox_dir_name
        assets +=
          Dir
            .glob("app/assets/javascripts/discourse/dist/assets/#{workbox_dir_name}/*")
            .map { |f| "#{workbox_dir_name}/#{File.basename(f)}" }
      end

      Discourse
        .find_plugin_js_assets(include_disabled: true)
        .each do |file|
          next if file.ends_with?("_extra") # these are still handled by sprockets
          assets << "#{file}.js"
        end

      assets
    end
end

.dist_dirObject



4
5
6
# File 'lib/ember_cli.rb', line 4

def self.dist_dir
  "#{Rails.root}/app/assets/javascripts/discourse/dist"
end

.ember_versionObject



70
71
72
73
74
75
76
77
# File 'lib/ember_cli.rb', line 70

def self.ember_version
  @version ||=
    begin
      ember_source_package_raw =
        File.read("#{Rails.root}/app/assets/javascripts/node_modules/ember-source/package.json")
      JSON.parse(ember_source_package_raw)["version"]
    end
end

.has_tests?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/ember_cli.rb', line 107

def self.has_tests?
  File.exist?("#{dist_dir}/tests/index.html")
end

.is_ember_cli_asset?(name) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/ember_cli.rb', line 66

def self.is_ember_cli_asset?(name)
  assets.include?(name) || script_chunks.values.flatten.include?(name.delete_suffix(".js"))
end

.parse_chunks_from_html(html) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/ember_cli.rb', line 88

def self.parse_chunks_from_html(html)
  doc = Nokogiri::HTML5.parse(html)

  chunk_infos = {}

  doc
    .css("discourse-chunked-script")
    .each do |discourse_script|
      entrypoint = discourse_script.attr("entrypoint")
      chunk_infos[entrypoint] = discourse_script
        .css("script[src]")
        .map do |script|
          script.attr("src").delete_prefix("#{Discourse.base_path}/assets/").delete_suffix(".js")
        end
    end

  chunk_infos
end

.parse_source_map_path(file) ⇒ Object



62
63
64
# File 'lib/ember_cli.rb', line 62

def self.parse_source_map_path(file)
  File.read("#{dist_dir}/assets/#{file}")[%r{//# sourceMappingURL=(.*)$}, 1]
end

.script_chunksObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ember_cli.rb', line 41

def self.script_chunks
  return @@chunk_infos if defined?(@@chunk_infos)

  chunk_infos = {}

  begin
    test_html = File.read("#{dist_dir}/tests/index.html")
    chunk_infos.merge! parse_chunks_from_html(test_html)
  rescue Errno::ENOENT
    # production build
  end

  index_html = File.read("#{dist_dir}/index.html")
  chunk_infos.merge! parse_chunks_from_html(index_html)

  @@chunk_infos = chunk_infos if Rails.env.production?
  chunk_infos
rescue Errno::ENOENT
  {}
end

.workbox_dir_nameObject



79
80
81
82
83
84
85
86
# File 'lib/ember_cli.rb', line 79

def self.workbox_dir_name
  return @workbox_base_dir if defined?(@workbox_base_dir)

  @workbox_base_dir =
    if (full_path = Dir.glob("app/assets/javascripts/discourse/dist/assets/workbox-*")[0])
      File.basename(full_path)
    end
end