This repository has been archived by the owner on Sep 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 108
/
Rakefile
71 lines (60 loc) · 1.91 KB
/
Rakefile
1
2
3
4
5
6
7
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
require 'rake'
require 'uglifier'
require 'fileutils'
task :default => :build
desc "Ensures all dependent JS libraries are installed and builds the gem."
task :build_gem => :build do
exec("gem build jekyll-lunr-js-search.gemspec")
end
task :build => [
:bower_update,
:create_build_dir,
:copy_jekyll_plugin,
:concat_js,
:minify_js]
task :bower_update do
abort "Please ensure bower is installed: npm install -g bower" unless system('bower install')
end
task :create_build_dir do
Dir.mkdir('build') unless Dir.exists?('build')
end
task :copy_jekyll_plugin do
lunr_version = File.read("bower_components/lunr.js/VERSION").strip
open("build/jekyll_lunr_js_search.rb", "w") do |concat|
Dir.glob("lib/jekyll_lunr_js_search/*.rb") do |file|
ruby = File.read(file).sub(/LUNR_VERSION = .*$/, "LUNR_VERSION = \"#{lunr_version}\"")
concat.puts ruby
end
end
end
task :concat_js do
files = [
'bower_components/jquery/dist/jquery.js',
'bower_components/mustache/mustache.js',
'bower_components/date.format/date.format.js',
'bower_components/uri.js/src/URI.js',
'bower_components/lunr.js/lunr.min.js',
'js/jquery.lunr.search.js'
]
File.open('build/search.js', 'w') do |file|
file.write(files.inject('') { |data, file|
data << File.read(file)
})
end
# Lunr is stored separately so we can use it for index generation
FileUtils.cp('bower_components/lunr.js/lunr.min.js', 'build/lunr.min.js')
end
task :minify_js do
minified, map = Uglifier.new.compile(File.read('build/search.js'))
File.open('build/search.min.js', 'w') do |file|
file.puts minified
end
end
task :minify_js_map do
minified, map = Uglifier.new.compile_with_map(File.read('build/search.js'))
File.open('build/search.js.map', 'w') { |file| file.write(map) }
File.open('build/search.min.js', 'w') do |file|
file.puts minified
file.write "//# sourceMappingURL=search.js.map"
end
end