feat(project): add support for dart

This commit is contained in:
Oleksandr Babieiev 2024-10-22 19:36:00 +02:00 committed by Jan De Dobbeleer
parent fbcd78eff1
commit 17c19c3157
3 changed files with 66 additions and 1 deletions

View file

@ -11,6 +11,7 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/regex"
"golang.org/x/exp/slices"
yaml "github.com/goccy/go-yaml"
toml "github.com/pelletier/go-toml/v2"
)
@ -80,6 +81,11 @@ func (n *Project) Enabled() bool {
Files: []string{"composer.json"},
Fetcher: n.getNodePackage,
},
{
Name: "dart",
Files: []string{"pubspec.yaml"},
Fetcher: n.getDartPackage,
},
{
Name: "nuspec",
Files: []string{"*.nuspec"},
@ -180,6 +186,18 @@ func (n *Project) getPythonPackage(item ProjectItem) *ProjectData {
}
}
func (n *Project) getDartPackage(item ProjectItem) *ProjectData {
content := n.env.FileContent(item.Files[0])
var data ProjectData
err := yaml.Unmarshal([]byte(content), &data)
if err != nil {
n.Error = err.Error()
return nil
}
return &data
}
func (n *Project) getNuSpecPackage(_ ProjectItem) *ProjectData {
files := n.env.LsDir(n.env.Pwd())
var content string

View file

@ -74,6 +74,22 @@ func TestPackage(t *testing.T) {
Name: "node", File: "package.json",
PackageContents: "{\"version\":\"3.2.1\",\"name\":\"test\"}",
},
{
Case: "1.0.0 dart",
ExpectedEnabled: true,
ExpectedString: "\uf487 1.0.0 test",
Name: "dart",
File: "pubspec.yaml",
PackageContents: "name: test\nversion: 1.0.0",
},
{
Case: "3.2.1 dart",
ExpectedEnabled: true,
ExpectedString: "\uf487 3.2.1 test",
Name: "dart",
File: "pubspec.yaml",
PackageContents: "name: test\nversion: 3.2.1",
},
{
Case: "1.0.0 cargo",
ExpectedEnabled: true,
@ -130,6 +146,14 @@ func TestPackage(t *testing.T) {
File: "package.json",
PackageContents: "{\"name\":\"test\"}",
},
{
Case: "No version present dart",
ExpectedEnabled: true,
ExpectedString: "test",
Name: "dart",
File: "pubspec.yaml",
PackageContents: "name: test",
},
{
Case: "No version present cargo",
ExpectedEnabled: true,
@ -162,6 +186,14 @@ func TestPackage(t *testing.T) {
File: "package.json",
PackageContents: "{\"version\":\"1.0.0\"}",
},
{
Case: "No name present dart",
ExpectedEnabled: true,
ExpectedString: "\uf487 1.0.0",
Name: "dart",
File: "pubspec.yaml",
PackageContents: "version: 1.0.0",
},
{
Case: "No name present cargo",
ExpectedEnabled: true,
@ -193,6 +225,13 @@ func TestPackage(t *testing.T) {
File: "package.json",
PackageContents: "{}",
},
{
Case: "Empty project package dart",
ExpectedEnabled: true,
Name: "dart",
File: "pubspec.yaml",
PackageContents: "",
},
{
Case: "Empty project package cargo",
ExpectedEnabled: true,
@ -221,6 +260,13 @@ func TestPackage(t *testing.T) {
File: "Cargo.toml",
PackageContents: "[",
},
{
Case: "Invalid yaml",
ExpectedString: "[1:1] sequence was used where mapping is expected\n> 1 | [\n ^",
Name: "dart",
File: "pubspec.yaml",
PackageContents: "[",
},
{
Case: "Julia project",
ExpectedEnabled: true,

View file

@ -14,6 +14,7 @@ Supports:
- Cargo project (`Cargo.toml`)
- Python project (`pyproject.toml`, supports metadata defined according to [PEP 621][pep621-standard] or [Poetry][poetry-standard])
- PHP project (`composer.json`)
- Dart project (`pubspec.yaml`)
- Any nuspec based project (`*.nuspec`, first file match info is displayed)
- .NET project (`*.sln`, `*.slnf`, `*.csproj`, `*.vbproj` or `*.fsproj`, first file match info is displayed)
- Julia project (`JuliaProject.toml`, `Project.toml`)
@ -55,7 +56,7 @@ import Config from "@site/src/components/Config.js";
| Name | Type | Description |
| ---------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `.Type` | `string` | The type of project:<ul><li>`node`</li><li>`cargo`</li><li>`python`</li><li>`php`</li><li>`nuspec`</li><li>`dotnet`</li><li>`julia`</li><li>`powershell`</li></ul> |
| `.Type` | `string` | The type of project:<ul><li>`node`</li><li>`cargo`</li><li>`python`</li><li>`php`</li><li>`dart`</li><li>`nuspec`</li><li>`dotnet`</li><li>`julia`</li><li>`powershell`</li></ul> |
| `.Version` | `string` | The version of your project |
| `.Target` | `string` | The target framwork/language version of your project |
| `.Name` | `string` | The name of your project |