/
Rakefile
83 lines (67 loc) · 1.44 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
require 'listen'
require 'uglifier'
require 'jshintrb/jshinttask'
require 'jasmine'
load 'jasmine/tasks/jasmine.rake'
SOURCE_FILE = File.expand_path('../uri.js', __FILE__)
TEST_DIR = File.expand_path('../spec', __FILE__)
# Set default task
task default: :js
# Task js depends on all of js_files being up to date
task js: [:lint, :test, :minify]
desc 'Watch source for changes'
task :watch do
puts "| Watching for changes."
puts '| Hit `ctrl + c` to stop'
js_listener = Listen.to SOURCE_FILE do
sh 'rake js'
end
test_listener = Listen.to TEST_DIR do
sh 'rake test'
end
test_listener.start
js_listener.start
sleep
end
desc 'Test js'
task test: :'jasmine:ci'
desc 'Lint js'
task lint: :jshint
desc 'Minify js'
task :minify do
puts 'Minifying...'
js = File.read(SOURCE_FILE)
ugly = Uglifier.compile(js)
File.open("#{File.basename(SOURCE_FILE, '.js')}.min.js", 'w') do |file|
file.puts ugly
end
puts 'Done.'
end
Jshintrb::JshintTask.new :jshint do |t|
t.pattern = SOURCE_FILE
t.options ={
bitwise: true,
browser: true,
camelcase: true,
curly: true,
eqeqeq: true,
forin: true,
indent: 2,
immed: true,
latedef: true,
noarg: true,
noempty: true,
nonew: true,
quotmark: true,
regexp: true,
undef: true,
strict: true,
trailing: true,
undef: true,
unused: true,
maxparams: 4,
maxdepth: 3,
# maxstatements: 10,
maxlen: 80
}
end