From 37b9b02bbd6890713fe5157cd27ef3fa41394515 Mon Sep 17 00:00:00 2001 From: Alexandr Morogov <42555001+krankenbro@users.noreply.github.com> Date: Tue, 17 Aug 2021 11:12:14 +0200 Subject: [PATCH] VCI-91: Add manifest creation from existing environment (#13) * VCI-91: Add manifest creation from existing environment * VCI-91: Fix codesmell --- PlatformTools/Build.PackageManager.cs | 58 ++++++++++++++++++++------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/PlatformTools/Build.PackageManager.cs b/PlatformTools/Build.PackageManager.cs index 81213db..a23e826 100644 --- a/PlatformTools/Build.PackageManager.cs +++ b/PlatformTools/Build.PackageManager.cs @@ -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); @@ -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; @@ -316,5 +304,47 @@ private bool NeedToInstallPlatform(string version) } PackageManager.ToFile(packageManifest); + }); + + private async Task 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; + } }