diff --git a/docs/CLI-tools/package-management.md b/docs/CLI-tools/package-management.md index 7793d56..d2ff8a6 100644 --- a/docs/CLI-tools/package-management.md +++ b/docs/CLI-tools/package-management.md @@ -81,6 +81,18 @@ This command downloads and installs the platform or modules into the relevant fo "Id": "42920184" } ] + }, + { + "Name": "Local", + "Modules": [ + { + "Path": "C:/projects/vc/vc-module-saas/artifacts/VirtoCommerce.SaaS_3.214.0.zip", + "Id": "OptionalForThisSource" + }, + { + "Path": "C:\\projects\\vc\\vc-module-catalog\\artifacts\\VirtoCommerce.Catalog" + } + ] } ], "ManifestVersion": "2.0", diff --git a/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs b/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs index 310c17f..5a43e26 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs @@ -16,6 +16,7 @@ using PlatformTools.Modules.Azure; using PlatformTools.Modules.Github; using PlatformTools.Modules.Gitlab; +using PlatformTools.Modules.LocalModules; using Serilog; using VirtoCommerce.Build.PlatformTools; using VirtoCommerce.Platform.Core.Common; @@ -474,13 +475,14 @@ private static ManifestModuleInfo LoadModuleInfo(ModuleItem module, ManifestModu return moduleInfo; } - private static ModulesInstallerBase GetModuleInstaller(ModuleSource moduleSource) => moduleSource switch + private static ModuleInstallerBase GetModuleInstaller(ModuleSource moduleSource) => moduleSource switch { AzurePipelineArtifacts => new AzurePipelineArtifactsModuleInstaller(AzureToken, GetDiscoveryPath()), AzureUniversalPackages => new AzureUniversalPackagesModuleInstaller(AzureToken, GetDiscoveryPath()), GithubPrivateRepos => new GithubPrivateModulesInstaller(GitHubToken, GetDiscoveryPath()), AzureBlob _ => new AzureBlobModuleInstaller(AzureToken, GetDiscoveryPath()), GitlabJobArtifacts _ => new GitlabJobArtifactsModuleInstaller(GitLabServer, GitLabToken, GetDiscoveryPath()), + Local _ => new LocalModuleInstaller(GetDiscoveryPath()), _ => throw new NotImplementedException("Unknown module source"), }; @@ -687,7 +689,6 @@ private async static Task CreateManifestFromEnvironment(AbsolutePa if (!modulesInCatalog.Contains(manifest.Id)) { Log.Warning("There is no module {0}:{1} in external catalog. You should add it in manifest manually.", manifest.Id, manifest.Version); - } else { diff --git a/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzureBlobModuleInstaller.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzureBlobModuleInstaller.cs index e0b1c7e..83ac315 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzureBlobModuleInstaller.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzureBlobModuleInstaller.cs @@ -9,7 +9,7 @@ namespace PlatformTools.Modules.Azure { - internal class AzureBlobModuleInstaller : ModulesInstallerBase + internal class AzureBlobModuleInstaller : ModuleInstallerBase { private readonly string _token; private readonly string _destination; diff --git a/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzurePipelineArtifactsModuleInstaller.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzurePipelineArtifactsModuleInstaller.cs index cf7d513..74946c7 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzurePipelineArtifactsModuleInstaller.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzurePipelineArtifactsModuleInstaller.cs @@ -8,7 +8,7 @@ namespace PlatformTools.Modules.Azure { - internal class AzurePipelineArtifactsModuleInstaller : ModulesInstallerBase + internal class AzurePipelineArtifactsModuleInstaller : ModuleInstallerBase { private readonly string _token; private readonly string _discoveryPath; diff --git a/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzureUniversalPackagesModuleInstaller.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzureUniversalPackagesModuleInstaller.cs index 3cc508f..593e5c8 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzureUniversalPackagesModuleInstaller.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzureUniversalPackagesModuleInstaller.cs @@ -11,7 +11,7 @@ namespace PlatformTools.Modules.Azure { - internal class AzureUniversalPackagesModuleInstaller : ModulesInstallerBase + internal class AzureUniversalPackagesModuleInstaller : ModuleInstallerBase { readonly string token; readonly string discoveryPath; diff --git a/src/VirtoCommerce.Build/PlatformTools/Modules/Github/GithubPrivateModulesInstaller.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/Github/GithubPrivateModulesInstaller.cs index a322fa8..059e3cb 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Modules/Github/GithubPrivateModulesInstaller.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/Github/GithubPrivateModulesInstaller.cs @@ -11,7 +11,7 @@ namespace PlatformTools.Modules.Github { - internal class GithubPrivateModulesInstaller : ModulesInstallerBase + internal class GithubPrivateModulesInstaller : ModuleInstallerBase { private readonly string _token; diff --git a/src/VirtoCommerce.Build/PlatformTools/Modules/Gitlab/GitlabJobArtifactsModuleInstaller.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/Gitlab/GitlabJobArtifactsModuleInstaller.cs index 0efaab7..e45f7a3 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Modules/Gitlab/GitlabJobArtifactsModuleInstaller.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/Gitlab/GitlabJobArtifactsModuleInstaller.cs @@ -8,7 +8,7 @@ namespace PlatformTools.Modules.Gitlab; -internal class GitlabJobArtifactsModuleInstaller : ModulesInstallerBase +internal class GitlabJobArtifactsModuleInstaller : ModuleInstallerBase { private readonly GitLabClient _client; private readonly string _discoveryPath; diff --git a/src/VirtoCommerce.Build/PlatformTools/Modules/LocalModules/Local.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/LocalModules/Local.cs new file mode 100644 index 0000000..003aa38 --- /dev/null +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/LocalModules/Local.cs @@ -0,0 +1,8 @@ +using System.Collections.Generic; + +namespace PlatformTools.Modules.LocalModules; +internal class Local : ModuleSource +{ + public override string Name { get; set; } = nameof(Local); + public List Modules { get; set; } +} diff --git a/src/VirtoCommerce.Build/PlatformTools/Modules/LocalModules/LocalModuleInstaller.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/LocalModules/LocalModuleInstaller.cs new file mode 100644 index 0000000..94c6f5d --- /dev/null +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/LocalModules/LocalModuleInstaller.cs @@ -0,0 +1,55 @@ +using System; +using System.IO; +using System.Threading.Tasks; +using Extensions; +using Nuke.Common.IO; +using VirtoCommerce.Platform.Core.Modularity; + +namespace PlatformTools.Modules.LocalModules +{ + internal class LocalModuleInstaller : ModuleInstallerBase + { + readonly string _modulesDirectory; + + public LocalModuleInstaller(string modulesDirectory) + { + _modulesDirectory = modulesDirectory; + } + protected override async Task InnerInstall(ModuleSource source, IProgress progress) + { + var moduleSource = (Local)source; + + foreach (var module in moduleSource.Modules) + { + var moduleSourceName = module.Id ?? Path.GetFileName(module.Path); + var moduleDestination = Path.Combine(_modulesDirectory, moduleSourceName); + var attributes = File.GetAttributes(module.Path); + if (attributes.HasFlag(FileAttributes.Directory)) + { + progress.ReportInfo($"Copying the module from the directory {module.Path}"); + await SetupModuleFromDirectory(module.Path, moduleDestination); + } + else + { + progress.ReportInfo($"Extracting an archive {moduleSourceName}"); + await SetupModuleFromArchive(module.Path, moduleDestination); + } + progress.ReportInfo($"Successfully installed {moduleSourceName}"); + } + } + + private static Task SetupModuleFromArchive(string src, string moduleDestination) + { + var absolutePath = src.ToAbsolutePath(); + absolutePath.UnZipTo(moduleDestination.ToAbsolutePath()); + return Task.CompletedTask; + } + + private static Task SetupModuleFromDirectory(string src, string moduleDestination) + { + var absolutePath = src.ToAbsolutePath(); + FileSystemTasks.CopyDirectoryRecursively(absolutePath, moduleDestination.ToAbsolutePath(), DirectoryExistsPolicy.Merge, FileExistsPolicy.OverwriteIfNewer); + return Task.CompletedTask; + } + } +} diff --git a/src/VirtoCommerce.Build/PlatformTools/Modules/LocalModules/LocalModuleItem.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/LocalModules/LocalModuleItem.cs new file mode 100644 index 0000000..fa7b33a --- /dev/null +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/LocalModules/LocalModuleItem.cs @@ -0,0 +1,11 @@ +namespace PlatformTools.Modules.LocalModules; + +internal class LocalModuleItem : ModuleItem +{ + public LocalModuleItem(string id, string version) : base(id, version) + { + + } + + public string Path { get; set; } +} diff --git a/src/VirtoCommerce.Build/PlatformTools/Modules/ModulesInstallerBase.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/ModuleInstallerBase.cs similarity index 96% rename from src/VirtoCommerce.Build/PlatformTools/Modules/ModulesInstallerBase.cs rename to src/VirtoCommerce.Build/PlatformTools/Modules/ModuleInstallerBase.cs index d024ad2..7219584 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Modules/ModulesInstallerBase.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/ModuleInstallerBase.cs @@ -4,7 +4,7 @@ namespace PlatformTools.Modules { - public abstract class ModulesInstallerBase + public abstract class ModuleInstallerBase { public virtual Task Install(ModuleSource source, IProgress progress) { diff --git a/src/VirtoCommerce.Build/PlatformTools/Modules/ModuleSourceConverter.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/ModuleSourceConverter.cs index 68af9f4..7930cf9 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Modules/ModuleSourceConverter.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/ModuleSourceConverter.cs @@ -5,6 +5,7 @@ using PlatformTools.Modules.Azure; using PlatformTools.Modules.Github; using PlatformTools.Modules.Gitlab; +using PlatformTools.Modules.LocalModules; using VirtoCommerce.Build.PlatformTools; namespace PlatformTools.Modules @@ -40,6 +41,8 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist case nameof(GitlabJobArtifacts): return JsonConvert.DeserializeObject(jo.ToString(), SpecifiedSubclassConversion); + case nameof(Local): + return JsonConvert.DeserializeObject(jo.ToString(), SpecifiedSubclassConversion); default: throw new TypeLoadException($"Unknown module source: {sourceName}"); }