diff --git a/libraries.api.php b/libraries.api.php index 023cc0a..49d4c59 100644 --- a/libraries.api.php +++ b/libraries.api.php @@ -177,7 +177,19 @@ function hook_libraries_info() { // Only used in administrative UI of Libraries API. 'name' => 'Example library', 'vendor url' => 'http://example.com', + // Optional: A website link to the Library's download page. 'download url' => 'http://example.com/download', + // Optional: Information for automated downloading of the Library using + // Drush Make. Visit Drush Make's documentation to read more regarding + // the "download" property: http://bit.ly/jWzHPa + 'download' => array( + // The type of download (file, git, svn, or cvs). + 'type' => 'git', + // The URL or repository to download the Library. + 'url' => 'git://github.com/jane_doe/mytheme.git', + // The revision information to check out. + 'revision' => '7.x-1.x', + ), // Optional: If, after extraction, the actual library files are contained in // 'sites/all/libraries/example/lib', specify the relative path here. 'path' => 'lib', diff --git a/libraries.drush.inc b/libraries.drush.inc index 26b35eb..642dbf2 100644 --- a/libraries.drush.inc +++ b/libraries.drush.inc @@ -9,18 +9,23 @@ * Implements hook_drush_command(). */ function libraries_drush_command() { + // List all registered Libraries. $items['libraries-list'] = array( 'callback' => 'libraries_drush_list', 'description' => dt('Lists registered library information.'), 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL, ); - /**$items['libraries-download'] = array( - 'callback' => 'libraries_drush_download', - 'description' => dt('Downloads a registered library into the libraries directory for the active site.'), - 'arguments' => array( - 'name' => dt('The internal name of the registered library.'), - ), - );*/ + + // Downloads all registered Libraries using Drush Make. + if (function_exists('drush_make_download_factory')) { + $items['libraries-download'] = array( + 'callback' => 'libraries_drush_download', + 'description' => dt('Downloads a registered library into the libraries directory for the active site.'), + 'arguments' => array( + 'name' => dt('The internal name of the registered library.'), + ), + ); + } return $items; } @@ -89,63 +94,29 @@ function libraries_drush_list() { * The internal name of the library to download. */ function libraries_drush_download($name) { - return; - - // @todo Looks wonky? - if (!drush_shell_exec('type unzip')) { - return drush_set_error(dt('Missing dependency: unzip. Install it before using this command.')); - } - - // @todo Simply use current drush site. - $args = func_get_args(); - if ($args[0]) { - $path = $args[0]; - } - else { - $path = 'sites/all/libraries'; - } - - // Create the path if it does not exist. - if (!is_dir($path)) { - drush_op('mkdir', $path); - drush_log(dt('Directory @path was created', array('@path' => $path)), 'notice'); - } - - // Set the directory to the download location. - $olddir = getcwd(); - chdir($path); - - $filename = basename(COLORBOX_DOWNLOAD_URI); - $dirname = basename(COLORBOX_DOWNLOAD_URI, '.zip'); - - // Remove any existing Colorbox plugin directory - if (is_dir($dirname)) { - drush_log(dt('A existing Colorbox plugin was overwritten at @path', array('@path' => $path)), 'notice'); - } - // Remove any existing Colorbox plugin zip archive - if (is_file($filename)) { - drush_op('unlink', $filename); + $library = libraries_info($name); + if (empty($library)) { + return drush_log(dt('The given Library was not found.'), 'error'); } - - // Download the zip archive - if (!drush_shell_exec('wget '. COLORBOX_DOWNLOAD_URI)) { - drush_shell_exec('curl -O '. COLORBOX_DOWNLOAD_URI); - } - - if (is_file($filename)) { - // Decompress the zip archive - drush_shell_exec('unzip -qq -o '. $filename); - // Remove the zip archive - drush_op('unlink', $filename); - } - - // Set working directory back to the previous working directory. - chdir($olddir); - - if (is_dir($path .'/'. $dirname)) { - drush_log(dt('Colorbox plugin has been downloaded to @path', array('@path' => $path)), 'success'); + if (isset($library['download'])) { + // Download the Library using Drush Make. + // @TODO: Allow changing the destination directory. + $destination = DRUPAL_ROOT . '/sites/all/libraries/' . $name; + $path = drush_make_download_factory($name, $library['download'], $destination); + if ($path) { + drush_log(dt('The @name library was downloaded to %path.', array( + '@name' => $name, + '%path' => $location, + )), 'success'); + } + else { + return drush_log(dt('There was an error downloading @name to %path.', array( + '@name' => $name, + '%path' => $location, + )), 'error'); + } } else { - drush_log(dt('Drush was unable to download the Colorbox plugin to @path', array('@path' => $path)), 'error'); + drush_log(dt('Automated downloading of this Library is not supported.'), 'error'); } }