Skip to content

Commit 18ca481

Browse files
Add CPM & multiple package manager commands (#10277)
* Add CPM & multiple package manager commands * Adjust management to Management --------- Co-authored-by: Maria Ghiondea <[email protected]>
1 parent e6bbaec commit 18ca481

8 files changed

Lines changed: 269 additions & 116 deletions

File tree

src/Bootstrap/dist/css/bootstrap-theme.css

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Bootstrap/less/theme/page-display-package.less

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,14 +488,25 @@
488488

489489
.copy-button {
490490
display: flex;
491-
491+
492492
button {
493493
display: flex;
494494
gap: 4px;
495495
padding: 2px 8px;
496496
justify-content: center;
497497
align-items: center;
498498
}
499+
500+
.package-manager-command-header {
501+
display: inline;
502+
font-size: 14px;
503+
font-family: @font-family-base;
504+
padding: 0px 8px;
505+
line-height: 75%;
506+
color: var(--neutralForeground1Rest);
507+
justify-content: center;
508+
align-items: center;
509+
}
499510
}
500511
}
501512

src/NuGetGallery/Content/gallery/css/bootstrap.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/NuGetGallery/Extensions/CakeBuildManagerExtensions.cs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Collections.Generic;
56
using System.Linq;
67

78
namespace NuGetGallery
@@ -13,7 +14,12 @@ public static bool IsCakeExtension(this DisplayPackageViewModel model)
1314
return IsCakeAddin(model) || IsCakeModule(model) || IsCakeRecipe(model);
1415
}
1516

