This repository has been archived by the owner on Aug 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Rakefile
94 lines (77 loc) · 2.5 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
require 'bundler/gem_tasks'
require 'json'
require 'rake/testtask'
require 'zlib'
PACKAGE_INFO = JSON.parse(
File.read(File.join(File.dirname(__FILE__), 'package.json')))
Rake::TestTask.new do |t|
t.libs << 'test'
t.test_files = FileList['test/*test.rb']
end
desc "Run tests"
task :default => :test
def program_exists?(program)
`which #{program}`
$?.success?
end
def required_programs
result = PACKAGE_INFO['dependencies'].keys
dev_dep = PACKAGE_INFO['devDependencies'] || {}
result.concat(dev_dep.keys.each { |k| "#{k} (development)" })
end
desc "Check for Node.js and NPM packages"
task :check_for_node do
unless program_exists? 'which'
puts [
"Cannot automatically check for Node.js and NPM packages on this system.",
"If Node.js is not installed, visit https://nodejs.org/.",
"If any of the following packages are not yet installed, please install",
"them by executing `npm install -g PACKAGE`, where `PACKAGE` is one of",
"the names below:"].join("\n")
puts " " + required_programs.join("\n ")
return
end
unless program_exists? 'node'
abort 'Please install Node.js: https://nodejs.org/'
end
end
desc "Install JavaScript components"
task :install_js_components => :check_for_node do
abort unless system 'npm', 'install'
end
desc "Update JavaScript components"
task :update_js_components => :check_for_node do
abort unless system 'npm', 'update'
end
LIB_LUNR_TARGET = File.join %w(lib jekyll_pages_api_search lunr.min.js)
LIB_LUNR_SOURCE = File.join %w(node_modules lunr lunr.min.js)
file LIB_LUNR_TARGET => LIB_LUNR_SOURCE do
FileUtils.cp LIB_LUNR_SOURCE, LIB_LUNR_TARGET
end
main_js = PACKAGE_INFO['main']
search_bundle = File.join 'assets', 'js', 'search-bundle.js'
file search_bundle => main_js do
unless system 'npm', 'run', 'make-bundle'
abort "browserify failed"
end
end
search_bundle_gz = "#{search_bundle}.gz"
file search_bundle_gz => search_bundle do
::Zlib::GzipWriter.open(search_bundle_gz, ::Zlib::BEST_COMPRESSION) do |gz|
gz.write(File.read(search_bundle))
end
end
ARTIFACTS = [LIB_LUNR_TARGET, search_bundle, search_bundle_gz]
task :build_js => [ :check_for_node ].concat(ARTIFACTS) do
ARTIFACTS.each do |artifact|
unless File.exist?(artifact) && File.stat(artifact).size != 0
abort "#{artifact} missing or empty"
end
end
end
task :clean do
[search_bundle, search_bundle_gz].each { |f| File.unlink(f) }
end
task :test => [:build_js]
task :build => [:test]
task :ci_build => [:install_js_components, :test]