Skip to content

Commit 6112738

Browse files
committed
initialization plugin
1 parent 3c51f43 commit 6112738

9 files changed

+142
-122
lines changed

README.md

+7-15
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-dotnet 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 dotnet
7+
```

hooks/available.lua

+88-15
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,94 @@
11
local util = require("util")
2-
2+
local http = require("http")
3+
local html = require("html")
34
--- Return all available versions provided by this plugin
45
--- @param ctx table Empty table used as context, for future extension
56
--- @return table Descriptions of available versions and accompanying tool descriptions
67
function PLUGIN:Available(ctx)
7-
util:DoSomeThing()
8-
local runtimeVersion = ctx.runtimeVersion
9-
return {
10-
{
11-
version = "xxxx",
12-
note = "LTS",
13-
addition = {
14-
{
15-
name = "npm",
16-
version = "8.8.8",
17-
}
18-
}
19-
}
20-
}
8+
local result = {}
9+
local versions = {}
10+
local resp, err = http.get({
11+
url = util.VERSIONS_URL
12+
})
13+
if err ~= nil or resp.status_code ~= 200 then
14+
error("Getting releases failed: " .. err)
15+
end
16+
local type = util:getOsTypeAndArch()
17+
local doc = html.parse(resp.body)
18+
local tableDoc = doc:find("table")
19+
-- first find available sdk versions
20+
tableDoc:find("tbody"):first():find("tr"):each(function(ti, ts)
21+
local td = ts:find("td")
22+
local downloadLink = td:eq(0):find("a"):attr("href")
23+
local support = td:eq(1):text()
24+
local installableVersion = td:eq(3):text()
25+
local endOfLife = td:eq(5):text():gsub("\n", ""):gsub("%s+$", "")
26+
table.insert(versions, {
27+
version = installableVersion,
28+
url = util.BARE_URL .. downloadLink,
29+
note = "End of Support: " .. endOfLife,
30+
-- sha256 = nil,
31+
})
32+
end)
33+
-- then find os and arch specific version
34+
for _, version in ipairs(versions) do
35+
local resp, err = http.get({
36+
url = version.url
37+
})
38+
if err ~= nil or resp.status_code ~= 200 then
39+
error("Getting specific versions failed: " .. err)
40+
end
41+
local downloadDoc = html.parse(resp.body)
42+
local tableDoc = downloadDoc:find("table"):first():find("tbody"):first()
43+
local osSpecifics = tableDoc:find("tr")
44+
45+
local downloadUrl = ""
46+
47+
if type.osType == "Linux" then
48+
local archVersions = osSpecifics:eq(0):find("td"):eq(1):find("a")
49+
if type.archType == "x64" then
50+
downloadUrl = archVersions:eq(4):attr("href")
51+
elseif type.archType == "Arm64" then
52+
downloadUrl = archVersions:eq(2):attr("href")
53+
elseif type.archType == "x86" then
54+
error("Can't provide dotnet for x86 architecture linux")
55+
end
56+
elseif type.osType == "macOS" then
57+
local archVersions = osSpecifics:eq(1):find("td"):eq(1):find("a")
58+
if type.archType == "x64" then
59+
downloadUrl = archVersions:eq(1):attr("href")
60+
elseif type.archType == "Arm64" then
61+
downloadUrl = archVersions:eq(0):attr("href")
62+
end
63+
elseif type.osType == "Windows" then
64+
local archVersions = osSpecifics:eq(2):find("td"):eq(1):find("a")
65+
if type.archType == "x64" then
66+
downloadUrl = archVersions:eq(1):attr("href")
67+
elseif type.archType == "Arm64" then
68+
downloadUrl = archVersions:eq(0):attr("href")
69+
elseif type.archType == "x86" then
70+
downloadUrl = archVersions:eq(2):attr("href")
71+
end
72+
end
73+
74+
-- after getting download url parse direct download link and checksum
75+
local resp, err = http.get({
76+
url = util.BARE_URL .. downloadUrl
77+
})
78+
if err ~= nil or resp.status_code ~= 200 then
79+
error("Getting specific versions failed: " .. err)
80+
end
81+
82+
local directLinkDoc = html.parse(resp.body)
83+
local directLink = directLinkDoc:find("a#directLink"):attr("href")
84+
local checksum = directLinkDoc:find("input#checksum"):attr("value")
85+
86+
table.insert(result, {
87+
version = version.version,
88+
url = directLink,
89+
note = version.note,
90+
sha512 = checksum
91+
})
92+
end
93+
return result
2194
end

hooks/env_keys.lua

+3-17
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,15 @@
66
function PLUGIN:EnvKeys(ctx)
77
--- this variable is same as ctx.sdkInfo['plugin-name'].path
88
local mainPath = ctx.path
9-
local runtimeVersion = ctx.runtimeVersion
10-
local mainSdkInfo = ctx.main
11-
local mpath = mainSdkInfo.path
12-
local mversion = mainSdkInfo.version
13-
local mname = mainSdkInfo.name
14-
local sdkInfo = ctx.sdkInfo['sdk-name']
15-
local path = sdkInfo.path
16-
local version = sdkInfo.version
17-
local name = sdkInfo.name
189
return {
1910
{
20-
key = "JAVA_HOME",
11+
key = "DOTNET_ROOT",
2112
value = mainPath
2213
},
2314
{
2415
key = "PATH",
25-
value = mainPath .. "/bin"
26-
},
27-
{
28-
key = "PATH",
29-
value = mainPath .. "/bin2"
30-
},
31-
16+
value = mainPath
17+
}
3218
}
3319

3420
end

hooks/post_install.lua

+1-6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,5 @@
33
--- Currently can be left unimplemented!
44
function PLUGIN:PostInstall(ctx)
55
--- ctx.rootPath SDK installation directory
6-
local rootPath = ctx.rootPath
7-
local runtimeVersion = ctx.runtimeVersion
8-
local sdkInfo = ctx.sdkInfo['sdk-name']
9-
local path = sdkInfo.path
10-
local version = sdkInfo.version
11-
local name = sdkInfo.name
6+
--do nothing
127
end

hooks/pre_install.lua

+7-33
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,11 @@
44
--- @field ctx.version string User-input version
55
--- @return table Version information
66
function PLUGIN:PreInstall(ctx)
7-
local version = ctx.version
8-
local runtimeVersion = ctx.runtimeVersion
9-
return {
10-
--- Version number
11-
version = "xxx",
12-
--- remote URL or local file path [optional]
13-
url = "xxx",
14-
--- SHA256 checksum [optional]
15-
sha256 = "xxx",
16-
--- md5 checksum [optional]
17-
md5 = "xxx",
18-
--- sha1 checksum [optional]
19-
sha1 = "xxx",
20-
--- sha512 checksum [optional]
21-
sha512 = "xx",
22-
--- additional need files [optional]
23-
addition = {
24-
{
25-
--- additional file name !
26-
name = "xxx",
27-
--- remote URL or local file path [optional]
28-
url = "xxx",
29-
--- SHA256 checksum [optional]
30-
sha256 = "xxx",
31-
--- md5 checksum [optional]
32-
md5 = "xxx",
33-
--- sha1 checksum [optional]
34-
sha1 = "xxx",
35-
--- sha512 checksum [optional]
36-
sha512 = "xx",
37-
}
38-
}
39-
}
7+
local releases = self:Available(ctx)
8+
for _, release in ipairs(releases) do
9+
if release.version == ctx.version then
10+
return release
11+
end
12+
end
13+
return {}
4014
end

hooks/pre_use.lua

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

lib/uil.lua

-8
This file was deleted.

lib/util.lua

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
local util = {}
3+
4+
util.BARE_URL = "https://dotnet.microsoft.com"
5+
util.VERSIONS_URL = "https://dotnet.microsoft.com/en-us/download/dotnet"
6+
7+
8+
function util:getOsTypeAndArch()
9+
local osType = RUNTIME.osType
10+
local archType = RUNTIME.archType
11+
if RUNTIME.osType == "darwin" then
12+
osType = "macOS"
13+
elseif RUNTIME.osType == "linux" then
14+
osType = "Linux"
15+
elseif RUNTIME.osType == "windows" then
16+
osType = "Windows"
17+
end
18+
if RUNTIME.archType == "amd64" then
19+
archType = "x64"
20+
elseif RUNTIME.archType == "arm64" then
21+
archType = "Arm64"
22+
elseif RUNTIME.archType == "386" then
23+
archType = "x86"
24+
end
25+
return {
26+
osType = osType, archType = archType
27+
}
28+
end
29+
30+
return util

metadata.lua

+5-5
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 = "dotnet"
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-dotnet"
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 = "dotnet plugin, support for dotnet sdks 6.0, 7.0, 8.0"
1515

1616

1717
--- !!! OPTIONAL !!!
@@ -33,7 +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-dotnet/releases/download/manifest/manifest.json"
3737
-- Some things that need user to be attention!
3838
PLUGIN.notes = {
3939
"",

0 commit comments

Comments
 (0)