16-
public static string GetCakeInstallPackageCommand(this DisplayPackageViewModel model)
17+
public static PackageManagerViewModel.InstallPackageCommand[] GetCakeInstallPackageCommands(this DisplayPackageViewModel model)
18+
=> model
19+
.EnumerateCakeInstallPackageCommands()
20+
.ToArray();
21+
22+
public static IEnumerable<PackageManagerViewModel.InstallPackageCommand> EnumerateCakeInstallPackageCommands(this DisplayPackageViewModel model)
1723
{
1824
var scheme = model.IsDotnetToolPackageType ? "dotnet" : "nuget";
1925
var reference = $"{scheme}:?package={model.Id}&version={model.Version}";
@@ -25,31 +31,32 @@ public static string GetCakeInstallPackageCommand(this DisplayPackageViewModel m
2531

2632
if (model.IsDotnetToolPackageType)
2733
{
28-
return $"#tool {reference}";
34+
yield return new PackageManagerViewModel.InstallPackageCommand($"#tool {reference}");
2935
}
30-
31-
if (IsCakeAddin(model))
36+
else if (IsCakeAddin(model))
3237
{
33-
return $"#addin {reference}";
38+
yield return new PackageManagerViewModel.InstallPackageCommand($"#addin {reference}");
3439
}
35-
36-
if (IsCakeModule(model))
40+
else if (IsCakeModule(model))
3741
{
38-
return $"#module {reference}";
42+
yield return new PackageManagerViewModel.InstallPackageCommand($"#module {reference}");
3943
}
40-
41-
if (IsCakeRecipe(model))
44+
else if (IsCakeRecipe(model))
4245
{
43-
return $"#load {reference}";
46+
yield return new PackageManagerViewModel.InstallPackageCommand($"#load {reference}");
4447
}
48+
else
49+
{
50+
yield return new PackageManagerViewModel.InstallPackageCommand(
51+
$"Install {model.Id} as a Cake Addin",
52+
$"#addin {reference}"
53+
);
4554

46-
return string.Join(Environment.NewLine,
47-
$"// Install {model.Id} as a Cake Addin",
48-
$"#addin {reference}",
49-
"",
50-
$"// Install {model.Id} as a Cake Tool",
51-
$"#tool {reference}"
52-
);
55+
yield return new PackageManagerViewModel.InstallPackageCommand(
56+
$"Install {model.Id} as a Cake Tool",
57+
$"#tool {reference}"
58+
);
59+
};
5360
}
5461

5562
private static bool IsCakeAddin(ListPackageItemViewModel model) =>

src/NuGetGallery/ViewModels/PackageManagerViewModel.cs

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,44 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
5+
using System.Collections.Generic;
6+
using System.Globalization;
7+
using System.Linq;
8+
49
namespace NuGetGallery
510
{
611
/// <summary>
712
/// The basic model for a client that conforms to the NuGet protocol.
813
/// </summary>
914
public class PackageManagerViewModel
1015
{
11-
public PackageManagerViewModel(string name)
16+
public PackageManagerViewModel(
17+
string id,
18+
string name,
19+
params InstallPackageCommand[] installPackageCommands
20+
)
1221
{
22+
Id = id;
1323
Name = name;
1424
CopyLabel = string.Format("Copy the {0} command", name);
25+
int index = 0;
26+
InstallPackageCommands = installPackageCommands.ToDictionary(
27+
_ => string.Format(CultureInfo.InvariantCulture, "{0}-{1:0000}", Id, ++index),
28+
value => value,
29+
StringComparer.OrdinalIgnoreCase
30+
);
1531
}
1632

1733
/// <summary>
1834
/// The package manager's name.
1935
/// </summary>
20-
public string Name { get; set; }
36+
public string Name { get; }
2137

2238
/// <summary>
2339
/// A unique identifier that represents this package manager.
2440
/// </summary>
25-
public string Id { get; set; }
41+
public string Id { get; }
2642

2743
/// <summary>
2844
/// The non-selectable prefix displayed on before the package manager's commands.
@@ -32,7 +48,7 @@ public PackageManagerViewModel(string name)
3248
/// <summary>
3349
/// One or more strings that represent the command(s) used to install a specific package.
3450
/// </summary>
35-
public string[] InstallPackageCommands { get; set; }
51+
public Dictionary<string, InstallPackageCommand> InstallPackageCommands { get; }
3652

3753
/// <summary>
3854
/// The alert message that contains clarifications about the command/scenario
@@ -48,6 +64,24 @@ public PackageManagerViewModel(string name)
4864
/// The label for the copy button.
4965
/// </summary>
5066
public string CopyLabel { get; set; }
67+
68+
public class InstallPackageCommand
69+
{
70+
public InstallPackageCommand(string command) : this(string.Empty, command)
71+
{
72+
}
73+
74+
public InstallPackageCommand(string header, string command)
75+
{
76+
HasHeader = !string.IsNullOrWhiteSpace(header);
77+
Header = header;
78+
Command = command;
79+
}
80+
81+
public bool HasHeader { get; }
82+
public string Header { get; }
83+
public string Command { get; }
84+
}
5185
}
5286

5387
public enum AlertLevel
@@ -56,4 +90,4 @@ public enum AlertLevel
5690
Info,
5791
Warning
5892
}
59-
}
93+
}

src/NuGetGallery/ViewModels/ThirdPartyPackageManagerViewModel.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
namespace NuGetGallery
@@ -15,7 +15,16 @@ public class ThirdPartyPackageManagerViewModel : PackageManagerViewModel
1515
/// </summary>
1616
public string ContactUrl { get; set; }
1717

18-
public ThirdPartyPackageManagerViewModel(string name, string contactUrl) : base(name)
18+
public ThirdPartyPackageManagerViewModel(
19+
string id,
20+
string name,
21+
string contactUrl,
22+
params InstallPackageCommand[] installPackageCommands
23+
) : base(
24+
id,
25+
name,
26+
installPackageCommands
27+
)
1928
{
2029
ContactUrl = contactUrl;
2130
AlertLevel = AlertLevel.Warning;
@@ -24,4 +33,4 @@ public ThirdPartyPackageManagerViewModel(string name, string contactUrl) : base(
2433
+ $"<a href=\"{contactUrl}\" aria-label=\"Contact the maintainers of the {name} client\">maintainers</a> for support.";
2534
}
2635
}
27-
}
36+
}

0 commit comments

Comments
 (0)