summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-13 12:27:58 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-13 12:27:58 +0800
commit8b6b83093031d586ced64146cd35cc616121a9c9 (patch)
treeedd9a3d3ce58bdf5160e69e4b556d23101ab6454
parent11004db9fc51a552107ae6d54fbaef8f37694e2f (diff)
downloadlua-language-server-8b6b83093031d586ced64146cd35cc616121a9c9.zip
发布时更新node_module
-rw-r--r--server/publish.lua29
1 files changed, 19 insertions, 10 deletions
diff --git a/server/publish.lua b/server/publish.lua
index 76d36472..643faf03 100644
--- a/server/publish.lua
+++ b/server/publish.lua
@@ -9,10 +9,20 @@ package.path = (ROOT / 'src' / '?.lua'):string()
require 'utility'
local json = require 'json'
-local function loadVersion()
+local function loadPackage()
local buf = io.load(EXTENSION / 'package.json')
local package = json.decode(buf)
- return package.version
+ return package.version, package.scripts.postinstall
+end
+
+local function updateNodeModules(postinstall)
+ local current = fs.current_path()
+ fs.current_path(EXTENSION)
+ local cmd = io.popen(postinstall)
+ for line in cmd:lines 'l' do
+ print(line)
+ end
+ fs.current_path(current)
end
local function createDirectory(version)
@@ -28,6 +38,7 @@ local function copyFiles(out)
local source = EXTENSION / relative
local target = out / relative
if not fs.exists(source) then
+ error('文件不存在: ' .. tostring(source))
return
end
if fs.is_directory(source) then
@@ -62,13 +73,8 @@ local function runTest(root)
stdout = true,
stderr = true,
}
- while true do
- local out = lua.stdout:read 'l'
- if out then
- print(out)
- else
- break
- end
+ for line in lua.stdout:lines 'l' do
+ print(line)
end
lua:wait()
local err = lua.stderr:read 'a'
@@ -104,11 +110,14 @@ local function removeFiles(out)
end
end
-local version = loadVersion()
+local version, postinstall = loadPackage()
print('版本号为:' .. version)
local out = createDirectory(version)
+print('更新NodeModules...')
+updateNodeModules(postinstall)
+
print('清理目录...')
removeFiles(out)(true)