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
|
|
|
|
|
|
|
|
task 'javascript:update' do
|
|
|
|
|
|
|
|
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'
|
|
|
|
}, {
|
|
|
|
source: 'jquery-color/jquery.color.js'
|
|
|
|
}, {
|
|
|
|
source: 'jquery.cookie/jquery.cookie.js'
|
|
|
|
}, {
|
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-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'
|
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
|
|
|
|
|
|
|
|
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
|