From 3bca78b6b552a5fcc391acdd6bd2603d9dc62f8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Pereira?= Date: Fri, 22 Oct 2021 11:38:09 +0100 Subject: [PATCH] chore: remove dependencies packing #54 --- cmf-cli/Commands/pack/PackCommand.cs | 93 ++-------------------------- 1 file changed, 4 insertions(+), 89 deletions(-) diff --git a/cmf-cli/Commands/pack/PackCommand.cs b/cmf-cli/Commands/pack/PackCommand.cs index da64aabf..e2513ccd 100644 --- a/cmf-cli/Commands/pack/PackCommand.cs +++ b/cmf-cli/Commands/pack/PackCommand.cs @@ -7,9 +7,7 @@ using System; using System.CommandLine; using System.CommandLine.Invocation; -using System.IO; using System.IO.Abstractions; -using System.Linq; namespace Cmf.Common.Cli.Commands { @@ -41,20 +39,12 @@ public override void Configure(Command cmd) isDefault: true, description: "Output directory for created package")); - cmd.AddOption(new Option( - aliases: new string[] { "-r", "--repo" }, - description: "Repository where dependencies are located (url or folder)")); - cmd.AddOption(new Option( aliases: new string[] { "-f", "--force" }, description: "Overwrite all packages even if they already exists")); - cmd.AddOption(new Option( - aliases: new string[] { "--skipDependencies" }, - description: "Do not get all dependencies recursively")); - // Add the handler - cmd.Handler = CommandHandler.Create(Execute); + cmd.Handler = CommandHandler.Create(Execute); } /// @@ -62,20 +52,16 @@ public override void Configure(Command cmd) /// /// The working dir. /// The output dir. - /// The repo. /// if set to true [force]. - /// /// - public void Execute(IDirectoryInfo workingDir, IDirectoryInfo outputDir, string repo, bool force, bool skipDependencies) + public void Execute(IDirectoryInfo workingDir, IDirectoryInfo outputDir, bool force) { IFileInfo cmfpackageFile = this.fileSystem.FileInfo.FromFileName($"{workingDir}/{CliConstants.CmfPackageFileName}"); - Uri repoUri = repo != null ? new Uri(repo) : null; - // Reading cmfPackage CmfPackage cmfPackage = CmfPackage.Load(cmfpackageFile, setDefaultValues: true); - Execute(cmfPackage, outputDir, repoUri, null, force, skipDependencies); + Execute(cmfPackage, outputDir, force); } /// @@ -83,20 +69,15 @@ public void Execute(IDirectoryInfo workingDir, IDirectoryInfo outputDir, string /// /// The CMF package. /// The output dir. - /// The repo URI. - /// The loaded packages. /// if set to true [force]. - /// /// /// /// - public void Execute(CmfPackage cmfPackage, IDirectoryInfo outputDir, Uri repoUri, CmfPackageCollection loadedPackages, bool force, bool skipDependencies) + public void Execute(CmfPackage cmfPackage, IDirectoryInfo outputDir, bool force) { // TODO: Need to review file patterns in contentToPack and contentToIgnore IPackageTypeHandler packageTypeHandler = PackageTypeFactory.GetPackageTypeHandler(cmfPackage); - loadedPackages ??= new CmfPackageCollection(); - IDirectoryInfo packageDirectory = cmfPackage.GetFileInfo().Directory; #region Output Directories Handling @@ -114,72 +95,6 @@ public void Execute(CmfPackage cmfPackage, IDirectoryInfo outputDir, Uri repoUri try { packageTypeHandler.Pack(packageOutputDir, outputDir); - - #region Get Dependencies - - if (!skipDependencies - && cmfPackage.Dependencies.HasAny()) - { - // Read all local manifests - CmfPackageCollection _loadedPackages = packageDirectory.LoadCmfPackagesFromSubDirectories(setDefaultValues: true); - _loadedPackages.AddRange(loadedPackages); - - // TODO: Bulk Copy - foreach (var dependency in cmfPackage.Dependencies) - { - string _dependencyFileName = $"{dependency.Id}.{dependency.Version}.zip"; - bool dependencyFound = false; - - // Check if dependency is already in the Output Directory - if (outputDir.GetFiles(_dependencyFileName).HasAny()) - { - if (force) - { - outputDir.GetFiles(_dependencyFileName)[0].Delete(); - } - else - { - // TODO: Validate if all child Dependencies are also in the OutputDir - Log.Information($"Skipping {_dependencyFileName}. Already packed in Output Directory."); - continue; - } - } - - // Some logic removed is trying to load CmfPackage.json on output repository and generate package again - dependencyFound = GenericUtilities.GetPackageFromRepository(outputDir, repoUri, force, dependency.Id, dependency.Version, this.fileSystem); - - #region Get Loaded Dependencies - - if (!dependencyFound) - { - // Search by Packages to Pack - CmfPackage dependencyPackage = _loadedPackages.GetDependency(dependency); - - // cmfpackage.json found, need to pack - if (dependencyPackage != null) - { - dependencyFound = true; - Execute(dependencyPackage, outputDir, repoUri, _loadedPackages, force, skipDependencies); - } - } - - #endregion - - if (!dependencyFound) - { - if (dependency.Mandatory) - { - throw new CliException(string.Format(CliMessages.MissingMandatoryDependency, dependency)); - } - else - { - Log.Warning(string.Format(CliMessages.MissingMandatoryDependency, dependency)); - } - } - } - } - - #endregion } catch (Exception e) {