Created
January 16, 2014 15:16
-
-
Save bjjb/8456583 to your computer and use it in GitHub Desktop.
Lets you enter the name of a JavaScript library on the command-line, and prints out the library's contents, having fetched it from cdnjs.com.
`cdnjs backbone.js`, for example, or `cdnjs jquery > jquery.js` to save it.
This file contains hidden or 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
| #! /usr/bin/env perl | |
| # A simple command-line utility for finding and retrieving JavaScript libraries | |
| # from cdnjs.com | |
| use strict; | |
| use warnings; | |
| use LWP::Simple; | |
| my $lib = shift or die "No script entered on the command-line!"; | |
| get("http://cdnjs.com") =~ m#<tr[^>]+data-library-name="$lib"[^>]*>.*?<p[^>]+itemprop="downloadUrl"[^>]+>([^<]+)#; | |
| die "Failed to find $lib at cdnjs.com - are you sure the name is right?" unless $1; | |
| my $url = "http:$1"; | |
| my $script = get($url); | |
| print $script; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment