-
Notifications
You must be signed in to change notification settings - Fork 46
/
Rakefile
257 lines (184 loc) · 8.42 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
require 'json'
require 'open-uri'
require 'net/http'
require 'zlib'
GEMS_DIR = '/Library/Ruby/Gems/1.8/gems'
def find_gem name, options={}
options = { :prerelease => false }.merge(options)
versions = Dir["#{GEMS_DIR}/#{name}-*"].map { |path| File.basename(path) =~ /^#{name}-(\d+\.\d.*)$/ ? [path, $1] : nil }.compact
unless options[:prerelease]
versions = versions.reject { |path, ver| ver =~ /alpha/ }
end
versions.sort! { |a, b| Gem::Version.new(a[1]) <=> Gem::Version.new(b[1]) }
versions.last
end
class GemHosting
class <<self
def latest_gem_version name, prerelease=false
result = gem_versions(name, prerelease).last
if result.nil? && prerelease
result = gem_versions(name, false).last
end
result[1]
end
def gem_versions name, prerelease=false
gem_specs(prerelease).select { |n, ver, plaf| n == name }.sort { |a, b| a[1] <=> b[1] }
end
def gem_specs prerelease=false
if prerelease
@prerelease_gem_specs ||= load_gem_specs('http://rubygems.org/prerelease_specs.4.8.gz')
else
@gem_specs ||= load_gem_specs('http://rubygems.org/latest_specs.4.8.gz')
end
end
def load_gem_specs url
puts "Loading gem list from #{url}..."
Marshal.load(Zlib::GzipReader.new(StringIO.new(open(url).read)).read)
end
end
end
class Dependency < Struct.new(:name, :cur_version, :old_version, :requires_update, :dst_path)
end
class NpmDependency < Dependency
include Rake::DSL
def install! plugin_dir
Dir.chdir plugin_dir do
sh "npm install #{name}@#{cur_version}"
end
end
end
class GemDependency < Dependency
include Rake::DSL
def src_path
File.join(GEMS_DIR, "#{name}-#{cur_version}")
end
def install! plugin_dir
unless File.directory? src_path
sh "sudo gem install #{name} -v #{cur_version} --no-rdoc --no-ri --verbose"
end
begin
cp_r src_path, dst_path
rescue Errno::EACCES
# fix perms of compass-*/examples/css3/extensions/fancy-fonts/templates/project/bgrove.otf
sh "sudo chmod -R +r #{src_path}"
rm_rf dst_path
cp_r src_path, dst_path
end
end
end
class PluginTask
include Rake::DSL
def initialize name, options={}
options = {
:gems => [],
:npm => [],
:prerelease => true
}.merge(options)
@name = name
@gems = options[:gems]
@npm = options[:npm]
@important_dependencies = options[:important] || [@gems.first, @npm.first].compact
@plugin_dir = "#{@name}.lrplugin"
@lib_dir = "#{@plugin_dir}/lib"
@node_modules_dir = "#{@plugin_dir}/node_modules"
@versions_json = File.join(@plugin_dir, 'versions.json')
task_name = @name.downcase
desc "Bundle the latest stable version of #{name}"
task(task_name) { bundle(options.merge(:prerelease => false)) }
if options[:prerelease]
desc "Bundle the latest prerelease version of #{name}"
task("#{task_name}:pre") { bundle(options.merge(:prerelease => true)) }
end
task "all" => task_name
task "all:pre" => "#{task_name}:pre"
end
def bundle options
dep_versions = (JSON.parse(File.read(@versions_json)) rescue {})
gem_dependencies = @gems.map do |gem_name|
cur_version = GemHosting.latest_gem_version(gem_name, options[:prerelease]).to_s
dst_path = File.join(@lib_dir, gem_name)
requires_update = (dep_versions[gem_name] != cur_version) || !File.exists?(dst_path)
GemDependency.new(gem_name, cur_version, dep_versions[gem_name], requires_update, dst_path)
end
npm_dependencies = if @npm.empty?
[]
else
Net::HTTP.start('registry.npmjs.org', 80) do |http|
@npm.map do |npm_name|
manifest = JSON.parse(http.get("/#{npm_name}/").body)
dist_tags = manifest['dist-tags']
dst_path = File.join(@node_modules_dir, npm_name)
cur_version = dist_tags['latest']
if !options[:prerelease] && dist_tags.include?('stable')
cur_version = dist_tags['stable']
end
requires_update = (dep_versions[npm_name] != cur_version) || !File.exists?(dst_path)
NpmDependency.new(npm_name, cur_version, dep_versions[npm_name], requires_update, dst_path)
end
end
end
dependencies = gem_dependencies + npm_dependencies
updated_dependencies = dependencies.select { |dep| dep.requires_update }
important_dependencies = @important_dependencies.map { |n| [n, dependencies.find { |d| d.name == n }] }
overall_name = case important_dependencies.size
when 1 then important_dependencies.first[1].cur_version
else important_dependencies.map { |n, d| "#{n} #{d.cur_version}" }.join(", ")
end
if updated_dependencies.empty?
puts "All #{@name} #{overall_name} dependencies are up to date."
else
puts "Updating #{@name} to #{overall_name} -- dependencies: #{updated_dependencies.map { |d| d.name }.join(' ')}."
for dependency in updated_dependencies
puts "Updating #{dependency.name}: #{dependency.old_version} => #{dependency.cur_version}"
rm_rf dependency.dst_path
mkdir_p File.dirname(dependency.dst_path) unless File.directory?(File.dirname(dependency.dst_path))
dependency.install! @plugin_dir
dep_versions[dependency.name] = dependency.cur_version
puts "Updated #{dependency.name}: #{dependency.old_version} => #{dependency.cur_version}"
end
puts "Updated #{@name} #{overall_name} dependencies: #{updated_dependencies.map { |d| d.name }.join(' ')}."
puts "Final #{@name} #{overall_name} dependency versions: " + JSON.pretty_generate(dep_versions)
dep_versions['.'] = overall_name
File.open(@versions_json, 'w') { |f| f.puts JSON.pretty_generate(dep_versions) }
sh "find . -name example -or -name examples -or -name test -or -name tests -or -name spec -or -name docs -or -name tmp -or -name .idea -or -name dist | xargs rm -rf"
puts "Committing #{@name}..."
Dir.chdir @plugin_dir do
sh "git add -A versions.json " + Dir['{lib,node_modules}'].join(' ')
sh "git commit . -m 'Update #{@name} to #{overall_name}' && git log -1" rescue nil
end
end
end
end
class NewPluginTask
include Rake::DSL
def initialize name, options={}
end
end
desc "Bundle the latest stable versions of all compilers"
task 'all'
desc "Bundle the latest prerelease versions of all compilers"
task 'all:pre'
PluginTask.new 'CoffeeScript', :npm => %w(coffee-script)
PluginTask.new 'IcedCoffeeScript', :npm => %w(iced-coffee-script)
PluginTask.new 'TypeScript', :npm => %w(typescript)
PluginTask.new 'Eco', :npm => %w(eco)
PluginTask.new 'LESS', :npm => %w(less)
# Cairo prob on OS X? Try this:
# export PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig
# see: https://github.com/mxcl/homebrew/issues/14123
PluginTask.new 'Stylus', :npm => %w(stylus nib canvas)
PluginTask.new 'Jade', :npm => %w(jade markdown)
PluginTask.new 'streamline', :npm => %w(streamline)
PluginTask.new 'autoprefixer', :npm => %w(autoprefixer)
PluginTask.new 'HAML', :gems => %w(haml tilt)
PluginTask.new 'SLIM', :gems => %w(slim temple tilt)
PluginTask.new 'SASS', :gems => %w(sass compass chunky_png html5-boilerplate compass-h5bp compass-960-plugin susy zurb-foundation compass-colors fancy-buttons compass-slickmap grid-coordinates compass-rgbapng compass-baseline compass-vgrid-plugin compass-less-plugin sassy-buttons compass-thesquaregrid compass-fancybox-plugin font-stack compass-squaregrid-plugin compass_formalize compass-lucid-grid stitch), :important => %w(sass compass)
NewPluginTask.new 'SASS'
task :default do
puts ENV['INSTALL']
puts find_gem('compass', :prerelease => true )
end
desc "Print a summary of the bundled compiler versions"
task :summary do
sh 'coffee', 'summary.coffee'
end