2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-03 22:15:43 +08:00
|
|
|
def public_js
|
|
|
|
"#{Rails.root}/public/javascripts"
|
|
|
|
end
|
|
|
|
|
|
|
|
def vendor_js
|
|
|
|
"#{Rails.root}/vendor/assets/javascripts"
|
|
|
|
end
|
|
|
|
|
|
|
|
def library_src
|
|
|
|
"#{Rails.root}/node_modules"
|
|
|
|
end
|
|
|
|
|
2020-05-12 03:43:09 +08:00
|
|
|
def write_template(path, template)
|
2020-05-12 03:29:46 +08:00
|
|
|
header = <<~HEADER
|
2020-05-09 01:25:25 +08:00
|
|
|
// DO NOT EDIT THIS FILE!!!
|
|
|
|
// Update it by running `rake javascript:update_constants`
|
2020-05-12 03:29:46 +08:00
|
|
|
HEADER
|
|
|
|
|
2020-05-12 03:43:09 +08:00
|
|
|
basename = File.basename(path)
|
|
|
|
output_path = "#{Rails.root}/app/assets/javascripts/#{path}"
|
|
|
|
|
|
|
|
File.write(output_path, "#{header}\n\n#{template}")
|
|
|
|
puts "#{basename} created"
|
|
|
|
%x{yarn run prettier --write #{output_path}}
|
|
|
|
puts "#{basename} prettified"
|
|
|
|
end
|
2020-05-09 01:25:25 +08:00
|
|
|
|
2020-05-12 03:43:09 +08:00
|
|
|
task 'javascript:update_constants' => :environment do
|
|
|
|
write_template("discourse/app/lib/constants.js", <<~JS)
|
2020-05-09 03:50:55 +08:00
|
|
|
export const SEARCH_PRIORITIES = #{Searchable::PRIORITIES.to_json};
|
2020-05-09 01:25:25 +08:00
|
|
|
|
2020-05-09 03:50:55 +08:00
|
|
|
export const SEARCH_PHRASE_REGEXP = '#{Search::PHRASE_MATCH_REGEXP_PATTERN}';
|
2020-05-09 01:25:25 +08:00
|
|
|
JS
|
2018-10-03 22:15:43 +08:00
|
|
|
|
2020-05-12 03:43:09 +08:00
|
|
|
write_template("pretty-text/addon/emoji/data.js", <<~JS)
|
2020-05-12 03:29:46 +08:00
|
|
|
export const emojis = #{Emoji.standard.map(&:name).flatten.inspect};
|
|
|
|
export const tonableEmojis = #{Emoji.tonable_emojis.flatten.inspect};
|
|
|
|
export const aliases = #{Emoji.aliases.inspect.gsub("=>", ":")};
|
|
|
|
export const searchAliases = #{Emoji.search_aliases.inspect.gsub("=>", ":")};
|
|
|
|
export const translations = #{Emoji.translations.inspect.gsub("=>", ":")};
|
|
|
|
export const replacements = #{Emoji.unicode_replacements_json};
|
|
|
|
JS
|
2020-05-12 03:43:09 +08:00
|
|
|
|
|
|
|
write_template("pretty-text/addon/emoji/version.js", <<~JS)
|
|
|
|
export const IMAGE_VERSION = "#{Emoji::EMOJI_VERSION}";
|
|
|
|
JS
|
2020-05-09 01:25:25 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
task 'javascript:update' do
|
2018-10-03 22:15:43 +08:00
|
|
|
require 'uglifier'
|
|
|
|
|
|
|
|
yarn = system("yarn install")
|
|
|
|
abort('Unable to run "yarn install"') unless yarn
|
|
|
|
|
|
|
|
dependencies = [
|
|
|
|
{
|
2019-03-21 21:18:12 +08:00
|
|
|
source: 'bootstrap/js/modal.js',
|
|
|
|
destination: 'bootstrap-modal.js'
|
|
|
|
}, {
|
2019-02-15 00:05:28 +08:00
|
|
|
source: 'ace-builds/src-min-noconflict/.',
|
2018-10-03 22:15:43 +08:00
|
|
|
destination: 'ace',
|
|
|
|
public: true
|
|
|
|
}, {
|
|
|
|
source: 'chart.js/dist/Chart.min.js',
|
|
|
|
public: true
|
|
|
|
}, {
|
|
|
|
source: 'magnific-popup/dist/jquery.magnific-popup.min.js',
|
|
|
|
public: true
|
|
|
|
}, {
|
|
|
|
source: 'pikaday/pikaday.js',
|
|
|
|
public: true
|
|
|
|
}, {
|
|
|
|
source: 'spectrum-colorpicker/spectrum.js',
|
|
|
|
uglify: true,
|
|
|
|
public: true
|
|
|
|
}, {
|
|
|
|
source: 'spectrum-colorpicker/spectrum.css',
|
|
|
|
public: true
|
|
|
|
}, {
|
|
|
|
source: 'favcount/favcount.js'
|
|
|
|
}, {
|
|
|
|
source: 'handlebars/dist/handlebars.js'
|
|
|
|
}, {
|
|
|
|
source: 'handlebars/dist/handlebars.runtime.js'
|
2019-01-15 01:46:35 +08:00
|
|
|
}, {
|
|
|
|
source: 'highlight.js/build/.',
|
|
|
|
destination: 'highlightjs'
|
2018-10-03 22:15:43 +08:00
|
|
|
}, {
|
|
|
|
source: 'jquery-resize/jquery.ba-resize.js'
|
|
|
|
}, {
|
|
|
|
source: 'jquery.autoellipsis/src/jquery.autoellipsis.js',
|
|
|
|
destination: 'jquery.autoellipsis-1.0.10.js'
|
|
|
|
}, {
|
2019-07-04 21:03:21 +08:00
|
|
|
source: 'jquery-color/dist/jquery.color.js'
|
2018-10-03 22:15:43 +08:00
|
|
|
}, {
|
|
|
|
source: 'jquery.cookie/jquery.cookie.js'
|
2020-04-28 22:39:29 +08:00
|
|
|
}, {
|
|
|
|
source: 'blueimp-file-upload/js/jquery.fileupload.js',
|
|
|
|
}, {
|
|
|
|
source: 'blueimp-file-upload/js/jquery.iframe-transport.js',
|
|
|
|
}, {
|
|
|
|
source: 'blueimp-file-upload/js/vendor/jquery.ui.widget.js',
|
2018-10-03 22:15:43 +08:00
|
|
|
}, {
|
2018-12-12 12:36:08 +08:00
|
|
|
source: 'jquery/dist/jquery.js'
|
2018-10-03 22:15:43 +08:00
|
|
|
}, {
|
|
|
|
source: 'jquery-tags-input/src/jquery.tagsinput.js'
|
|
|
|
}, {
|
|
|
|
source: 'markdown-it/dist/markdown-it.js'
|
|
|
|
}, {
|
|
|
|
source: 'mousetrap/mousetrap.js'
|
2019-02-13 02:57:52 +08:00
|
|
|
}, {
|
|
|
|
source: 'moment/moment.js'
|
|
|
|
}, {
|
2019-02-15 00:05:28 +08:00
|
|
|
source: 'moment/locale/.',
|
2019-02-13 02:57:52 +08:00
|
|
|
destination: 'moment-locale',
|
|
|
|
}, {
|
2019-05-08 11:42:49 +08:00
|
|
|
source: 'moment-timezone/builds/moment-timezone-with-data-10-year-range.js',
|
|
|
|
destination: 'moment-timezone-with-data.js'
|
2019-07-11 22:57:03 +08:00
|
|
|
}, {
|
|
|
|
source: 'lodash.js',
|
|
|
|
destination: 'lodash.js'
|
2019-02-26 03:40:02 +08:00
|
|
|
}, {
|
|
|
|
source: 'moment-timezone-names-translations/locales/.',
|
|
|
|
destination: 'moment-timezone-names-locale'
|
2019-02-14 13:19:27 +08:00
|
|
|
}, {
|
|
|
|
source: 'mousetrap/plugins/global-bind/mousetrap-global-bind.js'
|
2018-10-03 22:15:43 +08:00
|
|
|
}, {
|
|
|
|
source: 'resumablejs/resumable.js'
|
2018-12-12 12:36:08 +08:00
|
|
|
}, {
|
|
|
|
# TODO: drop when we eventually drop IE11, this will land in iOS in version 13
|
|
|
|
source: 'intersection-observer/intersection-observer.js'
|
2019-07-16 00:05:55 +08:00
|
|
|
}, {
|
|
|
|
source: 'workbox-sw/build/.',
|
|
|
|
destination: 'workbox',
|
|
|
|
public: true
|
|
|
|
}, {
|
|
|
|
source: 'workbox-routing/build/.',
|
|
|
|
destination: 'workbox',
|
|
|
|
public: true
|
|
|
|
}, {
|
|
|
|
source: 'workbox-core/build/.',
|
|
|
|
destination: 'workbox',
|
|
|
|
public: true
|
|
|
|
}, {
|
|
|
|
source: 'workbox-strategies/build/.',
|
|
|
|
destination: 'workbox',
|
|
|
|
public: true
|
|
|
|
}, {
|
|
|
|
source: 'workbox-expiration/build/.',
|
|
|
|
destination: 'workbox',
|
|
|
|
public: true
|
2020-02-04 22:34:46 +08:00
|
|
|
}, {
|
|
|
|
source: '@popperjs/core/dist/umd/popper.js'
|
2018-10-03 22:15:43 +08:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
start = Time.now
|
|
|
|
|
|
|
|
dependencies.each do |f|
|
|
|
|
src = "#{library_src}/#{f[:source]}"
|
|
|
|
|
|
|
|
unless f[:destination]
|
|
|
|
filename = f[:source].split("/").last
|
|
|
|
else
|
|
|
|
filename = f[:destination]
|
|
|
|
end
|
|
|
|
|
2019-01-15 01:46:35 +08:00
|
|
|
# Highlight.js needs building
|
|
|
|
if src.include? "highlight.js"
|
|
|
|
puts "Install Highlight.js dependencies"
|
|
|
|
system("cd node_modules/highlight.js && yarn install")
|
|
|
|
|
|
|
|
puts "Build Highlight.js"
|
|
|
|
system("cd node_modules/highlight.js && node tools/build.js -t cdn none")
|
|
|
|
|
|
|
|
puts "Cleanup unused styles folder"
|
|
|
|
system("rm -rf node_modules/highlight.js/build/styles")
|
|
|
|
end
|
|
|
|
|
2019-02-15 00:05:28 +08:00
|
|
|
if src.include? "ace-builds"
|
|
|
|
puts "Cleanup unused snippets folder for ACE"
|
|
|
|
system("rm -rf node_modules/ace-builds/src-min-noconflict/snippets")
|
|
|
|
end
|
|
|
|
|
2018-10-03 22:15:43 +08:00
|
|
|
if f[:public]
|
|
|
|
dest = "#{public_js}/#{filename}"
|
|
|
|
else
|
|
|
|
dest = "#{vendor_js}/#{filename}"
|
|
|
|
end
|
|
|
|
|
2019-07-11 22:57:03 +08:00
|
|
|
# lodash.js needs building
|
|
|
|
if src.include? "lodash.js"
|
|
|
|
puts "Building custom lodash.js build"
|
|
|
|
system('yarn run lodash include="each,filter,map,range,first,isEmpty,chain,extend,every,omit,merge,union,sortBy,uniq,intersection,reject,compact,reduce,debounce,throttle,values,pick,keys,flatten,min,max,isArray,delay,isString,isEqual,without,invoke,clone,findIndex,find,groupBy" minus="template" -d -o "node_modules/lodash.js"')
|
|
|
|
end
|
|
|
|
|
2018-10-03 22:15:43 +08:00
|
|
|
unless File.exists?(dest)
|
|
|
|
STDERR.puts "New dependency added: #{dest}"
|
|
|
|
end
|
|
|
|
|
|
|
|
if f[:uglify]
|
|
|
|
File.write(dest, Uglifier.new.compile(File.read(src)))
|
|
|
|
else
|
|
|
|
FileUtils.cp_r(src, dest)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
STDERR.puts "Completed copying dependencies: #{(Time.now - start).round(2)} secs"
|
|
|
|
end
|