powershell 2.0 下载 bootcdn 资源

powershell 2.0 , win 7 以上操作系统可用。

[System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions")

$path = "D:\front\"
$library = "element-ui"

$json = "[]"
$json = $client.DownloadString("https://api.bootcdn.cn/libraries/"+ $library +".json")
$ser = New-Object System.Web.Script.Serialization.JavaScriptSerializer
$obj = $ser.DeserializeObject($json)
##$info = ConvertFrom-Json -InputObject $json
if($obj.assets.length){
    $array = $obj.assets[0].files
    $version = $obj.assets[0].version
    $client = new-object System.Net.WebClient
    foreach ($src in $array){
    $url = "https://cdn.bootcss.com/"+ $library +"/" + $version +"/" + $src 
    $des = ( $path + $library + "@" + $version  +"/" + $src ).replace("/", "\")
    if((Test-Path $des.Substring(0,$des.LastIndexOf('\')) ) -eq $False)
    {
        New-Item $des.Substring(0,$des.LastIndexOf('\')) -type directory
    }
    $client.DownloadFile($url,$des)
    }
}

猜你喜欢

转载自www.cnblogs.com/edit/p/9541206.html
今日推荐