22using System . Collections . Generic ;
33using System . IO ;
44using System . Linq ;
5- using System . Net . Http ;
65using System . Text . RegularExpressions ;
76using System . Threading . Tasks ;
87
@@ -11,11 +10,7 @@ namespace dotnet_unpkg
1110 public static class Add
1211 {
1312 private static readonly Regex DistInPath = new Regex ( @"\/dist\/.*" ) ;
14- private static readonly HttpClient Client = new HttpClient
15- {
16- BaseAddress = new Uri ( "https://unpkg.com" )
17- } ;
18-
13+
1914 private static readonly string BaseDirectory = Path . Combine ( "wwwroot" , "lib" ) ;
2015
2116 public static async Task Run ( IEnumerable < string > args )
@@ -78,7 +73,14 @@ private static Task DownloadPackage(string package, string basePath, IEnumerable
7873
7974 private static async Task DownloadFile ( string package , string basePath , DistFile file )
8075 {
81- var ( cdn , localPath ) = await Download . DistFile ( package , $ "{ basePath . TrimSlashes ( ) } /{ file . Path . TrimSlashes ( ) } ") ;
76+ basePath = basePath . TrimSlashes ( ) ;
77+ var path = file . Path . TrimSlashes ( ) ;
78+ var pathSegments = path . Split ( '/' ) ;
79+ if ( basePath . Split ( '/' ) . LastOrDefault ( ) == pathSegments . FirstOrDefault ( ) )
80+ {
81+ path = string . Join ( '/' , pathSegments . Skip ( 1 ) ) ;
82+ }
83+ var ( cdn , localPath ) = await Download . DistFile ( package , $ "{ basePath } /{ path } ") ;
8284 file . Url = cdn ;
8385 file . LocalPath = localPath . Replace ( Path . DirectorySeparatorChar , '/' ) ;
8486 }
0 commit comments