This repository has been archived by the owner on Mar 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Rakefile
71 lines (61 loc) · 1.67 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 'rubygems'
require 'bundler/setup'
require 'closure-compiler'
require 'jslint'
require 'webrick'
prefix = File.dirname(__FILE__)
lectric = File.join(prefix, 'js', 'lectric.js')
lectric_min = File.join(prefix, 'js', 'lectric.min.js')
version = File.join(prefix, 'VERSION')
task :default => :build
desc "Build and minify Lectric."
task :build => [:lint, :stamp_version, :minify] do
puts "Lectric build complete."
end
desc "Stamp the library with the current version"
task :stamp_version => :version do
contents = File.read(lectric)
file = File.open(lectric, 'w')
file.puts contents.gsub(/(Lectric v)([\d\w\.-]+)/, "\\1#{@version}")
file.close
end
desc "Run library against JSLint"
task :lint do
lint = JSLint::Lint.new(
:paths => ['js/**/*.js'],
:exclude_paths => ['js/**/*.min.js']
)
lint.run
end
desc "Compress the library using Google's Closure Compiler"
task :minify => :version do
puts "Minifying Lectric..."
comments = <<-EOS
/*!
* Lectric v#{@version}
* http://github.com/mckinney/lectric
*
* Copyright 2011, McKinney
* Licensed under the MIT license.
* http://github.com/mckinney/lectric/blob/master/LICENSE
*
* Author: Brett C. Buddin
*/
EOS
file = File.open(lectric_min, 'w')
file.puts comments + Closure::Compiler.new.compile(File.open(lectric, 'r'))
file.close
end
task :version do
@version = File.read(version).strip
puts "VERSION: #{@version}"
end
desc "Starts an HTTP server in the current directory"
task :server do
config = {:Port => 3000, :DocumentRoot => '.'}
server = WEBrick::HTTPServer.new config
['INT', 'TERM'].each do |signal|
trap(signal) { server.shutdown }
end
server.start
end