diff --git a/src/config/segment_types.go b/src/config/segment_types.go index 63df09bd..e4b6213e 100644 --- a/src/config/segment_types.go +++ b/src/config/segment_types.go @@ -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. @@ -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{} }, diff --git a/src/segments/vite.go b/src/segments/vite.go new file mode 100644 index 00000000..650ef750 --- /dev/null +++ b/src/segments/vite.go @@ -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((?P[0-9]+).(?P[0-9]+).(?P[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") +} diff --git a/themes/schema.json b/themes/schema.json index 1318b394..f568b96c 100644 --- a/themes/schema.json +++ b/themes/schema.json @@ -399,6 +399,7 @@ "unity", "upgrade", "vala", + "vite", "wakatime", "winreg", "withings", @@ -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" + } + } + } + } + } } ] } diff --git a/website/docs/segments/cli/vite.mdx b/website/docs/segments/cli/vite.mdx new file mode 100644 index 00000000..4a3ff1c8 --- /dev/null +++ b/website/docs/segments/cli/vite.mdx @@ -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"; + + + +## 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` |
  • `always`: the segment is always displayed
  • `files`: the segment is only displayed when file `extensions` listed are present
  • `context`: displays the segment when the environment or files is active
| +| `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 diff --git a/website/sidebars.js b/website/sidebars.js index d3326e30..b84a5119 100644 --- a/website/sidebars.js +++ b/website/sidebars.js @@ -89,6 +89,7 @@ module.exports = { "segments/cli/ui5tooling", "segments/cli/umbraco", "segments/cli/unity", + "segments/cli/vite", "segments/cli/xmake", "segments/cli/yarn", ]