-
Notifications
You must be signed in to change notification settings - Fork 2
/
compiler.rb
61 lines (51 loc) · 1.64 KB
/
compiler.rb
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
require 'pathname'
require 'fileutils'
require 'coffee_script'
module Jasmine
class Compiler
def self.run
compile_gem_assets
compile_jasmine_specs
end
private
def self.clean(dir)
FileUtils.rm_rf dir, :secure => true
end
def self.compile_gem_assets
root = File.expand_path("../../../app/assets/javascripts", __FILE__)
destination_dir = File.expand_path("../../../tmp/assets", __FILE__)
clean(destination_dir)
compile_path_files(root, destination_dir)
end
def self.compile_jasmine_specs
root = File.expand_path("../../../spec/javascripts", __FILE__)
destination_dir = File.expand_path("../../../tmp/specs", __FILE__)
clean(destination_dir)
compile_path_files(root, destination_dir)
copy_path_files(root, destination_dir)
end
def self.copy_path_files(srcdir, destdir)
glob = File.expand_path("**/*.{js,html}", srcdir)
Dir.glob(glob).each do |srcfile|
srcfile = Pathname.new(srcfile)
destfile = srcfile.sub(srcdir, destdir)
FileUtils.mkdir_p(destfile.dirname)
FileUtils.cp(srcfile, destfile)
end
end
def self.compile_path_files(srcdir, destdir)
glob = File.expand_path("**/*.js.coffee", srcdir)
Dir.glob(glob).each do |srcfile|
srcfile = Pathname.new(srcfile)
destfile = srcfile.sub(srcdir, destdir).sub(".coffee", "")
compile(srcfile, destfile)
end
end
def self.compile(srcfile, destfile)
FileUtils.mkdir_p(destfile.dirname)
File.open(destfile, "w") do |f|
f.write(CoffeeScript.compile(File.new(srcfile)))
end
end
end
end