Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/test-vfox.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: test-vfox

on:
pull_request:
push:
branches: [main]

concurrency:
group: test-vfox-${{ github.ref }}
cancel-in-progress: true

jobs:
"test-vfox":
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: Swatinem/rust-cache@v2
- run: |
cargo build --all-features
echo "$PWD/target/debug" >> "$GITHUB_PATH"
- run: mise -v
- run: mise --cd crates/vfox install
- uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4
with:
key: ${{ runner.os }}-${{ runner.arch }}-mise-tools-vfox-${{ hashFiles('crates/vfox/mise.toml') }}
path: |
~/.local/share/mise
~/.cache/mise
- run: mise --cd crates/vfox run build
- run: mise --cd crates/vfox run lint
- run: mise --cd crates/vfox run test
2 changes: 2 additions & 0 deletions crates/vfox/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[env]
RUST_TEST_THREADS = '1'
1 change: 1 addition & 0 deletions crates/vfox/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test/downloads
1 change: 1 addition & 0 deletions crates/vfox/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
plugins/nodejs
30 changes: 30 additions & 0 deletions crates/vfox/mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[tools]
"cargo-binstall" = "latest"
"cargo:cargo-edit" = "latest"
"cargo:git-cliff" = "latest"
"npm:prettier" = "latest"

[tasks.build]
run = "cargo build"
[tasks.test]
alias = "t"
depends = ['test:setup-plugins']
run = "cargo test"
[tasks."test:setup-plugins"]
run = [
"mkdir -p plugins",
"test -d plugins/nodejs || git clone https://github.com/version-fox/vfox-nodejs plugins/nodejs",
"test -d plugins/cmake || git clone https://github.com/version-fox/vfox-cmake plugins/cmake",
]
[tasks.lint-fix]
run = "cargo fmt --all && cargo clippy --fix --all --all-features --allow-dirty --allow-staged -- -D warnings"
[tasks.lint]
depends = ['lint:prettier', 'lint:clippy', 'lint:fmt']
[tasks."lint:prettier"]
run = "prettier -c ."
[tasks."lint:clippy"]
run = 'cargo clippy --all-features -- -D warnings'
[tasks."lint:fmt"]
run = 'cargo fmt --all -- --check'
[tasks.pre-commit]
depends = ['lint:*']
2 changes: 2 additions & 0 deletions crates/vfox/plugins/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cmake
nodejs
15 changes: 15 additions & 0 deletions crates/vfox/plugins/dummy/Injection.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--[[
Do not change any thing in the current file,
it's just there to show what objects are injected by vfox and what they do.

It's just handy when developing plugins, IDE can use this object for code hints!
--]]
RUNTIME = {
--- Operating system type at runtime (Windows, Linux, Darwin)
osType = "",
--- Operating system architecture at runtime (amd64, arm64, etc.)
archType = "",
--- vfox runtime version
version = "",
}

16 changes: 16 additions & 0 deletions crates/vfox/plugins/dummy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# vfox-nodejs

