diff --git a/README.md b/README.md
index 5f50b89..98f3539 100644
--- a/README.md
+++ b/README.md
@@ -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
+```
\ No newline at end of file
diff --git a/hooks/available.lua b/hooks/available.lua
index a5e6e3b..5d95ebf 100644
--- a/hooks/available.lua
+++ b/hooks/available.lua
@@ -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('
') do
+ table.insert(result, {version = match:gsub("^Scala ", ""), note = ""})
+ end
+
+ return result
end
\ No newline at end of file
diff --git a/hooks/env_keys.lua b/hooks/env_keys.lua
index aa80ad2..eaf69fc 100644
--- a/hooks/env_keys.lua
+++ b/hooks/env_keys.lua
@@ -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
\ No newline at end of file
diff --git a/hooks/post_install.lua b/hooks/post_install.lua
index 4bf262a..56c3b96 100644
--- a/hooks/post_install.lua
+++ b/hooks/post_install.lua
@@ -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
\ No newline at end of file
diff --git a/hooks/pre_install.lua b/hooks/pre_install.lua
index 1a9c34c..7d31763 100644
--- a/hooks/pre_install.lua
+++ b/hooks/pre_install.lua
@@ -1,3 +1,4 @@
+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
@@ -5,35 +6,10 @@
--- @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
\ No newline at end of file
diff --git a/hooks/pre_use.lua b/hooks/pre_use.lua
index daf6d36..98235ef 100644
--- a/hooks/pre_use.lua
+++ b/hooks/pre_use.lua
@@ -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
\ No newline at end of file
diff --git a/lib/util.lua b/lib/util.lua
index 7a7f8d9..e3645f7 100644
--- a/lib/util.lua
+++ b/lib/util.lua
@@ -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
\ No newline at end of file
diff --git a/metadata.lua b/metadata.lua
index d221628..c5ad2ed 100644
--- a/metadata.lua
+++ b/metadata.lua
@@ -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 !!!
@@ -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 = {
- "",
}