Use Powershell to download files (from DefinitelyTyped) [5 minutes]

Powershell gives us dotnet power to the commandline. I wanted to be able to easily download Typescript definition files from the awesome DefinitelyTyped project on GitHub and put together a short script for that reason:

Function GetDts ($lib)
{
  $url = "https://github.com/borisyankov/DefinitelyTyped/raw/master/" + $lib + "/" + $lib + ".d.ts"
  (New-Object System.Net.WebClient).DownloadFile($url,$pwd.path + "/" + $lib + ".d.ts")
}

To use it : add the code to your powershell, for example at your Visual Studio project location:

1) Right click folder in VS Solution Explorer, click Open Folder in File Explorer

2) Type “Powershell” in the Explorer address bar

3) Paste the code above

4) Hit enter once or twice to get out of the >> prompt

5) Change to your definitions path (if you have one):

cd definitions

6) Go ahead and download your d.ts’es:

GetDts jquery
GetDts jasmine
GetDts whatever

7) The script downloads the files to your current path

GetDts

Some comments
This code defines a function that lives as long as you have your powershell script open. It disappears when you end the session (close the window), and you have to re add the function again. If you like to keep the script you will need to save it.

The code assumes that the definition file is to be found in the url https://github.com/borisyankov/DefinitelyTyped/raw/master/{library}/{library.d.ts}).

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s