-
Notifications
You must be signed in to change notification settings - Fork 63
/
Rakefile
95 lines (79 loc) · 2.49 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
95
require 'bundler'
Bundler.require
Bundler::GemHelper.install_tasks
ENV['RUNNER'] = 'chrome'
require 'opal/rspec/rake_task'
Opal::RSpec::RakeTask.new(:default) do |server, task|
server.index_path = 'spec-opal/jquery/index.html.erb'
task.default_path = 'spec-opal'
end
Opal::RSpec::RakeTask.new(:jquery3) do |server, task|
server.index_path = 'spec-opal/jquery/index3.html.erb'
task.default_path = 'spec-opal'
end
Opal::RSpec::RakeTask.new(:zepto) do |server, task|
server.index_path = 'spec-opal/zepto/index.html.erb'
task.default_path = 'spec-opal'
end
desc "Build build/opal-jquery.js"
task :dist do
require 'fileutils'
FileUtils.mkdir_p 'build'
src = Opal::Builder.build('opal-jquery')
min = uglify src
gzp = gzip min
File.open('build/opal-jquery.js', 'w+') do |out|
out << src
end
puts "development: #{src.size}, minified: #{min.size}, gzipped: #{gzp.size}"
end
# Used for uglifying source to minify
def uglify(str)
IO.popen('uglifyjs', 'r+') do |i|
i.puts str
i.close_write
return i.read
end
rescue Errno::ENOENT
$stderr.puts '"uglifyjs" command not found (install with: "npm install -g uglify-js")'
nil
end
# Gzip code to check file size
def gzip(str)
IO.popen('gzip -f', 'r+') do |i|
i.puts str
i.close_write
return i.read
end
rescue Errno::ENOENT
$stderr.puts '"gzip" command not found, it is required to produce the .gz version'
nil
end
namespace :doc do
doc_repo = Pathname(ENV['DOC_REPO'] || 'gh-pages')
doc_base = doc_repo.join('doc')
current_git_release = -> { `git rev-parse --abbrev-ref HEAD`.chomp }
# template_option = "--template opal --template-path #{doc_repo.join('yard-templates')}"
template_option = ""
directory doc_repo.to_s do
remote = ENV['DOC_REPO_REMOTE'] || '.'
sh 'git', 'clone', '-b', 'gh-pages', '--', remote, doc_repo.to_s
end
# To generate docs that live on http://opalrb.org/opal-jquery/ use the
# `rake doc` task
#
# DOC_REPO_REMOTE=https://github.com/opal/opal-jquery.git bundle exec rake doc
# open gh-pages/index.html
task :default => doc_repo.to_s do
git = current_git_release.call
name = 'api'
glob = 'opal/**/*.rb'
command = "yard doc #{glob} #{template_option} "\
"--readme opal/README.md -o gh-pages/doc/#{git}/#{name}"
puts command; system command
end
# To generate api docs on rubygems: http://www.rubydoc.info/gems/opal-jquery/0.4.2
# yard --main README.md --markup markdown --github
# open doc/index.html
end
task :doc => 'doc:default'