forked from mootools/mootools-more
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rb
executable file
·120 lines (97 loc) · 2.9 KB
/
build.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
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
#!/usr/bin/env ruby
# USAGE:
#
# Full:
# ./build.rb
#
# Fx.Accordion, DomReady including all dependencies:
# ./build.rb Fx.Tween DomReady
require 'rubygems'
require 'json'
require 'yaml'
module MooTools
class Build
attr_reader :included
attr_accessor :build_path
attr_accessor :dependency_paths
attr_accessor :data
def initialize(opts={})
@path = opts[:path] || File.dirname(__FILE__)
@build_path = opts[:build_path] || @path + '/mootools-more.js'
@dependency_paths = opts[:dependency_paths] || [@path + '/Source']
@dependency_file = opts[:dependency_file] || 'scripts.json'
@scripts = []
@included = []
@data = {}
@dependency_paths.each do |dependency_path|
json = JSON.load(File.read( dependency_path + "/#{@dependency_file}" ))
json.each_pair do |folder, group|
group.each_pair do |script, properties|
@scripts.push(script)
@data[script] = {:folder => "#{dependency_path}/#{folder}", :deps => properties["deps"]}
end
end
end
end
def full_build
@scripts.each { |name| load_script name }
@string
end
def load_script(name)
return if @included.index(name) || name == 'None';
unless @data.key? name
puts "Script '#{name}' not found!"
throw :script_not_found
end
puts "loading #{name}\n"
@included.push name
@data[name][:deps].each { |dep| load_script dep }
@string ||= ""
@string << File.read("#{@data[name][:folder]}/#{name}.js") << "\n"
end
def build
@string ||= full_build
@string.sub!('%build%', build_number)
end
alias :to_s :build
def build_number
begin
ref = File.read(File.dirname(__FILE__) + '/.git/HEAD').chomp.match(/ref: (.*)/)[1]
return File.read(File.dirname(__FILE__) + "/.git/#{ref}").chomp
rescue
return ""
end
end
def save(filename)
File.open(filename, 'w') { |fh| fh.write to_s }
end
def save!
save build_path
end
def self.build!(argv, mootools = MooTools::Build.new)
catch :script_not_found do
if argv.length > 0
argv.each { |script| mootools.load_script(script) }
else
mootools.full_build
end
end
puts "MooTools Built '#{mootools.build_path}'"
print " Included Scripts:","\n "
puts mootools.included.join(" ")
mootools.save!
end
end
end
if __FILE__ == $0
conf = YAML.load_file('build.yml')
if (File.exist?('build.local.yml'))
local_conf = YAML.load_file('build.local.yml')
conf.merge!(local_conf)
end
builder = MooTools::Build.new({
:dependency_paths => conf[:dependency_paths],
:build_path => conf[:build_path]
})
MooTools::Build.build! ARGV, builder
end