forked from twitter-archive/twitter-text-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
102 lines (81 loc) · 3.11 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
96
97
98
99
100
101
102
require 'rubygems'
require 'yaml'
require 'json'
require 'date'
require 'digest'
def conformance_version(dir)
Dir[File.join(dir, '*')].inject(Digest::SHA1.new){|digest, file| digest.update(Digest::SHA1.file(file).hexdigest) }
end
namespace :test do
namespace :conformance do
desc "Update conformance testing data"
task :update do
puts "Updating conformance data ... "
system("git submodule init") || raise("Failed to init submodule")
system("git submodule update") || raise("Failed to update submodule")
puts "Updating conformance data ... DONE"
end
desc "Change conformance test data to the lastest version"
task :latest => ['conformance:update'] do
current_dir = File.dirname(__FILE__)
submodule_dir = File.join(File.dirname(__FILE__), "test", "twitter-text-conformance")
version_before = conformance_version(submodule_dir)
system("cd #{submodule_dir} && git pull origin master") || raise("Failed to pull submodule version")
system("cd #{current_dir}")
if conformance_version(submodule_dir) != version_before
system("cd #{current_dir} && git add #{submodule_dir}") || raise("Failed to add upgrade files")
system("git commit -m \"Upgraded to the latest conformance suite\" #{submodule_dir}") || raise("Failed to commit upgraded conformacne data")
puts "Upgraded conformance suite."
else
puts "No conformance suite changes."
end
end
desc "Prepare JS conformance test suite"
task :prepare do
test_files = ['autolink', 'extract', 'hit_highlighting', 'validate']
r = {}
f = File.open(File.join(File.dirname(__FILE__), "test", "conformance.js"), "w")
f.write("var cases = {};")
test_files.each do |test_file|
path = File.join(File.dirname(__FILE__), "test", "twitter-text-conformance", test_file + ".yml")
yml = YAML.load_file(path)
f.write("cases.#{test_file} = #{yml['tests'].to_json};")
end
f.close
end
desc "Run conformance test suite"
task :run do
exec('open test/conformance.html')
end
end
desc "Run conformance test suite"
task :conformance => ['conformance:latest', 'conformance:prepare', 'conformance:run'] do
end
desc "Run JavaScript test suite"
task :run do
exec('open test/test.html')
end
end
desc "Run JavaScript test suite"
task :test => ['test:run']
directory "pkg"
task :package, [:version] => [:pkg] do |t, args|
pkg_name = "twitter-text-#{args.version}.js"
puts "Building #{pkg_name}..."
lib_name = "twitter-text-js #{args.version}"
pkg_file = File.open(File.join(File.dirname(__FILE__), "pkg", pkg_name), "w")
pkg_file.write("/*!\n * #{lib_name}\n *\n")
puts "Writing license..."
license_file = File.open(File.join(File.dirname(__FILE__), "LICENSE"), "r")
license_file.each_line do |line|
pkg_file.write(" * #{line}")
end
license_file.close
pkg_file.write(" */\n\n")
puts "Writing library..."
js_file = File.open(File.join(File.dirname(__FILE__), "twitter-text.js"), "r")
pkg_file.write(js_file.read)
js_file.close
pkg_file.close
puts "Done with #{pkg_name}"
end