Skip to content

Commit

Permalink
init plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ahai-code committed Apr 3, 2024
1 parent bfaaf99 commit 15f734d
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 113 deletions.
22 changes: 7 additions & 15 deletions README.md
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
```
31 changes: 17 additions & 14 deletions hooks/available.lua
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
23 changes: 5 additions & 18 deletions hooks/env_keys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,16 @@
--- @field ctx.path string SDK installation directory
function PLUGIN:EnvKeys(ctx)
--- this variable is same as ctx.sdkInfo['plugin-name'].path
local mainPath = ctx.path
local mainSdkInfo = ctx.main
local mpath = mainSdkInfo.path
local mversion = mainSdkInfo.version
local mname = mainSdkInfo.name
local sdkInfo = ctx.sdkInfo['sdk-name']
local path = sdkInfo.path
local version = sdkInfo.version
local name = sdkInfo.name
local path = ctx.path
return {
{
key = "JAVA_HOME",
value = mainPath
key = "SCALA_HOME",
value = path
},
{
key = "PATH",
value = mainPath .. "/bin"
},
{
key = "PATH",
value = mainPath .. "/bin2"
},

value = path .. "/bin"
}
}

end
8 changes: 1 addition & 7 deletions hooks/post_install.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,5 @@
--- such as file operations for the SDK installation directory or compile source code
--- Currently can be left unimplemented!
function PLUGIN:PostInstall(ctx)
--- ctx.rootPath SDK installation directory
local rootPath = ctx.rootPath
local sdkInfo = ctx.sdkInfo['sdk-name']
local path = sdkInfo.path
local version = sdkInfo.version
local name = sdkInfo.name
local note = sdkInfo.note
--do nothing
end
34 changes: 5 additions & 29 deletions hooks/pre_install.lua
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
23 changes: 1 addition & 22 deletions hooks/pre_use.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,5 @@
--- valid version information.
--- @param ctx table Context information
function PLUGIN:PreUse(ctx)
--- user input version
local version = ctx.version
--- user current used version
local previousVersion = ctx.previousVersion

--- installed sdks
local sdkInfo = ctx.installedSdks['version']
local path = sdkInfo.path
local name = sdkInfo.name
local version = sdkInfo.version

--- working directory
local cwd = ctx.cwd

--- user input scope
--- could be one of global/project/session
local scope = ctx.scope

--- return the version information
return {
version = version,
}
--do nothing
end
59 changes: 57 additions & 2 deletions lib/util.lua
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
11 changes: 5 additions & 6 deletions metadata.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ PLUGIN = {}

--- !!! MUST BE SET !!!
--- Plugin name
PLUGIN.name = "your plugin name"
PLUGIN.name = "scala"
--- Plugin version
PLUGIN.version = "0.0.1"
PLUGIN.version = "0.1.0"
--- Plugin homepage
PLUGIN.homepage = "https://github.com/version-fox/vfox-plugin-template"
PLUGIN.homepage = "https://github.com/version-fox/vfox-scala"
--- Plugin license, please choose a correct license according to your needs.
PLUGIN.license = "Apache 2.0"
--- Plugin description
PLUGIN.description = "your plugin description"
PLUGIN.description = "Scala plugin, https://www.scala-lang.org/"


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

0 comments on commit 15f734d

Please sign in to comment.