Skip to content

Commit

Permalink
Merge branch 'version-fox:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ShizheChang authored Mar 5, 2024
2 parents b495bd7 + eb2bcd5 commit a357833
Show file tree
Hide file tree
Showing 34 changed files with 873 additions and 276 deletions.
14 changes: 14 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: aooohan
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
polar: # Replace with a single Polar username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: VersionFox CI

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [ '1.21.x' ]

steps:
- uses: actions/checkout@v4
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Display Go version
run: go version
- name: Install dependencies
run: |
go get .
- name: Build with the Go CLI
run: |
go build .
- name: Test with the Go CLI
run: |
go test ./internal
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
golang 1.21.7
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,16 @@ echo 'eval "$(vfox activate bash)"' >> ~/.bashrc
echo 'eval "$(vfox activate zsh)"' >> ~/.zshrc
echo 'vfox activate fish | source' >> ~/.config/fish/config.fish

# For PowerShell, add the following line to your $PROFILE:
# For PowerShell:
# 1. Open PowerShell Profile:
New-Item -Type File -Path $PROFILE # Just ignore the 'file already exists' error.
Invoke-Item $PROFILE
# 2. Add the following line to the end of your $PROFILE and save:
Invoke-Expression "$(vfox activate pwsh)"
```

> Remember to restart your shell to apply the changes.
#### 3. Add an SDK plugin
```bash
$ vfox add nodejs/nodejs
Expand Down Expand Up @@ -76,7 +82,7 @@ See [vfox.lhan.me](https://vfox.lhan.me) for full documentation.

> If you have installed `vfox`, you can view all available plugins with the `vfox available` command.
[![plugins](https://skillicons.dev/icons?i=java,kotlin,nodejs,flutter,dotnet,python,dart,golang,maven,zig,deno&theme=light)](https://github.com/version-fox/version-fox-plugins)
[![plugins](https://skillicons.dev/icons?i=java,kotlin,nodejs,flutter,dotnet,python,dart,golang,gradle,maven,zig,deno&theme=light)](https://github.com/version-fox/version-fox-plugins)

For more details, see the [version-fox-plugins](https://github.com/version-fox/version-fox-plugins)

Expand Down
12 changes: 9 additions & 3 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,23 @@
#### 1.选择一个适合你的[安装方式](https://vfox.lhan.me/zh-hans/guides/quick-start.html#_1-%E5%AE%89%E8%A3%85vfox)

#### 2. ⚠️ **挂载vfox到你的Shell (从下面选择一条适合你shell的命令)** ⚠️
#### 2. ⚠️ **挂载vfox到你的 Shell (从下面选择一条适合你 shell 的命令)** ⚠️

```bash
echo 'eval "$(vfox activate bash)"' >> ~/.bashrc
echo 'eval "$(vfox activate zsh)"' >> ~/.zshrc
echo 'vfox activate fish | source' >> ~/.config/fish/config.fish

# PowerShell, 请将下面一行添加到你的$PROFILE文件中:
# PowerShell:
# 1. 打开 PowerShell 配置文件:
New-Item -Type File -Path $PROFILE # 无需在意 `文件已存在` 错误
Invoke-Item $PROFILE
# 2. 将下面一行添加到你的 $PROFILE 文件末尾并保存:
Invoke-Expression "$(vfox activate pwsh)"
```

> 请记住重启你的 Shell 以应用更改。
#### 3.添加插件
```bash
$ vfox add nodejs/nodejs
Expand Down Expand Up @@ -73,7 +79,7 @@ $ node -v

> 如果您已经安装了 `vfox`,您可以使用 `vfox available` 命令查看所有可用的插件。
[![plugins](https://skillicons.dev/icons?i=java,kotlin,nodejs,flutter,dotnet,python,dart,golang,maven,zig,deno&theme=light)](https://github.com/version-fox/version-fox-plugins)
[![plugins](https://skillicons.dev/icons?i=java,kotlin,nodejs,flutter,dotnet,python,dart,golang,gradle,maven,zig,deno&theme=light)](https://github.com/version-fox/version-fox-plugins)

详细内容,请看 [version-fox-plugins](https://github.com/version-fox/version-fox-plugins)

Expand Down
15 changes: 13 additions & 2 deletions cmd/commands/activate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ package commands

import (
"fmt"
"github.com/version-fox/vfox/internal"
"os"
"strings"
"text/template"

"github.com/version-fox/vfox/internal"

"github.com/urfave/cli/v2"
"github.com/version-fox/vfox/internal/env"
"github.com/version-fox/vfox/internal/shell"
Expand All @@ -46,7 +48,16 @@ func activateCmd(ctx *cli.Context) error {
return err
}
envKeys[env.HookFlag] = &name
envKeys[env.PathFlag] = envKeys["PATH"]
originPath := os.Getenv("PATH")
envKeys[env.PathFlag] = &originPath

sdkPaths := envKeys["PATH"]
if sdkPaths != nil {
paths := manager.EnvManager.Paths([]string{*sdkPaths, originPath})

envKeys["PATH"] = &paths
}

path := manager.PathMeta.ExecutablePath
path = strings.Replace(path, "\\", "/", -1)
s := shell.NewShell(name)
Expand Down
2 changes: 1 addition & 1 deletion cmd/commands/current.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var Current = &cli.Command{
}

func currentCmd(ctx *cli.Context) error {
manager := internal.NewSdkManager()
manager := internal.NewSdkManager(internal.GlobalRecordSource, internal.SessionRecordSource, internal.ProjectRecordSource)
defer manager.Close()
sdkName := ctx.Args().First()
if sdkName == "" {
Expand Down
54 changes: 53 additions & 1 deletion cmd/commands/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
package commands

import (
"encoding/json"
"fmt"
"github.com/urfave/cli/v2"
"github.com/version-fox/vfox/internal"
"github.com/version-fox/vfox/internal/env"
"github.com/version-fox/vfox/internal/shell"
"os"
)

var Env = &cli.Command{
Expand All @@ -37,12 +40,53 @@ var Env = &cli.Command{
Aliases: []string{"c"},
Usage: "cleanup temp file",
},
&cli.BoolFlag{
Name: "json",
Aliases: []string{"j"},
Usage: "get envs as json",
},
},
Action: envCmd,
}

func envCmd(ctx *cli.Context) error {
if ctx.IsSet("cleanup") {
if ctx.IsSet("json") {
type SDKs map[string]map[string]string
data := struct {
IsHookEnv bool `json:"is_hook_env"`
Paths []string `json:"paths"`
SDKs SDKs `json:"sdks"`
}{
IsHookEnv: env.IsHookEnv(),
Paths: []string{},
SDKs: make(SDKs),
}
manager := internal.NewSdkManagerWithSource(internal.GlobalRecordSource, internal.SessionRecordSource, internal.ProjectRecordSource)
defer manager.Close()
for k, v := range manager.Record.Export() {
if lookupSdk, err := manager.LookupSdk(k); err == nil {
if keys, err := lookupSdk.EnvKeys(internal.Version(v)); err == nil {
newEnv := make(map[string]string)
for key, value := range keys {
if key == "PATH" {
data.Paths = append(data.Paths, *value)
} else {
newEnv[key] = *value
}
}
if len(newEnv) > 0 {
data.SDKs[lookupSdk.Plugin.Name] = newEnv
}
}
}
}
jsonData, err := json.Marshal(data)
if err != nil {
return err
}
fmt.Println(string(jsonData))
return nil
} else if ctx.IsSet("cleanup") {
manager := internal.NewSdkManager()
defer manager.Close()
// Clean up the old temp files, before today.
Expand All @@ -63,6 +107,14 @@ func envCmd(ctx *cli.Context) error {
if err != nil {
return err
}

sdkPaths := envKeys["PATH"]
if sdkPaths != nil {
originPath := os.Getenv(env.PathFlag)
paths := manager.EnvManager.Paths([]string{*sdkPaths, originPath})
envKeys["PATH"] = &paths
}

exportStr := s.Export(envKeys)
fmt.Println(exportStr)
return nil
Expand Down
6 changes: 5 additions & 1 deletion cmd/commands/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
"github.com/urfave/cli/v2"
"github.com/version-fox/vfox/internal"
"github.com/version-fox/vfox/internal/printer"
"golang.org/x/crypto/ssh/terminal"
"math"
"os"
"strings"
)

Expand Down Expand Up @@ -48,10 +51,11 @@ func searchCmd(ctx *cli.Context) error {
if len(result) == 0 {
return fmt.Errorf("no available version")
}
_, height, _ := terminal.GetSize(int(os.Stdout.Fd()))
kvSelect := printer.PageKVSelect{
TopText: "Please select a version of " + sdkName,
Filter: true,
Size: 20,
Size: int(math.Min(math.Max(float64(height-3), 1), 20)),
SourceFunc: func(page, size int) ([]*printer.KV, error) {
start := page * size
end := start + size
Expand Down
5 changes: 4 additions & 1 deletion cmd/commands/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ package commands

import (
"fmt"
"github.com/version-fox/vfox/internal"
"os"
"strings"

"github.com/pterm/pterm"
"github.com/version-fox/vfox/internal"

"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -87,6 +88,7 @@ func useCmd(ctx *cli.Context) error {
if err != nil {
return fmt.Errorf("%s not supported, error: %w", name, err)
}

if version == "" {
list := source.List()
var arr []string
Expand All @@ -109,5 +111,6 @@ func useCmd(ctx *cli.Context) error {
result, _ := selectPrinter.Show(fmt.Sprintf("Please select a version of %s", name))
version = internal.Version(result)
}

return source.Use(version, scope)
}
1 change: 1 addition & 0 deletions docs/.vitepress/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function nav(): DefaultTheme.NavItem[] {
return [
{text: 'Home', link: '/'},
{text: 'Documentation', link: '/guides/intro'},
{text: 'FAQ', link: '/guides/faq'},
{text: 'Plugins', link: 'https://github.com/version-fox/version-fox-plugins'}
]
}
Expand Down
1 change: 1 addition & 0 deletions docs/.vitepress/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function nav(): DefaultTheme.NavItem[] {
return [
{text: '首页', link: '/zh-hans/'},
{text: '文档', link: '/zh-hans/guides/intro'},
{text: '常见问题', link: '/zh-hans/guides/faq'},
{text: '插件仓库', link: 'https://github.com/version-fox/version-fox-plugins'}
]
}
Expand Down
41 changes: 40 additions & 1 deletion docs/guides/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,43 @@
If your shell prompt `Warning: The current shell lacks hook support or configuration. It has switched to global scope
automatically` that means you do not hook `vfox` into your shell, please hook it manually first.

Please refer to [Quick Start#_2-hook-vfox-to-your-shell](./quick-start.md#_2-hook-vfox-to-your-shell) to manually hook `vfox` into your shell.
Please refer to [Quick Start#_2-hook-vfox-to-your-shell](./quick-start.md#_2-hook-vfox-to-your-shell) to manually hook `vfox` into your shell.

## Why can't I delete the plugin?

```text
I first added java/adoptium-jdk, then tried to install v21, because the download was slow, I exited halfway, and then tried
to remove the plugin with the remove command, and got the error message "java/adoptium-jdk not installed".
So I want to switch to another source, when I execute "vfox add java/azul-jdk", I also get the error message "plugin java
already exists", now I can't move forward or backward.
```

In the `vfox` concept, the plugin is the SDK, and the SDK is the plugin. You can think of the plugin as an extension of `vfox`
to manage different tools and runtime environments.

Taking the `nodejs/npmmirror` plugin as an example, `nodejs` is the category, `npmmirror` is the plugin name, and the
**SDK name** marked by the `name` field inside the plugin.

So, when deleting the plugin, you need to use the **SDK name** (here is `nodejs`) for deletion, not the plugin name
`nodejs/npmirror` or `npmmirror`.

```bash
$ vfox remove nodejs
```

before deleting, you can use `vfox ls` to view the currently installed plugins (i.e. SDK names), and then delete them.

## Why does the PATH environment variable value repeat on Windows?

Only one situation will cause this, that is, you have used the SDK globally (`vfox use -g`), at this time, `vfox` will
operate the registry and write the SDK's `PATH` into the user environment variable (for the purpose of, **Shell that does not
support Hook function** can also use SDK, such as `CMD`).

But because of the existence of the `.tool-versions` mechanism, the `PATH` becomes the sum of `.tool-verions` and the user
environment variable `PATH`.

::: warning
The same SDK **can be repeated at most twice**, it will not be repeated indefinitely. If >2 times, please feedback to us.
:::
22 changes: 21 additions & 1 deletion docs/guides/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,15 @@ echo 'vfox activate fish | source' >> ~/.config/fish/config.fish
:::

::: details Powershell
add the following line to your `$PROFILE`:

Open PowerShell Profile:

```shell
New-Item -Type File -Path $PROFILE # Just ignore the 'file already exists' error.
Invoke-Item $PROFILE
```

Add the following line to the end of your profile and save:

```shell
Invoke-Expression "$(vfox activate pwsh)"
Expand All @@ -116,6 +124,18 @@ If you don't know which plugin to add, you can use the `vfox available` command
$ vfox add nodejs/nodejs
```

::: tip About plugins and SDKs
In the `vfox` concept, the plugin is the SDK, and the SDK is the plugin. You can think of the plugin as an extension of `vfox`
to manage different tools and runtime environments.

Taking the `nodejs/npmmirror` plugin as an example, `nodejs` is the category, `npmmirror` is the plugin name, and the
**SDK name** marked by the `name` field inside the plugin.

So, when deleting the plugin, you need to use the **SDK name** (here is `nodejs`) for deletion, not the plugin name
`nodejs/npmirror` or `npmmirror`.

:::

## 4. Install a runtime

After the plugin is successfully installed, you can install the corresponding version of Nodejs.
Expand Down
Loading

0 comments on commit a357833

Please sign in to comment.