-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreprocess.lua
More file actions
68 lines (53 loc) · 1.47 KB
/
preprocess.lua
File metadata and controls
68 lines (53 loc) · 1.47 KB
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
local lfs = require("lfs")
local prepdir = require("prepdir")
local generate
function generate(settings, src, dest)
-- Preprocess a file from src and send the output to dest, recursive.
lfs.mkdir(dest)
for file in lfs.dir(src) do
if file ~= "." and file ~= ".." then
local source = src .. "/" .. file
local destination = dest .. "/" .. file
if lfs.attributes(source).mode == "directory" then
-- If it is a directory, we do this again
generate(settings, source, destination)
else
-- Preprocess file
local content = io.open(source):read("*a")
local f = io.open(destination, "w")
f:write(prepdir(content, settings))
f:flush()
end
end
end
end
local config = require("bundle-config")
if #arg == 0 then -- default behavior
local src, release = "./src", "./release"
lfs.mkdir(release)
-- Preprocess the code with every possible configuration
release = release .. "/"
for i = 1, #config do
generate(config[i].vars, src, release .. config[i].name)
end
else -- preprocess specific file with specific config
local cfg, file
for i = 1, #arg, 2 do
if arg[i] == "--cfg" then
cfg = arg[i + 1]
elseif arg[i] == "--file" then
file = arg[i + 1]
end
end
assert(cfg and file, "missing arguments")
local found = false
for i = 1, #config do
if config[i].name == cfg then
local content = io.open(file):read("*a")
print(prepdir(content, config[i].vars))
found = true
break
end
end
assert(found, "unknown configuration")
end