Browse Source

Support glob

pull/9145/head
liangshiwei 5 years ago
parent
commit
bc38fb717e
  1. 1
      framework/src/Volo.Abp.Cli.Core/Volo.Abp.Cli.Core.csproj
  2. 2
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/InstallLibsCommand.cs
  3. 75
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/LIbs/InstallLibsService.cs

1
framework/src/Volo.Abp.Cli.Core/Volo.Abp.Cli.Core.csproj

@ -13,6 +13,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="$(MicrosoftPackageVersion)" />
<PackageReference Include="SharpZipLib" Version="1.3.1" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" />
<PackageReference Include="NuGet.Versioning" Version="5.9.0" />

2
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/InstallLibsCommand.cs

@ -63,7 +63,7 @@ namespace Volo.Abp.Cli.Commands
public string GetShortDescription()
{
return "Bundles all third party styles and scripts required by modules and updates index.html file.";
return "Restore all npm packages and copy to libs.";
}
public static class Options

75
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/LIbs/InstallLibsService.cs

@ -1,7 +1,10 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.FileSystemGlobbing;
using Microsoft.Extensions.FileSystemGlobbing.Abstractions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using NuGet.Versioning;
@ -77,7 +80,7 @@ namespace Volo.Abp.Cli.LIbs
mapping.ReplaceAliases();
resourceMapping.Clean.AddRange(mapping.Clean);
mapping.Clean.ForEach(c => resourceMapping.Clean.AddIfNotContains(c));
mapping.Aliases.ToList().ForEach(x =>
{
resourceMapping.Aliases.AddIfNotContains(new KeyValuePair<string, string>(x.Key, x.Value));
@ -97,24 +100,21 @@ namespace Volo.Abp.Cli.LIbs
{
foreach (var mapping in resourceMapping.Mappings)
{
var sourcePath = Path.Combine(fileDirectory, mapping.Key);
var destPath = Path.Combine(fileDirectory, mapping.Value);
if (Path.HasExtension(sourcePath) && File.Exists(sourcePath))
{
Directory.CreateDirectory(Path.GetFullPath(destPath));
File.Copy(sourcePath, Path.Combine(destPath, Path.GetFileName(sourcePath)), true);
}
else
var files = FindFiles(fileDirectory, mapping.Key);
foreach (var file in files)
{
var files = Directory.GetFiles(fileDirectory, mapping.Key);
var destFilePath = Path.Combine(destPath, Path.GetFileName(file));
if (File.Exists(destFilePath))
{
continue;
}
Directory.CreateDirectory(Path.GetFullPath(destPath));
File.Copy(file, destFilePath);
foreach (var file in files)
{
File.Copy(file, Path.Combine(destPath, Path.GetFileName(file)), true);
}
}
}
}
@ -133,23 +133,56 @@ namespace Volo.Abp.Cli.LIbs
private void CleanDirsAndFiles(string directory, ResourceMapping resourceMapping)
{
foreach (var cleanPattern in resourceMapping.Clean)
var files = FindFiles(directory, resourceMapping.Clean.ToArray());
foreach (var file in files)
{
CleanDirsAndFiles(directory, cleanPattern);
if (File.Exists(file))
{
File.Delete(file);
}
}
foreach (var directoryInfo in Directory.GetDirectories(Path.Combine(directory, resourceMapping.Clean.First()),"*", SearchOption.AllDirectories).Reverse())
{
if (!Directory.EnumerateFileSystemEntries(directoryInfo).Any())
{
Directory.Delete(directoryInfo);
}
}
}
private void CleanDirsAndFiles(string directory, string patterns)
private string[] FindFiles(string directory, params string[] patterns)
{
foreach (var file in Directory.GetFiles(directory, patterns))
var matcher = new Matcher();
foreach (var pattern in patterns)
{
File.Delete(file);
if (pattern.StartsWith("!"))
{
matcher.AddExclude(NormalizeGlob(pattern).TrimStart('!'));
}
else
{
matcher.AddInclude(NormalizeGlob(pattern));
}
}
foreach (var dir in Directory.GetDirectories(directory, patterns))
var result = matcher.Execute(new DirectoryInfoWrapper(new DirectoryInfo(directory)));
return result.Files.Select(x => Path.Combine(directory, x.Path)).ToArray();
}
private string NormalizeGlob(string pattern)
{
pattern = pattern.Replace("//", "/");
if (!Path.HasExtension(pattern) && !pattern.EndsWith("*"))
{
Directory.Delete(dir, true);
return pattern.EnsureEndsWith('/') + "**";
}
return pattern;
}
private void RunNpmInstall(string directory)

Loading…
Cancel
Save