mirror of
https://github.com/correl/melpa.git
synced 2024-11-14 19:19:32 +00:00
parent
8e45bf58b9
commit
5cc2f0b27e
3 changed files with 38 additions and 51 deletions
|
@ -127,16 +127,10 @@
|
|||
var listed = _.intersection(_.keys(archive), _.keys(recipes));
|
||||
return new melpa.PackageList(_(listed).reduce(function(pkgs, name) {
|
||||
var built = archive[name];
|
||||
if (!built || !built[0]) {
|
||||
return pkgs;
|
||||
}
|
||||
var recipe = recipes[name];
|
||||
var descr = built[2].replace(/\s*\[((?:source: )?\w+)\]$/, "");
|
||||
var version = built[0].join(".");
|
||||
// Fix up hokey deps, which look like {"clojure-mode":{"2":[0,0]}} for 2.0.0
|
||||
var deps = _.map(built[1] || {}, function (val, name) {
|
||||
var v1 = _.keys(val)[0];
|
||||
return {name: name, version: [v1].concat(val[v1] || []).join('.')};
|
||||
var version = built.ver.join(".");
|
||||
var deps = _.map(built.deps || [], function (ver, name) {
|
||||
return {name: name, version: ver.join('.')};
|
||||
});
|
||||
var oldNames = recipe['old-names'] || [];
|
||||
|
||||
|
@ -144,12 +138,12 @@
|
|||
name: name,
|
||||
version: version,
|
||||
dependencies: deps,
|
||||
description: descr,
|
||||
description: built.desc.replace(/\s*\[((?:source: )?\w+)\]$/, ""),
|
||||
source: recipe.fetcher,
|
||||
downloads: _.reduce(oldNames.concat(name), function(sum, n) { return sum + (downloads[n] || 0); }, 0),
|
||||
fetcher: recipe.fetcher,
|
||||
recipeURL: "https://github.com/milkypostman/melpa/blob/master/recipes/" + name,
|
||||
packageURL: "packages/" + name + "-" + version + "." + (built[3] == "single" ? "el" : "tar"),
|
||||
packageURL: "packages/" + name + "-" + version + "." + (built.type == "single" ? "el" : "tar"),
|
||||
sourceURL: calculateSourceURL(name, recipe),
|
||||
oldNames: oldNames
|
||||
}));
|
||||
|
|
36
json-fix.el
36
json-fix.el
|
@ -1,36 +0,0 @@
|
|||
;;; Fixes for json.el such that integer plist / alist keys are rendered as strings, in order to comply with the json spec
|
||||
|
||||
(require 'json)
|
||||
(require 'cl-lib)
|
||||
|
||||
(defun json-encode-key-value-pair (pair)
|
||||
"Encode a (key . value) PAIR as JSON, ensuring that key is encoded into a string."
|
||||
(let ((encoded-key (json-encode (car pair))))
|
||||
(format "%s:%s"
|
||||
(if (string-match "^\"" encoded-key)
|
||||
encoded-key
|
||||
(json-encode-string encoded-key))
|
||||
(json-encode (cdr pair)))))
|
||||
|
||||
(defun json-encode-hash-table (hash-table)
|
||||
"Return a JSON representation of HASH-TABLE."
|
||||
(json-encode-alist (maphash 'cons hash-table)))
|
||||
|
||||
;; List encoding (including alists and plists)
|
||||
|
||||
(defun json-encode-alist (alist)
|
||||
"Return a JSON representation of ALIST."
|
||||
(format "{%s}"
|
||||
(json-join (mapcar 'json-encode-key-value-pair
|
||||
alist) ", ")))
|
||||
|
||||
(defun json-encode-plist (plist)
|
||||
"Return a JSON representation of PLIST."
|
||||
(json-encode-alist
|
||||
(cl-loop while plist
|
||||
collect (cons (car plist) (cadr plist))
|
||||
do (setf plist (cddr plist)))))
|
||||
|
||||
|
||||
(provide 'json-fix)
|
||||
;;; json-fix.el ends here
|
|
@ -45,6 +45,7 @@
|
|||
|
||||
(require 'package)
|
||||
(require 'lisp-mnt)
|
||||
(require 'json)
|
||||
|
||||
(defconst pb/this-dir (file-name-directory (or load-file-name (buffer-file-name))))
|
||||
|
||||
|
@ -1168,10 +1169,9 @@ If FILE-NAME is not specified, the default archive-contents file is used."
|
|||
(setq entries (remove old entries)))
|
||||
(add-to-list 'entries new)))))
|
||||
|
||||
|
||||
|
||||
;; Utility functions
|
||||
(require 'json)
|
||||
(load (expand-file-name "json-fix" pb/this-dir) nil 'nomessage)
|
||||
;;; Exporting data as json
|
||||
|
||||
(defun package-build-recipe-alist-as-json (file-name)
|
||||
"Dump the recipe list to FILE-NAME as json."
|
||||
|
@ -1179,11 +1179,40 @@ If FILE-NAME is not specified, the default archive-contents file is used."
|
|||
(with-temp-file file-name
|
||||
(insert (json-encode (package-build-recipe-alist)))))
|
||||
|
||||
(defun pb/sym-to-keyword (s)
|
||||
"Return a version of symbol S as a :keyword."
|
||||
(intern (concat ":" (symbol-name s))))
|
||||
|
||||
(defun pb/pkg-info-for-json (info)
|
||||
"Convert INFO into a data structure which will serialize to JSON in the desired shape."
|
||||
(let* ((ver (elt info 0))
|
||||
(deps (elt info 1))
|
||||
(desc (elt info 2))
|
||||
(type (elt info 3))
|
||||
(props (when (> (length info) 4) (elt info 4))))
|
||||
(list :ver ver
|
||||
:deps (apply 'append
|
||||
(mapcar (lambda (dep)
|
||||
(list (pb/sym-to-keyword (car dep))
|
||||
(cadr dep)))
|
||||
deps))
|
||||
:desc desc
|
||||
:type type
|
||||
:props props)))
|
||||
|
||||
(defun pb/archive-alist-for-json ()
|
||||
"Return the archive alist in a form suitable for JSON encoding."
|
||||
(apply 'append
|
||||
(mapcar (lambda (entry)
|
||||
(list (pb/sym-to-keyword (car entry))
|
||||
(pb/pkg-info-for-json (cdr entry))))
|
||||
(package-build-archive-alist))))
|
||||
|
||||
(defun package-build-archive-alist-as-json (file-name)
|
||||
"Dump the build packages list to FILE-NAME as json."
|
||||
(interactive)
|
||||
(with-temp-file file-name
|
||||
(insert (json-encode (package-build-archive-alist)))))
|
||||
(insert (json-encode (pb/archive-alist-for-json)))))
|
||||
|
||||
|
||||
(provide 'package-build)
|
||||
|
|
Loading…
Reference in a new issue