Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(segments): Add Vite segment #6036

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions src/config/segment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ const (
UPGRADE SegmentType = "upgrade"
// VALA writes the active vala version
VALA SegmentType = "vala"
// VUE writes the current vite version
VITE SegmentType = "vite"
// WAKATIME writes tracked time spend in dev editors
WAKATIME SegmentType = "wakatime"
// WINREG queries the Windows registry.
Expand Down Expand Up @@ -324,6 +326,7 @@ var Segments = map[SegmentType]func() SegmentWriter{
UNITY: func() SegmentWriter { return &segments.Unity{} },
UPGRADE: func() SegmentWriter { return &segments.Upgrade{} },
VALA: func() SegmentWriter { return &segments.Vala{} },
VITE: func() SegmentWriter { return &segments.Vite{} },
WAKATIME: func() SegmentWriter { return &segments.Wakatime{} },
WINREG: func() SegmentWriter { return &segments.WindowsRegistry{} },
WITHINGS: func() SegmentWriter { return &segments.Withings{} },
Expand Down
26 changes: 26 additions & 0 deletions src/segments/vite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package segments

type Vite struct {
language
}

func (v *Vite) Template() string {
return languageTemplate
}

func (v *Vite) Enabled() bool {
v.extensions = []string{"vite.config.*"}
v.commands = []*cmd{
{
regex: `(?:(?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+))))`,
getVersion: v.getVersion,
},
}
v.versionURLTemplate = "https://github.com/vitejs/vite/releases/tag/{{.Full}}"

return v.language.Enabled()
}

func (v *Vite) getVersion() (string, error) {
return v.nodePackageVersion("vite")
}
49 changes: 49 additions & 0 deletions themes/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@
"unity",
"upgrade",
"vala",
"vite",
"wakatime",
"winreg",
"withings",
Expand Down Expand Up @@ -5019,6 +5020,54 @@
}
}
}
},
{
"if": {
"properties": {
"type": {
"const": "vite"
}
}
},
"then": {
"title": "Vite Segment",
"description": "https://ohmyposh.dev/docs/segments/cli/vite",
"properties": {
"properties": {
"properties": {
"home_enabled": {
"$ref": "#/definitions/home_enabled"
},
"fetch_version": {
"$ref": "#/definitions/fetch_version"
},
"missing_command_text": {
"$ref": "#/definitions/missing_command_text"
},
"display_mode": {
"$ref": "#/definitions/display_mode"
},
"version_url_template": {
"$ref": "#/definitions/version_url_template"
},
"extensions": {
"type": "array",
"title": "Extensions",
"description": "The extensions to look for when determining if the current directory is an Vite project",
"default": [
"vite.config.*"
],
"items": {
"type": "string"
}
},
"folders": {
"$ref": "#/definitions/folders"
}
}
}
}
}
}
]
}
Expand Down
63 changes: 63 additions & 0 deletions website/docs/segments/cli/vite.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
id: vite
title: Vite
sidebar_label: Vite
---

## What

Display the currently active [Vite][vite] version.

## Sample Configuration

import Config from "@site/src/components/Config.js";

<Config
data={{
type: "vite",
style: "powerline",
powerline_symbol: "\uE0B0",
foreground: "#ffbd15",
background: "#a257fe",
template: " \uE8D7 {{ .Full }} ",
}}
/>

## Properties

| Name | Type | Default | Description |
| ---------------------- | :--------: | :------------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `home_enabled` | `boolean` | `false` | display the segment in the HOME folder or not |
| `fetch_version` | `boolean` | `true` | fetch the vite version |
| `cache_duration` | `string` | `24h` | the duration for which the version will be cached. The duration is a string in the format `1h2m3s` and is parsed using the [time.ParseDuration] function from the Go standard library. To disable the cache, use `none` |
| `missing_command_text` | `string` | | text to display when the command is missing |
| `display_mode` | `string` | `context` | <ul><li>`always`: the segment is always displayed</li><li>`files`: the segment is only displayed when file `extensions` listed are present</li><li>`context`: displays the segment when the environment or files is active</li></ul> |
| `version_url_template` | `string` | | a go [text/template][go-text-template] [template][templates] that creates the URL of the version info / release notes |
| `extensions` | `[]string` | `vite.config.*` | allows to override the default list of file extensions to validate |
| `folders` | `[]string` | | allows to override the list of folder names to validate |

## Template ([info][templates])

:::note default template

```template
{{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}
```

:::

### Properties

| Name | Type | Description |
| -------- | -------- | -------------------------------------------------- |
| `.Full` | `string` | the full version |
| `.Major` | `string` | major number |
| `.Minor` | `string` | minor number |
| `.Patch` | `string` | patch number |
| `.URL` | `string` | URL of the version info / release notes |
| `.Error` | `string` | error encountered when fetching the version string |

[go-text-template]: https://golang.org/pkg/text/template/
[templates]: /docs/configuration/templates
[vite]: https://vite.dev/
[time.ParseDuration]: https://golang.org/pkg/time/#ParseDuration
1 change: 1 addition & 0 deletions website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ module.exports = {
"segments/cli/ui5tooling",
"segments/cli/umbraco",
"segments/cli/unity",
"segments/cli/vite",
"segments/cli/xmake",
"segments/cli/yarn",
]
Expand Down