Optionally write badge images for use on github pages etc

See #2099
This commit is contained in:
Steve Purcell 2014-10-22 17:29:05 +01:00
parent 711ddbeb29
commit 7a86f574a5

View file

@ -95,6 +95,11 @@ Certain package names (e.g. \"@\") may not work properly with a BSD tar."
:group 'package-build
:type '(file :must-match t))
(defcustom package-build-write-melpa-badge-images nil
"When non-nil, write MELPA badge images alongside packages, for use on github pages etc."
:group 'package-build
:type 'boolean)
;;; Internal Variables
(defvar pb/recipe-alist nil
@ -1013,6 +1018,7 @@ simply pass `package-build-default-files-spec' in most cases.
Returns the archive entry for the package."
(when (symbolp package-name)
(setq package-name (symbol-name package-name)))
(prog1
(let ((files (package-build-expand-file-specs source-dir file-specs)))
(unless (equal file-specs package-build-default-files-spec)
(when (equal files (package-build-expand-file-specs
@ -1096,9 +1102,26 @@ Returns the archive entry for the package."
(delete-directory pkg-tmp-dir t nil)
(pb/archive-entry pkg-info 'tar)))
(t (error "Unable to find files matching recipe patterns")))))
(t (error "Unable to find files matching recipe patterns"))))
(when package-build-write-melpa-badge-images
(pb/write-melpa-badge-image package-name version target-dir))))
;; In future we should provide a hook, and perform this step in a separate package.
;; Note also that it would be straightforward to generate the SVG ourselves, which would
;; save the network overhead.
(defun pb/write-melpa-badge-image (package-name version target-dir)
(url-copy-file
(concat "http://img.shields.io/badge/"
(if package-build-stable "melpa stable" "melpa")
"-"
(url-hexify-string version)
"-"
(if package-build-stable "3e999f" "922793")
".svg")
(expand-file-name (concat package-name "-badge.svg") target-dir)
t))
;;; Helpers for recipe authors