-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmake.lua
More file actions
178 lines (153 loc) · 4.11 KB
/
make.lua
File metadata and controls
178 lines (153 loc) · 4.11 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
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
local fs = require('fs')
local json = require('json')
local package_file = require('./package.lua')
local binary_format = package.cpath:match('%p[\\|/]?%p(%a+)')
NULL = json.null
local make = {
manifest_file_dir = './manifest.json',
warnings = [[
-- THIS IS PROJECT TREE FILE
-- Do NOT delete this file or it will crash
-- Changes to this file may cause incorrect behavior
-- You will be responsible for this when changing any content in the file.
]],
version = 'v1.0.0',
args = {
build = {
type = 1,
desc = 'Build manifest to standalone executable file',
},
manifest = {
type = 2,
desc = 'Build manifest',
},
}
}
function make.run()
local cli_data = make.get_cli_data()
make.l('INFO', 'LunaticSea make')
make.l('INFO', 'Version: ' .. make.version)
if cli_data and cli_data.type == 3 then
return make.install()
end
local base_command = process.env["DOT_ENABLE"] and './lit make' or 'lit make'
if process.env["TIMEOUT_MODE"] then
base_command = 'timeout 7s ' .. base_command
end
make.manifest_file(cli_data, base_command)
end
function make.manifest_file(cli_data, curr_cmd)
make.l('INFO', 'Checking if ' .. make.manifest_file_dir .. ' exist')
local is_exist = fs.existsSync(make.manifest_file_dir)
if is_exist then
make.l('INFO', make.manifest_file_dir .. ' exist, delete...')
fs.unlinkSync(make.manifest_file_dir)
end
make.l('INFO', 'Making manifest file...')
-- Get git data
local gitobj = {
branch = "git rev-parse --abbrev-ref HEAD",
commit = "git rev-parse HEAD",
commitTime = "git show -s --format=%ct HEAD",
}
for key, command in pairs(gitobj) do
local openPop = assert(io.popen(command))
local output = openPop:read('*all')
openPop:close()
gitobj[key] = output:sub(1, -2)
end
-- Get luvit data
local runtimeObj = {}
local openLuvit = assert(io.popen(
process.env["DOT_ENABLE"] and './luvit --version' or 'luvit --version'
))
local outputLuvit = openLuvit:read('*all')
openLuvit:close()
outputLuvit = make.split(outputLuvit, '%a+ %a+: v?%d+.%d+.%d+')
for _, data in pairs(outputLuvit) do
data = make.split(data, '%S+')
runtimeObj[data[1]] = data[3]
end
-- Build object
local obj = {
name = package_file.name,
codename = package_file.codename,
author = package_file.author,
homepage = package_file.homepage,
license = package_file.license,
version = {
major = "1",
minor = "0",
patch = "2",
preRelease = "dev",
semver = "1.0.2-dev",
build = "",
},
runtime = runtimeObj,
buildTime = os.time(),
git = gitobj
}
make.l('INFO', 'Making manifest file complete')
fs.writeFile(make.manifest_file_dir, json.encode(obj), function(err)
make.build_project(err, cli_data, curr_cmd)
end)
end
function make.build_project(err, cli_data, curr_cmd)
if err then
error(err)
end
make.l('INFO', 'Writting complete!')
if cli_data.type == 2 then
return make.l('INFO', 'Finished 💫')
end
make.l('INFO', 'Building project ...')
local openPop = assert(io.popen(curr_cmd))
local output = openPop:read('*all')
openPop:close()
print(output)
make.l('INFO', 'Building complete!')
make.l('INFO', 'Removing old builds...')
fs.rmdirSync('./build')
make.l('INFO', 'Apply new builds')
local p_name = make.pname_output()
fs.mkdirSync('./build')
fs.renameSync('./' .. p_name, './build/' .. p_name)
make.l('INFO', 'Finished 💫')
end
function make.doc()
print('\n\nInvalid arg, choose only some mode below:\n')
for name, data in pairs(make.args) do
print(' - ' .. name .. ': ' .. data.desc)
end
print('')
print('')
os.exit()
end
function make.get_cli_data()
local get_mode = process.argv[2]
if not get_mode then
get_mode = 'build'
end
local arg_mode = make.args[get_mode]
if not arg_mode then
return make.doc()
end
return arg_mode, get_mode
end
function make.l(type, msg)
print(type .. ' - ' .. msg)
end
function make.pname_output()
if binary_format == 'dll' then
return package_file.name .. '.exe'
end
return package_file.name
end
function make.split(string, pattern)
local t = {}
for i in string.gmatch(string, pattern) do
t[#t + 1] = i
end
return t
end
make.run()