Repository navigation
Expand file tree
/
Copy pathclojure.lua
More file actions
100 lines (96 loc) · 3.85 KB
/
Copy pathclojure.lua
File metadata and controls
100 lines (96 loc) · 3.85 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
-- clojure: live GitHub Release crawl (ported from vcollector gh/lans/clojure.go).
local C = dofile(__vmr_plugin_dir .. "/_vmr_common.lua")
plugin_name = "clojure"
sdk_name = "clojure"
plugin_version = "0.1"
homepage = "https://clojure.org/"
ic = C.installer({
flag_files = {
windows = { "ClojureTools.psd1", "ClojureTools.psm1" },
darwin = { "deps.edn", "example-deps.edn" },
linux = { "deps.edn", "example-deps.edn" },
},
binary_dirs = {
windows = { { "bin" } },
darwin = { { "bin" } },
linux = { { "bin" } },
},
flag_dir_excepted = true,
})
function crawl()
return C.github({
repo = "clojure/brew-install",
tag_regex = "\\d+(\\.\\d+){2}",
version_parser = function(tag)
return vmrTrimPrefix(tag, "v")
end,
file_filter = function(name)
if vmrHasSuffix(name, ".zip") then
return true
end
return vmrHasPrefix(name, "clojure") and vmrHasSuffix(name, ".tar.gz")
end,
os_parser = function(name)
if vmrHasSuffix(name, ".zip") then
return "windows"
end
return "unix"
end,
arch_parser = function(_)
return "any"
end,
installer = vmrInstallerUnarchiver,
})
end
function postInstall(path, version, item, archive)
local os = vmrGetOsArch()
local bin = vmrPathJoin(path, "bin")
if not vmrCreateDir(bin) then
error("cannot create Clojure bin directory")
end
if os == "windows" then
local script = "$ErrorActionPreference = 'Stop'\r\nImport-Module (Join-Path $PSScriptRoot '..\\ClojureTools.psd1')\r\nInvoke-Clojure @args\r\nif ($null -ne $LASTEXITCODE) { exit $LASTEXITCODE }\r\n"
for _, name in ipairs({ "clojure", "clj" }) do
local launcher = '@echo off\r\npowershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0' .. name .. '.ps1" %*\r\nexit /b %errorlevel%\r\n'
if not vmrWriteFile(vmrPathJoin(bin, name .. ".ps1"), script)
or not vmrWriteFile(vmrPathJoin(bin, name .. ".cmd"), launcher) then
error("cannot write Clojure launchers")
end
end
else
local lib = vmrPathJoin(path, "lib/clojure")
local libexec = vmrPathJoin(lib, "libexec")
if not vmrCreateDir(libexec) then
error("cannot create Clojure library directory")
end
local entries = vmrReadDir(path)
if not entries then
error("cannot list Clojure installation")
end
for _, name in ipairs(entries) do
if name == "deps.edn" or name == "example-deps.edn" or name == "tools.edn"
or name:match("%.jar$") then
local source = vmrPathJoin(path, name)
local dest = vmrPathJoin(name:match("%.jar$") and libexec or lib, name)
if not vmrCopyFile(source, dest) or not vmrRemoveFile(source) then
error("cannot install Clojure file: " .. name)
end
end
end
for _, launcher in ipairs({ { "clojure", "PREFIX", lib }, { "clj", "BINDIR", bin } }) do
local source = vmrPathJoin(path, launcher[1])
local script = vmrReadFile(source)
if not script:find(launcher[2], 1, true) then
error("Clojure launcher is missing " .. launcher[2])
end
local quoted = "'" .. launcher[3]:gsub("'", "'\\''") .. "'"
script = script:gsub(launcher[2], function() return quoted end)
local dest = vmrPathJoin(bin, launcher[1])
if not vmrWriteFile(dest, script) or not vmrChmodExecutable(dest)
or not vmrRemoveFile(source) then
error("cannot install Clojure launcher: " .. launcher[1])
end
end
end
return true
end