generated from version-fox/vfox-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
98 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,7 @@ | ||
# vfox-plugin-template | ||
|
||
This is a [vfox plugin](https://vfox.lhan.me/plugins/create/howto.html) template with CI that package and publish the plugin. | ||
|
||
## Usage | ||
|
||
1. [Generate](https://github.com/version-fox/vfox-plugin-template/generate) a new repository based on this template. | ||
2. Configure [metadata](https://github.com/version-fox/vfox-plugin-template/blob/main/metadata.lua) information | ||
3. To develop your plugin further, please read [the plugins create section of the docs](https://vfox.lhan.me/plugins/create/howto.html). | ||
|
||
|
||
## How to publish? | ||
|
||
1. Push a new tag to the repository which name is `vX.Y.Z` (X.Y.Z is the version number). | ||
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). | ||
# Introduction | ||
vfox-scala is a plugin for [vfox](https://vfox.lhan.me/). | ||
# Install | ||
After installing vfox, run the following command to add the plugin: | ||
```bash | ||
vfox add scala | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
local util = require("util") | ||
|
||
local http = require("http") | ||
--- Return all available versions provided by this plugin | ||
--- @param ctx table Empty table used as context, for future extension | ||
--- @return table Descriptions of available versions and accompanying tool descriptions | ||
function PLUGIN:Available(ctx) | ||
util:DoSomeThing() | ||
return { | ||
{ | ||
version = "xxxx", | ||
note = "LTS", | ||
addition = { | ||
{ | ||
name = "npm", | ||
version = "8.8.8", | ||
} | ||
} | ||
} | ||
} | ||
local resp, err = http.get({ | ||
url = util.SEARCH_URL | ||
}) | ||
print(err) | ||
if err ~= nil or resp.status_code ~= 200 then | ||
return {} | ||
end | ||
local htmlBody = resp.body | ||
local htmlContent= [[]] .. htmlBody .. [[]] | ||
local result = {} | ||
|
||
for match in htmlContent:gmatch('<div class="download%-elem">.-<a href="[^"]-">([^<]-)</a>.-</div>') do | ||
table.insert(result, {version = match:gsub("^Scala ", ""), note = ""}) | ||
end | ||
|
||
return result | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,15 @@ | ||
local util = require("util") | ||
--- Returns some pre-installed information, such as version number, download address, local files, etc. | ||
--- If checksum is provided, vfox will automatically check it for you. | ||
--- @param ctx table | ||
--- @field ctx.version string User-input version | ||
--- @return table Version information | ||
function PLUGIN:PreInstall(ctx) | ||
local version = ctx.version | ||
local downloadUrl = util:getDownloadUrl(version) | ||
print(downloadUrl) | ||
return { | ||
--- Version number | ||
version = "xxx", | ||
--- remote URL or local file path [optional] | ||
url = "xxx", | ||
--- SHA256 checksum [optional] | ||
sha256 = "xxx", | ||
--- md5 checksum [optional] | ||
md5 = "xxx", | ||
--- sha1 checksum [optional] | ||
sha1 = "xxx", | ||
--- sha512 checksum [optional] | ||
sha512 = "xx", | ||
--- additional need files [optional] | ||
addition = { | ||
{ | ||
--- additional file name ! | ||
name = "xxx", | ||
--- remote URL or local file path [optional] | ||
url = "xxx", | ||
--- SHA256 checksum [optional] | ||
sha256 = "xxx", | ||
--- md5 checksum [optional] | ||
md5 = "xxx", | ||
--- sha1 checksum [optional] | ||
sha1 = "xxx", | ||
--- sha512 checksum [optional] | ||
sha512 = "xx", | ||
} | ||
} | ||
version = version, | ||
url = downloadUrl, | ||
} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,63 @@ | ||
|
||
local util = {} | ||
|
||
function util:DoSomeThing() | ||
print("Do some thing") | ||
util.SEARCH_URL = "https://www.scala-lang.org/download/all.html" | ||
util.SCALA3_DOWNLOAD_URL = "https://github.com/scala/scala3/releases/download/%s/scala3-%s.%s" | ||
util.SCALA2_DOWNLOAD_URL_2104_UP = "https://downloads.lightbend.com/scala/%s/scala-%s.%s" | ||
util.SCALA2_DOWNLOAD_URL_250_UP = "https://scala-lang.org/files/archive/scala-%s.%s" | ||
|
||
function util:compare_versions(v1o, v2o) | ||
local v1 = v1o.version | ||
local v2 = v2o.version | ||
local v1_parts = {} | ||
for part in string.gmatch(v1, "[^.]+") do | ||
table.insert(v1_parts, tonumber(part)) | ||
end | ||
|
||
local v2_parts = {} | ||
for part in string.gmatch(v2, "[^.]+") do | ||
table.insert(v2_parts, tonumber(part)) | ||
end | ||
|
||
for i = 1, math.max(#v1_parts, #v2_parts) do | ||
local v1_part = v1_parts[i] or 0 | ||
local v2_part = v2_parts[i] or 0 | ||
if v1_part > v2_part then | ||
return true | ||
elseif v1_part < v2_part then | ||
return false | ||
end | ||
end | ||
|
||
return false | ||
end | ||
|
||
function util:getDownloadUrl(version) | ||
local suffixType = "" | ||
local downloadUrl = "" | ||
if RUNTIME.osType == "windows" then | ||
suffixType = "zip" | ||
else | ||
if util:compare_versions({version="2.7.1"},{version=version}) or util:compare_versions({version=version},{version="3.0.0"})then | ||
suffixType = "tar.gz" | ||
else | ||
suffixType = "tgz" | ||
end | ||
end | ||
|
||
if util:compare_versions({version=version},{version="2.5.0"}) and util:compare_versions({version="2.10.4"},{version=version}) then | ||
if util:compare_versions({version="2.7.0"},{version=version}) then | ||
version = version:gsub("%.final", "-final") | ||
end | ||
downloadUrl = util.SCALA2_DOWNLOAD_URL_250_UP:format(version,suffixType) | ||
elseif util:compare_versions({version="3.0.0"},{version=version}) then | ||
downloadUrl = util.SCALA2_DOWNLOAD_URL_2104_UP:format(version, version,suffixType) | ||
else | ||
downloadUrl = util.SCALA3_DOWNLOAD_URL:format(version, version,suffixType) | ||
end | ||
|
||
return downloadUrl | ||
|
||
end | ||
|
||
return util |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters