From d40efeead267f7ddd667ea3ce63e45027bdfc574 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sun, 12 Apr 2020 00:27:04 +1000 Subject: [PATCH] put all dependencies in the one panel --- pkg/commands/config_parsing.go | 1 + pkg/commands/dependency.go | 1 + pkg/commands/package.go | 58 +++++++++++++++++++--------- pkg/gui/presentation/dependencies.go | 2 +- 4 files changed, 43 insertions(+), 19 deletions(-) diff --git a/pkg/commands/config_parsing.go b/pkg/commands/config_parsing.go index c06801e..4f7bfcb 100644 --- a/pkg/commands/config_parsing.go +++ b/pkg/commands/config_parsing.go @@ -228,6 +228,7 @@ func UnmarshalPackageConfig(r io.Reader) (*PackageConfig, error) { }) } } + value, dataType, _, err := jsonparser.Get(configData, "contributors") if err != nil { if err != jsonparser.KeyPathNotFoundError { diff --git a/pkg/commands/dependency.go b/pkg/commands/dependency.go index 6be109d..510a854 100644 --- a/pkg/commands/dependency.go +++ b/pkg/commands/dependency.go @@ -9,6 +9,7 @@ type Dependency struct { Present bool PackageConfig *PackageConfig Path string + Kind string } func (d *Dependency) Linked() bool { diff --git a/pkg/commands/package.go b/pkg/commands/package.go index 5707675..03277df 100644 --- a/pkg/commands/package.go +++ b/pkg/commands/package.go @@ -27,6 +27,7 @@ type PackageConfig struct { DevDependencies map[string]string PeerDependencies map[string]string OptionalDependencies map[string]string + SortedDependencies []*Dependency Engines struct { Node string Npm string @@ -82,26 +83,47 @@ type Package struct { LinkedGlobally bool } -func (p *Package) SortedDepsGeneric(depMap map[string]string) []*Dependency { - deps := make([]*Dependency, 0, len(depMap)) - for name, version := range depMap { - deps = append(deps, &Dependency{Name: name, Version: version}) +func (p *Package) SortedDependencies() []*Dependency { + deps := make([]*Dependency, 0, len(p.Config.Dependencies)+len(p.Config.DevDependencies)+len(p.Config.PeerDependencies)+len(p.Config.OptionalDependencies)) + + type blah struct { + kind string + depMap map[string]string } - sort.Slice(deps, func(i, j int) bool { return strings.Compare(deps[i].Name, deps[j].Name) < 0 }) - return deps -} -func (p *Package) SortedDependencies() []*Dependency { - return p.SortedDepsGeneric(p.Config.Dependencies) -} -func (p *Package) SortedDevDependencies() []*Dependency { - return p.SortedDepsGeneric(p.Config.DevDependencies) -} -func (p *Package) SortedPeerDependencies() []*Dependency { - return p.SortedDepsGeneric(p.Config.PeerDependencies) -} -func (p *Package) SortedOptionalDependencies() []*Dependency { - return p.SortedDepsGeneric(p.Config.OptionalDependencies) + them := []blah{ + { + kind: "prod", + depMap: p.Config.Dependencies, + }, + { + kind: "dev", + depMap: p.Config.DevDependencies, + }, + { + kind: "peer", + depMap: p.Config.PeerDependencies, + }, + { + kind: "optional", + depMap: p.Config.OptionalDependencies, + }, + } + + for _, mapping := range them { + depsForKind := make([]*Dependency, 0, len(mapping.depMap)) + for name, constraint := range mapping.depMap { + depsForKind = append(depsForKind, &Dependency{ + Name: name, + Version: constraint, + Kind: mapping.kind, + }) + } + sort.Slice(depsForKind, func(i, j int) bool { return strings.Compare(depsForKind[i].Name, depsForKind[j].Name) < 0 }) + deps = append(deps, depsForKind...) + } + + return deps } func (p *Package) SortedScripts() []*Script { diff --git a/pkg/gui/presentation/dependencies.go b/pkg/gui/presentation/dependencies.go index bb62f1b..1c14c1e 100644 --- a/pkg/gui/presentation/dependencies.go +++ b/pkg/gui/presentation/dependencies.go @@ -35,7 +35,7 @@ func getDepDisplayStrings(d *commands.Dependency) []string { localVersionCol = utils.ColoredString("missing", color.FgRed) } - return []string{d.Name, utils.ColoredString(d.Version, color.FgMagenta), localVersionCol} + return []string{d.Name, d.Kind, utils.ColoredString(d.Version, color.FgMagenta), localVersionCol} } func statusMap() map[int]string {