forked from mootools/mootools-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.lua
executable file
·129 lines (80 loc) · 2.5 KB
/
build.lua
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
#!/usr/bin/env lua
--[[
INSTRUCTIONS
============
Full Build
----------
./build.lua
Partial Build (includes dependancies)
-------------------------------------
./build.lua Fx.Tween DomReady
Requires
--------
This script requires yaml for lua. http://luayaml.luaforge.net/
To successfully compile luaYAML in OSX you'll have to open Makefile and replace
"-shared" with "-bundle -undefined dynamic_lookup -all_load"
luaYaml requires Syck 0.55, which compiles just fine in Mac OSX Leopard: http://whytheluckystiff.net/syck/
--]]
require "yaml"
-- table.contains ()
-- tests if an item is included in a table
function table:contains(item)
for key, value in ipairs(self) do
if value == item then
return true
end
end
return false;
end
-- table.include ()
-- includes an item in a table if not already present
function table:include(item)
if not table.contains(self, item) then table.insert(self, item) end
return self
end
-- build ()
local function build(selected_scripts)
local package = yaml.load_file("package.yml") -- reads the configuration from package.yml
local output_path = package.filename
local data = {}
local all_scripts = {}
for i, path in ipairs(package.files) do
local script = io.open(path):read("*all")
if i == 1 then -- fills %build% in the first file if it's called from a git clone
local ref = io.open('.git/HEAD')
if ref then
ref = ref:read("*all"):match("ref: ([%w/]+)")
ref = io.open('.git/' .. ref):read("*all"):match("(%w+)")
script = script:gsub("%%build%%", ref)
end
end
local descriptor = yaml.load(script:match("/[*]=(.*)=[*]/"))
table.insert(all_scripts, descriptor.name)
data[descriptor.name] = {
source = script,
path = path,
requires = (type(descriptor.requires) == 'table') and descriptor.requires or {descriptor.requires}
}
end
local included_scripts = {}
local scripts = table.maxn(selected_scripts) ~= 0 and selected_scripts or all_scripts
function rock_requires(name)
for i, n in ipairs(data[name].requires) do
rock_requires(n);
end
table.include(included_scripts, name)
end
for i, name in ipairs(scripts) do
rock_requires(name)
end
local sources = {}
local mootools = io.open(output_path, "w+")
io.write("\nBuilding " .. output_path .. "\n\nIncluded Scripts:\n\n")
for i, name in ipairs(included_scripts) do
table.insert(sources, data[name].source)
io.write('\t ' .. name .. '\n');
end
io.write('\n')
mootools:write(table.concat(sources, '\n\n'))
end
build(arg)