Skip to content

Commit

Permalink
Adding --latest-only option (#15)
Browse files Browse the repository at this point in the history
* Adding --latest-only option

By default, any duplicate packages that are found will be processed, resulting in multiple versions of the same package in the feed. In case you have a build process that retains older versions of VSIX packages, this option can be used to ensure only the latest version of packages with the same ID end up in the feed.

* Refactoring latest version to be much simpler.

Removing private method and switching to use a one-line LINQ statement.
It's probably slightly less efficient, but I think the simpler code outweighs the minor performance hit.
  • Loading branch information
archxor authored and madskristensen committed Sep 20, 2019
1 parent 3bb51c6 commit d30d58d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,26 @@ PrivateGalleryCreator.exe --exclude=dontwantthis
```

## Source option
Be default, the download source path used in the gallery will be the location where the .vsix files reside when running the PrivateGalleryCreator. If you intend to move the .vsix files after creating the feed, you can specify the intended download source path with the --source option:
By default, the download source path used in the gallery will be the location where the .vsix files reside when running the PrivateGalleryCreator. If you intend to move the .vsix files after creating the feed, you can specify the intended download source path with the --source option:

```cmd
PrivateGalleryCreator.exe --source=c:\your\vsix\repository\
```

## Terminate option
If you would like the application to exit immediately after processing VSIX files, use the --terminate option:

```cmd
PrivateGalleryCreator.exe --terminate
```

## Latest only option
By default, any duplicate packages that are found will be processed, resulting in multiple versions of the same package in the feed. If you have a folder structure that retains previous versions of the packages, use the --latest-only option:

```cmd
PrivateGalleryCreator.exe --latest-only
```

## Good to know

* Run the *PrivateGalleryCreator.exe* every time you add or update a .vsix in the directory
Expand Down
16 changes: 12 additions & 4 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ internal class Program
private static string _dir;
private static string _galleryName;
private static bool _recursive = false;
private static bool _latestOnly = false;
private static string _outputFile;
private static string _exclude = string.Empty;

Expand All @@ -27,6 +28,8 @@ private static void Main(string[] args)

_recursive = args.Any(a => a == "--recursive");

_latestOnly = args.Any(a => a == "--latest-only");

_outputFile = args.FirstOrDefault(a => a.StartsWith("--output="))?.Replace("--output=", string.Empty) ?? Path.Combine(_dir, _xmlFileName);

_exclude = args.FirstOrDefault(a => a.StartsWith("--exclude="))?.Replace("--exclude=", string.Empty) ?? string.Empty;
Expand All @@ -45,7 +48,7 @@ private static void Main(string[] args)

case var a when (a.Contains("--terminate") || a.Contains("-t")):
break;

default:
Console.WriteLine("Press any key to close...");
Console.ReadKey(true);
Expand Down Expand Up @@ -85,12 +88,17 @@ private static void FileChanged(object sender, EventArgs e)

private static void GenerateAtomFeed()
{
var packages = EnumerateFilesSafe(new DirectoryInfo(_dir), "*.vsix", _recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly).Distinct();
var filteredPackages = string.IsNullOrEmpty(_exclude) ? packages : packages.Where(f => !f.FullName.Contains(_exclude));
var packageFiles = EnumerateFilesSafe(new DirectoryInfo(_dir), "*.vsix", _recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly).Distinct();
var filteredPackageFiles = string.IsNullOrEmpty(_exclude) ? packageFiles : packageFiles.Where(f => !f.FullName.Contains(_exclude));
var packagesToProcess = filteredPackageFiles.Select(f => ProcessVsix(f.FullName));
if (_latestOnly)
{
packagesToProcess = packagesToProcess.GroupBy(p => p.ID).Select(g => g.OrderByDescending(pkg => Version.Parse(pkg.Version)).First());
}

var writer = new FeedWriter(_galleryName);
string feedUrl = _outputFile;
string xml = writer.GetFeed(feedUrl, filteredPackages.Select(f => ProcessVsix(f.FullName)));
string xml = writer.GetFeed(feedUrl, packagesToProcess);

File.WriteAllText(feedUrl, xml, Encoding.UTF8);

Expand Down

0 comments on commit d30d58d

Please sign in to comment.