-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VCI-822: Add local modules source (#125)
- Loading branch information
1 parent
b27925e
commit 3dce9c7
Showing
12 changed files
with
98 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/VirtoCommerce.Build/PlatformTools/Modules/LocalModules/Local.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<LocalModuleItem> Modules { get; set; } | ||
} |
55 changes: 55 additions & 0 deletions
55
src/VirtoCommerce.Build/PlatformTools/Modules/LocalModules/LocalModuleInstaller.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ProgressMessage> 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; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/VirtoCommerce.Build/PlatformTools/Modules/LocalModules/LocalModuleItem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters