mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 16:07:03 +08:00
DEV - versions of JS files written to a JS file to be included by loa… (#10649)
* DEV - versions of JS files written to a JS file to be included by load-script and appended as params to URLs * Formatting * Incorporate feedback from PR * Update filename of public-js-versions
This commit is contained in:
@ -16,10 +16,10 @@ def library_src
|
||||
"#{Rails.root}/node_modules"
|
||||
end
|
||||
|
||||
def write_template(path, template)
|
||||
def write_template(path, task_name, template)
|
||||
header = <<~HEADER
|
||||
// DO NOT EDIT THIS FILE!!!
|
||||
// Update it by running `rake javascript:update_constants`
|
||||
// Update it by running `rake javascript:#{task_name}`
|
||||
HEADER
|
||||
|
||||
basename = File.basename(path)
|
||||
@ -32,13 +32,15 @@ def write_template(path, template)
|
||||
end
|
||||
|
||||
task 'javascript:update_constants' => :environment do
|
||||
write_template("discourse/app/lib/constants.js", <<~JS)
|
||||
task_name = 'update_constants'
|
||||
|
||||
write_template("discourse/app/lib/constants.js", task_name, <<~JS)
|
||||
export const SEARCH_PRIORITIES = #{Searchable::PRIORITIES.to_json};
|
||||
|
||||
export const SEARCH_PHRASE_REGEXP = '#{Search::PHRASE_MATCH_REGEXP_PATTERN}';
|
||||
JS
|
||||
|
||||
write_template("pretty-text/addon/emoji/data.js", <<~JS)
|
||||
write_template("pretty-text/addon/emoji/data.js", task_name, <<~JS)
|
||||
export const emojis = #{Emoji.standard.map(&:name).flatten.inspect};
|
||||
export const tonableEmojis = #{Emoji.tonable_emojis.flatten.inspect};
|
||||
export const aliases = #{Emoji.aliases.inspect.gsub("=>", ":")};
|
||||
@ -47,7 +49,7 @@ task 'javascript:update_constants' => :environment do
|
||||
export const replacements = #{Emoji.unicode_replacements_json};
|
||||
JS
|
||||
|
||||
write_template("pretty-text/addon/emoji/version.js", <<~JS)
|
||||
write_template("pretty-text/addon/emoji/version.js", task_name, <<~JS)
|
||||
export const IMAGE_VERSION = "#{Emoji::EMOJI_VERSION}";
|
||||
JS
|
||||
end
|
||||
@ -84,7 +86,8 @@ task 'javascript:update' do
|
||||
public: true
|
||||
}, {
|
||||
source: 'spectrum-colorpicker/spectrum.css',
|
||||
public: true
|
||||
public: true,
|
||||
skip_versioning: true
|
||||
}, {
|
||||
source: 'favcount/favcount.js'
|
||||
}, {
|
||||
@ -171,6 +174,7 @@ task 'javascript:update' do
|
||||
|
||||
]
|
||||
|
||||
versions = {}
|
||||
start = Time.now
|
||||
|
||||
dependencies.each do |f|
|
||||
@ -202,6 +206,12 @@ task 'javascript:update' do
|
||||
if f[:public_root]
|
||||
dest = "#{public_root}/#{filename}"
|
||||
elsif f[:public]
|
||||
unless f[:skip_versioning]
|
||||
package_name = f[:source].split('/').first
|
||||
package_version = JSON.parse(File.read("#{library_src}/#{package_name}/package.json"))["version"]
|
||||
versions[filename] = package_version
|
||||
end
|
||||
|
||||
dest = "#{public_js}/#{filename}"
|
||||
else
|
||||
dest = "#{vendor_js}/#{filename}"
|
||||
@ -210,6 +220,7 @@ task 'javascript:update' do
|
||||
if src.include? "ace.js"
|
||||
ace_root = "#{library_src}/ace-builds/src-min-noconflict/"
|
||||
addtl_files = [ "ext-searchbox", "mode-html", "mode-scss", "mode-sql", "theme-chrome", "worker-html"]
|
||||
FileUtils.mkdir(dest) unless File.directory?(dest)
|
||||
addtl_files.each do |file|
|
||||
FileUtils.cp_r("#{ace_root}#{file}.js", dest)
|
||||
end
|
||||
@ -232,5 +243,9 @@ task 'javascript:update' do
|
||||
end
|
||||
end
|
||||
|
||||
write_template("discourse/app/lib/public-js-versions.js", "update", <<~JS)
|
||||
export const PUBLIC_JS_VERSIONS = #{versions.to_json};
|
||||
JS
|
||||
|
||||
STDERR.puts "Completed copying dependencies: #{(Time.now - start).round(2)} secs"
|
||||
end
|
||||
|
Reference in New Issue
Block a user