Node.js plugin for [vfox](https://vfox.lhan.me/).

## Install

After installing [vfox](https://github.com/version-fox/vfox), install the plugin by running:

```bash
vfox add nodejs
```

## Mirror

You can configure the mirror by `VFOX_NODEJS_MIRROR` environment variable. The default value
is `https://nodejs.org/dist/`.
13 changes: 13 additions & 0 deletions crates/vfox/plugins/dummy/hooks/available.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--- 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)
return {
{
version = "1.0.0",
},
{
version = "1.0.1",
},
}
end
25 changes: 25 additions & 0 deletions crates/vfox/plugins/dummy/hooks/env_keys.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--- Each SDK may have different environment variable configurations.
--- This allows plugins to define custom environment variables (including PATH settings)
--- Note: Be sure to distinguish between environment variable settings for different platforms!
--- @param ctx table Context information
--- @field ctx.path string SDK installation directory
function PLUGIN:EnvKeys(ctx)
--- this variable is same as ctx.sdkInfo['plugin-name'].path
local version_path = ctx.path
if RUNTIME.osType == "windows" then
return {
{
key = "PATH",
value = version_path
},
}
else
return {
{
key = "PATH",
value = version_path .. "/bin"
},
}
end

end
22 changes: 22 additions & 0 deletions crates/vfox/plugins/dummy/hooks/parse_legacy_file.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--- Parse legacy version files like .node-version, .nvmrc, etc.
--- @param ctx table Context information
--- @field ctx.filepath string Path to the legacy file
--- @return table Version information
function PLUGIN:ParseLegacyFile(ctx)
local filepath = ctx.filepath
local content = io.open(filepath, "r")
if content then
local version = content:read("*line")
content:close()
if version then
-- Remove any "v" prefix and trim whitespace
version = version:gsub("^v", ""):match("^%s*(.-)%s*$")
return {
version = version
}
end
end
return {
version = nil
}
end
11 changes: 11 additions & 0 deletions crates/vfox/plugins/dummy/hooks/post_install.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function PLUGIN:PostInstall(ctx)
--- SDK installation root path
local rootPath = ctx.rootPath
local runtimeVersion = ctx.runtimeVersion
--- Other SDK information, the `addition` field returned in PreInstall, obtained by name
--TODO
--local sdkInfo = ctx.sdkInfo['dummy']
--local path = sdkInfo.path
--local version = sdkInfo.version
--local name = sdkInfo.name
end
12 changes: 12 additions & 0 deletions crates/vfox/plugins/dummy/hooks/pre_install.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--- 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

return {
version = version,
}
end
26 changes: 26 additions & 0 deletions crates/vfox/plugins/dummy/metadata.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--- !!! DO NOT EDIT OR RENAME !!!
PLUGIN = {}

--- !!! MUST BE SET !!!
--- Plugin name
PLUGIN.name = "dummy"
--- Plugin version
PLUGIN.version = "0.3.0"
--- Plugin repository
PLUGIN.homepage = "https://github.com/version-fox/vfox-nodejs"
--- Plugin license
PLUGIN.license = "Apache 2.0"
--- Plugin description
PLUGIN.description = "Dummy plugin for testing."

--- !!! OPTIONAL !!!
--- minimum compatible vfox version
PLUGIN.minRuntimeVersion = "0.3.0"
--- Some things that need user to be attention!
PLUGIN.notes = {}

--- List legacy configuration filenames for determining the specified version of the tool.
--- such as ".node-version", ".nvmrc", etc.
PLUGIN.legacyFilenames = {
".dummy-version",
}
13 changes: 13 additions & 0 deletions crates/vfox/plugins/hooks/available.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--- 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)
return {
{
version = "1.0.0",
},
{
version = "1.0.1",
},
}
end
25 changes: 25 additions & 0 deletions crates/vfox/plugins/hooks/env_keys.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--- Each SDK may have different environment variable configurations.
--- This allows plugins to define custom environment variables (including PATH settings)
--- Note: Be sure to distinguish between environment variable settings for different platforms!
--- @param ctx table Context information
--- @field ctx.path string SDK installation directory
function PLUGIN:EnvKeys(ctx)
--- this variable is same as ctx.sdkInfo['plugin-name'].path
local version_path = ctx.path
if RUNTIME.osType == "windows" then
return {
{
key = "PATH",
value = version_path
},
}
else
return {
{
key = "PATH",
value = version_path .. "/bin"
},
}
end

end
11 changes: 11 additions & 0 deletions crates/vfox/plugins/hooks/post_install.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function PLUGIN:PostInstall(ctx)
--- SDK installation root path
local rootPath = ctx.rootPath
local runtimeVersion = ctx.runtimeVersion
--- Other SDK information, the `addition` field returned in PreInstall, obtained by name
--TODO
--local sdkInfo = ctx.sdkInfo['dummy']
--local path = sdkInfo.path
--local version = sdkInfo.version
--local name = sdkInfo.name
end
12 changes: 12 additions & 0 deletions crates/vfox/plugins/hooks/pre_install.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--- 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

return {
version = version,
}
end
11 changes: 11 additions & 0 deletions crates/vfox/src/hooks/parse_legacy_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,15 @@ mod tests {
let out = format!("{response:?}");
assert_snapshot!(out, @r###"ParseLegacyFileResponse { version: Some("20.0.0") }"###);
}

#[tokio::test]
async fn test_parse_legacy_file_dummy() {
let vfox = Vfox::test();
let response = vfox
.parse_legacy_file("dummy", Path::new("test/data/.dummy-version"))
.await
.unwrap();
let out = format!("{response:?}");
assert_snapshot!(out, @r###"ParseLegacyFileResponse { version: Some("1.0.0") }"###);
}
}
1 change: 1 addition & 0 deletions crates/vfox/test/data/.dummy-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0
Loading