Skip to content

Commit

Permalink
VCI-91: Add manifest creation from existing environment (#13)
Browse files Browse the repository at this point in the history
* VCI-91: Add manifest creation from existing environment

* VCI-91: Fix codesmell
  • Loading branch information
krankenbro authored Aug 17, 2021
1 parent 714880b commit 37b9b02
Showing 1 changed file with 44 additions and 14 deletions.
58 changes: 44 additions & 14 deletions PlatformTools/Build.PackageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,7 @@ internal partial class Build
.Triggers(InstallPlatform, InstallModules)
.Executes(async () =>
{
PackageManifest packageManifest;

if (!File.Exists(PackageManifestPath))
{
Logger.Info("vc-package.json does not exist.");
Logger.Info("Looking for the platform release");
var platformRelease = await GithubManager.GetPlatformRelease(GitHubToken, VersionToInstall);
packageManifest = PackageManager.CreatePackageManifest(platformRelease.TagName);
}
else
{
packageManifest = PackageManager.FromFile(PackageManifestPath);
}
PackageManifest packageManifest = await OpenOrCreateManifets(PackageManifestPath);

var localModuleCatalog = LocalModuleCatalog.GetCatalog(GetDiscoveryPath(), ProbingPath);
var externalModuleCatalog = ExtModuleCatalog.GetCatalog(GitHubToken, localModuleCatalog, packageManifest.ModuleSources);
Expand Down Expand Up @@ -296,7 +284,7 @@ private bool NeedToInstallPlatform(string version)
.Triggers(InstallPlatform, InstallModules)
.Executes(async () =>
{
var packageManifest = PackageManager.FromFile(PackageManifestPath);
var packageManifest = await OpenOrCreateManifets(PackageManifestPath);
var platformRelease = await GithubManager.GetPlatformRelease(GitHubToken, VersionToInstall);
packageManifest.PlatformVersion = platformRelease.TagName;
packageManifest.PlatformAssetUrl = platformRelease.Assets.First().BrowserDownloadUrl;
Expand All @@ -316,5 +304,47 @@ private bool NeedToInstallPlatform(string version)
}

PackageManager.ToFile(packageManifest);
});

private async Task<PackageManifest> OpenOrCreateManifets(string packageManifestPath)
{
PackageManifest packageManifest;
var platformWebDllPath = Path.Combine(Directory.GetParent(packageManifestPath).FullName, "VirtoCommerce.Platform.Web.dll");
if (!File.Exists(packageManifestPath) && File.Exists(platformWebDllPath))
{
var discoveryAbsolutePath = Path.GetFullPath(GetDiscoveryPath());
packageManifest = CreateManifestFromEnvironment(RootDirectory, (AbsolutePath)discoveryAbsolutePath);
}
else if (!File.Exists(packageManifestPath))
{
Logger.Info("vc-package.json is not exists.");
Logger.Info("Looking for the platform release");
var platformRelease = await GithubManager.GetPlatformRelease(GitHubToken, VersionToInstall);
packageManifest = PackageManager.CreatePackageManifest(platformRelease.TagName);
}
else
{
packageManifest = PackageManager.FromFile(PackageManifestPath);
}
return packageManifest;
}

private static PackageManifest CreateManifestFromEnvironment(AbsolutePath platformPath, AbsolutePath discoveryPath)
{
var platformWebDllPath = platformPath / "VirtoCommerce.Platform.Web.dll";
if (!FileSystemTasks.FileExists(platformWebDllPath))
{
ControlFlow.Fail($"{platformWebDllPath} can't be found!");
}
var platformWebDllFileInfo = FileVersionInfo.GetVersionInfo(platformWebDllPath);
var platformVersion = platformWebDllFileInfo.ProductVersion;
var packageManifest = PackageManager.CreatePackageManifest(platformVersion);

var manifests = discoveryPath.GlobFiles("*/module.manifest");
manifests.ForEach(m => {
var manifest = ManifestReader.Read(m);
packageManifest.Modules.Add(new ModuleItem(manifest.Id, manifest.Version));
});
return packageManifest;
}
}

0 comments on commit 37b9b02

Please sign in to comment.