3 local content =
file:read('*a')
11 for line in
string.gmatch(input,
"[^\n]+")
do
12 table.insert(result,
line)
21 local
byte = input:
byte(i)
22 result = result ..
string.format(
"\\x%02x",
byte)
27local function
map_files(files, prefix_len)
33 while index <= #files
do
34 local file_real_path = files[index]
35 local file_real = io.open(file_real_path,
'rb')
36 local file_real_content = file_real and file_real:read(
'*a')
37 local file_name = file_real_path:sub(prefix_len)
39 if file_real_content then
40 list_files[#list_files + 1] = file_name
43 list_paths[#list_paths + 1] = file_name
49 return list_paths, list_files, dict_files
54 while index <= #list_in
do
55 local key = list_in[index]
56 list_out[#list_out + 1] = key
57 if dict_out and dict_in then
58 dict_out[key] = dict_in[key]
64local function
build(...)
68 BOOTSTRAP_DISABLE =
true
71 local input_file = io.open(args[1],
'r')
72 local output_file = io.open(args[2],
'w')
75 return false,
'missing src\'s to bundle!'
78 if not input_file or not output_file then
79 return false,
'usage: lua bootstrap.lua ./dist/main.lua ./dist/cli.lua ./src ./assets'
83 local all_list_paths = {}
84 local all_list_files = {}
85 local all_dict_files = {}
86 while index <= #args
do
87 local path_src = args[index] or
'./src'
88 local prefix_path = path_src:match(
"^(.-)/[^/]+$")
91 if not prefix_path then
92 return false,
'src path must be a explicit relative path or absolute'
93 elseif path_src:sub(1, 2) ==
'./' then
96 prefix_len = #prefix_path + 2
100 local f = io.open(path_src,
'rb')
102 return false,
'directory not found'
104 local can_read = f:read(1)
106 return false,
'path src must be a directory'
111 local cmd_pid = io.popen(
'find '..path_src)
112 local cmd_raw, cmd_pid = cmd_pid:read(
'*a'), cmd_pid:close()
114 local list_paths, list_files, dict_files =
map_files(list_raw, prefix_len)
120 output_file:write(
'local BOOTSTRAP = {}\nlocal BOOTSTRAP_DISABLE = false\n')
124 local content =
'local BOOTSTRAP_DIRS = {'
125 while index <= #all_list_paths
do
126 local file_name = all_list_paths[index]
127 local file_content = all_dict_files[file_name]
128 content = content..
'\''..file_name..
'\''
130 if index <= #all_list_paths then
131 content = content..
', '
133 content = content..
'}\n'
136 output_file:write(content)
141 local content =
'local BOOTSTRAP_LIST = {'
142 while index <= #all_list_files
do
143 local file_name = all_list_files[index]
144 local file_content = all_dict_files[file_name]
145 content = content..
'\''..file_name..
'\''
147 if index <= #all_list_files then
148 content = content..
', '
150 content = content..
'}\n'
153 output_file:write(content)
157 while index <= #all_list_files
do
158 local file_name = all_list_files[index]
159 local file_content = all_dict_files[file_name]
160 output_file:write(
'BOOTSTRAP[\''..file_name..
'\'] = \
''..file_content..
'\'\n
')
164 output_file:write(bootstrap())
165 output_file:write(input_file:read('*a
'))
173 if not BOOTSTRAP then
174 return false, 'cli is not bootstraped
'
179 while index <= #BOOTSTRAP_DIRS do
180 os.execute('mkdir -p
'..BOOTSTRAP_DIRS[index])
187 while index <= #BOOTSTRAP_LIST do
188 local file = BOOTSTRAP_LIST[index]
189 local output_file = io.open(file, 'wb
')
190 output_file:write(BOOTSTRAP[file])
local function string_to_hex(input)
local function merge_dict_and_lists(list_out, dict_out, list_in, dict_in)
local function map_files(files, prefix_len)
local function explode_string(input)
local function bootstrap()
local function file(self, file)
local function line(x1, y1, x2, y2)