-
-
Notifications
You must be signed in to change notification settings - Fork 52
/
publish.lua
254 lines (226 loc) · 6.32 KB
/
publish.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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
local currentPath = debug.getinfo(1, 'S').source:sub(2)
local rootPath = currentPath:gsub('[^/\\]-$', '')
local fs = require 'bee.filesystem'
local subprocess = require 'bee.subprocess'
local platform = require 'bee.platform'
local thread = require 'bee.thread'
--dofile(rootPath .. 'server/test.lua')
package.path = package.path
.. ';' .. rootPath .. '?.lua'
.. ';' .. rootPath .. 'server/script/?.lua'
local fsu = require 'fs-utility'
ROOT = fs.path(rootPath)
fs.current_path(ROOT)
require 'package.build'
dofile(rootPath .. 'build-settings.lua')
local json = require 'json'
local function loadPackage()
local buf = fsu.loadFile(ROOT / 'package.json')
if not buf then
error(ROOT:string())
end
local package = json.decode(buf)
return package.version
end
local function createDirectory(version)
local out = ROOT / 'publish' / version
fs.create_directories(out)
return out
end
local function copyFiles(root, out)
return function (dirs)
local count = 0
local function copy(relative, mode)
local source = root / relative
local target = out / relative
if not fs.exists(source) then
return
end
if fs.is_directory(source) then
fs.create_directory(target)
if mode == true then
for path in fs.pairs(source) do
copy(relative / path:filename(), true)
end
else
for name, v in pairs(mode) do
copy(relative / name, v)
end
end
else
fs.copy_file(source, target)
count = count + 1
end
end
copy(fs.path '', dirs)
return count
end
end
local function runTest(root)
local ext = platform.os == 'windows' and '.exe' or ''
local exe = root / 'bin' / 'lua-language-server' .. ext
local test = root / 'test.lua'
local lua = subprocess.spawn {
exe,
test,
'-E',
cwd = root,
stdout = true,
stderr = true,
}
for line in lua.stdout:lines 'l' do
print(line)
end
lua:wait()
local err = lua.stderr:read 'a'
if err ~= '' then
error(err)
end
end
local function removeFiles(out)
return function (dirs)
local function remove(relative, mode)
local target = out / relative
if not fs.exists(target) then
return
end
if fs.is_directory(target) then
if mode == true then
for path in fs.pairs(target) do
remove(relative / path:filename(), true)
end
fs.remove(target)
else
for name, v in pairs(mode) do
remove(relative / name, v)
end
end
else
fs.remove(target)
end
end
remove(fs.path '', dirs)
end
end
local version = loadPackage()
print('版本号为:' .. version)
print('复制 readme ...')
fs.copy_file(ROOT / 'server' / 'changelog.md', ROOT / 'changelog.md', fs.copy_options.overwrite_existing)
fsu.saveFile(ROOT / 'README.md', fsu.loadFile(ROOT / 'server' / 'README.md'):gsub('%.svg', '.png'))
local out = createDirectory('test')
print('输出目录为:', out)
print('清理目录...')
removeFiles(out)(true)
print('开始复制文件...')
local count = copyFiles(ROOT , out) {
['client'] = {
['node_modules'] = true,
['package.json'] = true,
['3rd'] = {
['vscode-lua-doc'] = {
['doc'] = true,
['extension.js'] = true,
},
},
['web'] = true
},
['server'] = {
['bin'] = true,
['doc'] = true,
['locale'] = true,
['script'] = true,
['main.lua'] = true,
['test'] = true,
['test.lua'] = true,
['debugger.lua'] = true,
['changelog.md'] = true,
['meta'] = {
['template'] = true,
['3rd'] = true,
['spell'] = true,
},
},
['images'] = {
['logo.png'] = true,
},
['syntaxes'] = true,
['package.json'] = true,
['README.md'] = true,
['changelog.md'] = true,
['package.nls.json'] = true,
['package.nls.zh-cn.json'] = true,
['package.nls.zh-tw.json'] = true,
['package.nls.pt-br.json'] = true,
}
print(('复制了[%d]个文件'):format(count))
print('开始测试...')
runTest(out / 'server')
print('删除多余文件...')
removeFiles(out) {
['server'] = {
['log'] = true,
['test'] = true,
['test.lua'] = true,
['meta'] = {
['Lua 5.4 zh-cn'] = true,
}
},
}
print('完成')
for i = 5, 0, -1 do
print('将在' .. i .. '秒后发布版本:', version)
thread.sleep(1)
end
local function shell(command)
command.stdout = true
command.stderr = true
command.searchPath = true
local show = {}
for _, c in ipairs(command) do
show[#show+1] = tostring(c)
end
table.insert(command, 1, 'cmd')
table.insert(command, 2, '/c')
print(table.concat(show, ' '))
local p, err = subprocess.spawn(command)
if not p then
error(err)
end
p:wait()
print(p.stdout:read 'a')
print(p.stderr:read 'a')
end
--local vsix = ROOT / 'publish' / ('lua-' .. version .. '.vsix')
--shell {
-- 'vsce', 'package',
-- '-o', vsix,
-- cwd = out,
--}
shell {
'git', 'add', '*',
}
shell {
'git', 'commit', '-m', tostring(version),
}
shell {
'git', 'tag', 'v' .. tostring(version),
}
shell {
'git', 'push',
}
shell {
'git', 'push', '--tags',
}
--shell {
-- 'vsce', 'publish',
-- cwd = out,
--}
--local ovsxToken = fsu.loadFile(ROOT / 'ovsx-token')
--if ovsxToken then
-- ovsxToken = ovsxToken:match '[%w%-]+'
-- shell {
-- 'npx', 'ovsx', 'publish', vsix,
-- '-p', ovsxToken
-- }
--end
print('完成')