diff options
author | actboy168 <actboy168@gmail.com> | 2019-06-10 16:03:59 +0800 |
---|---|---|
committer | actboy168 <actboy168@gmail.com> | 2019-06-10 16:03:59 +0800 |
commit | 7d1a60dfcbffd163c56cc319bd13a51e8ff405b1 (patch) | |
tree | ffaca535468c7a019a4b19469cad49e25920b46b /make/copy.lua | |
parent | 55ec1070ea56297151f06a988322c4a8b404c607 (diff) | |
download | lua-language-server-7d1a60dfcbffd163c56cc319bd13a51e8ff405b1.zip |
安装脚本
Diffstat (limited to 'make/copy.lua')
-rw-r--r-- | make/copy.lua | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/make/copy.lua b/make/copy.lua new file mode 100644 index 00000000..253c1332 --- /dev/null +++ b/make/copy.lua @@ -0,0 +1,58 @@ +local fs = require 'bee.filesystem' + +local function getExtensionDirName(packageDir) + local publisher,name,version + for line in io.lines(packageDir .. '/package.json') do + if not publisher then + publisher = line:match('"publisher": "([^"]+)"') + end + if not name then + name = line:match('"name": "([^"]+)"') + end + if not version then + version = line:match('"version": "(%d+%.%d+%.%d+)"') + end + end + if not publisher then + error 'Cannot found `publisher` in package.json.' + end + if not name then + error 'Cannot found `name` in package.json.' + end + if not version then + error 'Cannot found `version` in package.json.' + end + return ('%s.%s-%s'):format(publisher,name,version) +end + +local function copy_directory(from, to, filter) + fs.create_directories(to) + for fromfile in from:list_directory() do + if fs.is_directory(fromfile) then + copy_directory(fromfile, to / fromfile:filename(), filter) + else + if (not filter) or filter(fromfile) then + print('copy', fromfile, to / fromfile:filename()) + fs.copy_file(fromfile, to / fromfile:filename(), true) + end + end + end +end + +local extensionPath = ... +local packageDir = "." +local sourceDir = fs.path(".") +local extensionDirName = getExtensionDirName(packageDir) +local extensionDir = fs.path(extensionPath) / extensionDirName +if not fs.exists(extensionDir) then + error(extensionDir .. "is not installed.") +end + +if pcall(fs.remove_all, extensionDir / "server" / "bin-bak") then + fs.rename(extensionDir / "server" / "bin", extensionDir / "server" / "bin-bak") +else + fs.remove_all(extensionDir / "server" / "bin") +end +copy_directory(sourceDir / "server" / "bin", extensionDir / "server" / "bin") + +print 'ok' |