Skip to content

Commit 15f734d

Browse files
committed
init plugin
1 parent bfaaf99 commit 15f734d

File tree

8 files changed

+98
-113
lines changed

8 files changed

+98
-113
lines changed

README.md

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
# vfox-plugin-template
2-
3-
This is a [vfox plugin](https://vfox.lhan.me/plugins/create/howto.html) template with CI that package and publish the plugin.
4-
5-
## Usage
6-
7-
1. [Generate](https://github.com/version-fox/vfox-plugin-template/generate) a new repository based on this template.
8-
2. Configure [metadata](https://github.com/version-fox/vfox-plugin-template/blob/main/metadata.lua) information
9-
3. To develop your plugin further, please read [the plugins create section of the docs](https://vfox.lhan.me/plugins/create/howto.html).
10-
11-
12-
## How to publish?
13-
14-
1. Push a new tag to the repository which name is `vX.Y.Z` (X.Y.Z is the version number).
15-
2. The CI will automatically package, then publish [release](https://github.com/version-fox/vfox-plugin-template/releases/tag/v0.0.1) and publish [manifest](https://github.com/version-fox/vfox-plugin-template/releases/tag/manifest).
1+
# Introduction
2+
vfox-scala is a plugin for [vfox](https://vfox.lhan.me/).
3+
# Install
4+
After installing vfox, run the following command to add the plugin:
5+
```bash
6+
vfox add scala
7+
```

hooks/available.lua

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
local util = require("util")
2-
2+
local http = require("http")
33
--- Return all available versions provided by this plugin
44
--- @param ctx table Empty table used as context, for future extension
55
--- @return table Descriptions of available versions and accompanying tool descriptions
66
function PLUGIN:Available(ctx)
7-
util:DoSomeThing()
8-
return {
9-
{
10-
version = "xxxx",
11-
note = "LTS",
12-
addition = {
13-
{
14-
name = "npm",
15-
version = "8.8.8",
16-
}
17-
}
18-
}
19-
}
7+
local resp, err = http.get({
8+
url = util.SEARCH_URL
9+
})
10+
print(err)
11+
if err ~= nil or resp.status_code ~= 200 then
12+
return {}
13+
end
14+
local htmlBody = resp.body
15+
local htmlContent= [[]] .. htmlBody .. [[]]
16+
local result = {}
17+
18+
for match in htmlContent:gmatch('<div class="download%-elem">.-<a href="[^"]-">([^<]-)</a>.-</div>') do
19+
table.insert(result, {version = match:gsub("^Scala ", ""), note = ""})
20+
end
21+
22+
return result
2023
end

hooks/env_keys.lua

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,16 @@
55
--- @field ctx.path string SDK installation directory
66
function PLUGIN:EnvKeys(ctx)
77
--- this variable is same as ctx.sdkInfo['plugin-name'].path
8-
local mainPath = ctx.path
9-
local mainSdkInfo = ctx.main
10-
local mpath = mainSdkInfo.path
11-
local mversion = mainSdkInfo.version
12-
local mname = mainSdkInfo.name
13-
local sdkInfo = ctx.sdkInfo['sdk-name']
14-
local path = sdkInfo.path
15-
local version = sdkInfo.version
16-
local name = sdkInfo.name
8+
local path = ctx.path
179
return {
1810
{
19-
key = "JAVA_HOME",
20-
value = mainPath
11+
key = "SCALA_HOME",
12+
value = path
2113
},
2214
{
2315
key = "PATH",
24-
value = mainPath .. "/bin"
25-
},
26-
{
27-
key = "PATH",
28-
value = mainPath .. "/bin2"
29-
},
30-
16+
value = path .. "/bin"
17+
}
3118
}
3219

3320
end

hooks/post_install.lua

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,5 @@
22
--- such as file operations for the SDK installation directory or compile source code
33
--- Currently can be left unimplemented!
44
function PLUGIN:PostInstall(ctx)
5-
--- ctx.rootPath SDK installation directory
6-
local rootPath = ctx.rootPath
7-
local sdkInfo = ctx.sdkInfo['sdk-name']
8-
local path = sdkInfo.path
9-
local version = sdkInfo.version
10-
local name = sdkInfo.name
11-
local note = sdkInfo.note
5+
--do nothing
126
end

hooks/pre_install.lua

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,15 @@
1+
local util = require("util")
12
--- Returns some pre-installed information, such as version number, download address, local files, etc.
23
--- If checksum is provided, vfox will automatically check it for you.
34
--- @param ctx table
45
--- @field ctx.version string User-input version
56
--- @return table Version information
67
function PLUGIN:PreInstall(ctx)
78
local version = ctx.version
9+
local downloadUrl = util:getDownloadUrl(version)
10+
print(downloadUrl)
811
return {
9-
--- Version number
10-
version = "xxx",
11-
--- remote URL or local file path [optional]
12-
url = "xxx",
13-
--- SHA256 checksum [optional]
14-
sha256 = "xxx",
15-
--- md5 checksum [optional]
16-
md5 = "xxx",
17-
--- sha1 checksum [optional]
18-
sha1 = "xxx",
19-
--- sha512 checksum [optional]
20-
sha512 = "xx",
21-
--- additional need files [optional]
22-
addition = {
23-
{
24-
--- additional file name !
25-
name = "xxx",
26-
--- remote URL or local file path [optional]
27-
url = "xxx",
28-
--- SHA256 checksum [optional]
29-
sha256 = "xxx",
30-
--- md5 checksum [optional]
31-
md5 = "xxx",
32-
--- sha1 checksum [optional]
33-
sha1 = "xxx",
34-
--- sha512 checksum [optional]
35-
sha512 = "xx",
36-
}
37-
}
12+
version = version,
13+
url = downloadUrl,
3814
}
3915
end

hooks/pre_use.lua

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,5 @@
22
--- valid version information.
33
--- @param ctx table Context information
44
function PLUGIN:PreUse(ctx)
5-
--- user input version
6-
local version = ctx.version
7-
--- user current used version
8-
local previousVersion = ctx.previousVersion
9-
10-
--- installed sdks
11-
local sdkInfo = ctx.installedSdks['version']
12-
local path = sdkInfo.path
13-
local name = sdkInfo.name
14-
local version = sdkInfo.version
15-
16-
--- working directory
17-
local cwd = ctx.cwd
18-
19-
--- user input scope
20-
--- could be one of global/project/session
21-
local scope = ctx.scope
22-
23-
--- return the version information
24-
return {
25-
version = version,
26-
}
5+
--do nothing
276
end

lib/util.lua

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,63 @@
11

22
local util = {}
33

4-
function util:DoSomeThing()
5-
print("Do some thing")
4+
util.SEARCH_URL = "https://www.scala-lang.org/download/all.html"
5+
util.SCALA3_DOWNLOAD_URL = "https://github.com/scala/scala3/releases/download/%s/scala3-%s.%s"
6+
util.SCALA2_DOWNLOAD_URL_2104_UP = "https://downloads.lightbend.com/scala/%s/scala-%s.%s"
7+
util.SCALA2_DOWNLOAD_URL_250_UP = "https://scala-lang.org/files/archive/scala-%s.%s"
8+
9+
function util:compare_versions(v1o, v2o)
10+
local v1 = v1o.version
11+
local v2 = v2o.version
12+
local v1_parts = {}
13+
for part in string.gmatch(v1, "[^.]+") do
14+
table.insert(v1_parts, tonumber(part))
15+
end
16+
17+
local v2_parts = {}
18+
for part in string.gmatch(v2, "[^.]+") do
19+
table.insert(v2_parts, tonumber(part))
20+
end
21+
22+
for i = 1, math.max(#v1_parts, #v2_parts) do
23+
local v1_part = v1_parts[i] or 0
24+
local v2_part = v2_parts[i] or 0
25+
if v1_part > v2_part then
26+
return true
27+
elseif v1_part < v2_part then
28+
return false
29+
end
30+
end
31+
32+
return false
33+
end
34+
35+
function util:getDownloadUrl(version)
36+
local suffixType = ""
37+
local downloadUrl = ""
38+
if RUNTIME.osType == "windows" then
39+
suffixType = "zip"
40+
else
41+
if util:compare_versions({version="2.7.1"},{version=version}) or util:compare_versions({version=version},{version="3.0.0"})then
42+
suffixType = "tar.gz"
43+
else
44+
suffixType = "tgz"
45+
end
46+
end
47+
48+
if util:compare_versions({version=version},{version="2.5.0"}) and util:compare_versions({version="2.10.4"},{version=version}) then
49+
if util:compare_versions({version="2.7.0"},{version=version}) then
50+
version = version:gsub("%.final", "-final")
51+
end
52+
downloadUrl = util.SCALA2_DOWNLOAD_URL_250_UP:format(version,suffixType)
53+
elseif util:compare_versions({version="3.0.0"},{version=version}) then
54+
downloadUrl = util.SCALA2_DOWNLOAD_URL_2104_UP:format(version, version,suffixType)
55+
else
56+
downloadUrl = util.SCALA3_DOWNLOAD_URL:format(version, version,suffixType)
57+
end
58+
59+
return downloadUrl
60+
661
end
762

863
return util

metadata.lua

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ PLUGIN = {}
33

44
--- !!! MUST BE SET !!!
55
--- Plugin name
6-
PLUGIN.name = "your plugin name"
6+
PLUGIN.name = "scala"
77
--- Plugin version
8-
PLUGIN.version = "0.0.1"
8+
PLUGIN.version = "0.1.0"
99
--- Plugin homepage
10-
PLUGIN.homepage = "https://github.com/version-fox/vfox-plugin-template"
10+
PLUGIN.homepage = "https://github.com/version-fox/vfox-scala"
1111
--- Plugin license, please choose a correct license according to your needs.
1212
PLUGIN.license = "Apache 2.0"
1313
--- Plugin description
14-
PLUGIN.description = "your plugin description"
14+
PLUGIN.description = "Scala plugin, https://www.scala-lang.org/"
1515

1616

1717
--- !!! OPTIONAL !!!
@@ -33,8 +33,7 @@ NOTE:
3333
you can set this address to the manifest file address, so that the plugin can be updated automatically.
3434
3535
--]]
36-
PLUGIN.manifestUrl = "https://github.com/version-fox/vfox-plugin-template/releases/download/manifest/manifest.json"
36+
PLUGIN.manifestUrl = "https://github.com/version-fox/vfox-scala/releases/download/manifest/manifest.json"
3737
-- Some things that need user to be attention!
3838
PLUGIN.notes = {
39-
"",
4039
}

0 commit comments

Comments
 (0)