forked from jashkenas/coffeescript
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
109 lines (98 loc) · 3.27 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
103
104
105
106
107
108
109
require 'rubygems'
require 'erb'
require 'fileutils'
require 'rake/testtask'
require 'json'
def load_gem(gem_name)
begin
gem gem_name
rescue Gem::LoadError
raise "Could not load the #{gem_name} gem. Install it with `gem install #{gem_name}`."
end
end
desc "Build the documentation page"
task :doc do
source = 'documentation/index.html.erb'
child = fork { exec "bin/coffee -bcw -o documentation/js documentation/coffee/*.coffee" }
at_exit { Process.kill("INT", child) }
Signal.trap("INT") { exit }
loop do
mtime = File.stat(source).mtime
if !@mtime || mtime > @mtime
rendered = ERB.new(File.read(source)).result(binding)
File.open('index.html', 'w+') {|f| f.write(rendered) }
end
@mtime = mtime
sleep 1
end
end
desc "install coffeescript.syntax into ultraviolet gem"
task :install_coffeescript_syntax do
require 'yaml'
require 'open-uri'
if RUBY_VERSION.to_f >= 1.9
ultraviolet_gem = 'spox-ultraviolet'
plist_gem = 'spox-plist'
else
ultraviolet_gem = 'ultraviolet'
plist_gem = 'plist'
end
load_gem ultraviolet_gem
load_gem plist_gem
require 'plist'
cs_tm_language_url = "https://raw.github.com/jashkenas/coffee-script-tmbundle/master/Syntaxes/CoffeeScript.tmLanguage"
cs_tm_language = open(cs_tm_language_url).read
result = Plist::parse_xml(cs_tm_language)
ultraviolet_coffeescript_syntax_path = File.join(Gem.loaded_specs[ultraviolet_gem].full_gem_path, "syntax", "coffeescript.yaml")
File.open(ultraviolet_coffeescript_syntax_path, "w" ) { |f| YAML.dump( result, f ) }
puts "wrote coffeescript syntax to: #{ultraviolet_coffeescript_syntax_path}"
end
desc "Build coffee-script-source gem"
task :gem do
require 'rubygems'
require 'rubygems/package'
gemspec = Gem::Specification.new do |s|
s.name = 'coffee-script-source'
s.version = JSON.parse(File.read('package.json'))["version"]
s.date = Time.now.strftime("%Y-%m-%d")
s.homepage = "http://jashkenas.github.com/coffee-script/"
s.summary = "The CoffeeScript Compiler"
s.description = <<-EOS
CoffeeScript is a little language that compiles into JavaScript.
Underneath all of those embarrassing braces and semicolons,
JavaScript has always had a gorgeous object model at its heart.
CoffeeScript is an attempt to expose the good parts of JavaScript
in a simple way.
EOS
s.files = [
'lib/coffee_script/coffee-script.js',
'lib/coffee_script/source.rb'
]
s.authors = ['Jeremy Ashkenas']
s.email = '[email protected]'
s.rubyforge_project = 'coffee-script-source'
s.license = "MIT"
end
file = File.open("coffee-script-source.gem", "w")
Gem::Package.open(file, 'w') do |pkg|
pkg.metadata = gemspec.to_yaml
path = "lib/coffee_script/source.rb"
contents = <<-ERUBY
module CoffeeScript
module Source
def self.bundled_path
File.expand_path("../coffee-script.js", __FILE__)
end
end
end
ERUBY
pkg.add_file_simple(path, 0644, contents.size) do |tar_io|
tar_io.write(contents)
end
contents = File.read("extras/coffee-script.js")
path = "lib/coffee_script/coffee-script.js"
pkg.add_file_simple(path, 0644, contents.size) do |tar_io|
tar_io.write(contents)
end
end
end