]> code.delx.au - gnu-emacs-elpa/blobdiff - packages/context-coloring/scripts/download-dependencies.el
Add *.info and dir to debbugs
[gnu-emacs-elpa] / packages / context-coloring / scripts / download-dependencies.el
index 37f243b96d8136eef10d3cdde24fb251e43742b0..2ab24e2f496ffec421fa66f2632aaf88722bfc9f 100644 (file)
@@ -1,4 +1,4 @@
-;; -*- lexical-binding: t; -*-
+;;; scripts/download-dependencies.el --- Get files for development. -*- lexical-binding: t; -*-
 
 ;; Copyright (C) 2014-2015  Free Software Foundation, Inc.
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-(defconst directory (file-name-directory (or load-file-name buffer-file-name)))
+;; Download dependencies for development.
 
-(defun resolve-path (path)
-  (expand-file-name path directory))
+;; Dependencies don't need to be version-controlled. They are also
+;; bleeding-edge, which is good because that is what most MELPA users are using.
 
-(defun strip-headers ()
+;;; Code:
+
+(defconst download-dependencies-directory
+  (file-name-directory (or load-file-name buffer-file-name))
+  "This file's directory.")
+
+(defun download-dependencies-resolve-path (path)
+  "Resolve a path relative to this file's directory."
+  (expand-file-name path download-dependencies-directory))
+
+(defun download-dependencies-strip-headers ()
+  "Remove the http headers included in the output of
+`url-retrieve-synchronously'."
   (goto-char 1)
-  (kill-paragraph 1) ; The headers are 1 paragraph. I hope.
-  (kill-line)        ; A line separates the headers from the file's content.
-  )
-
-(let ((files '("https://raw.githubusercontent.com/mooz/js2-mode/master/js2-mode.el"
-               "https://raw.githubusercontent.com/rejeep/ert-async.el/master/ert-async.el")))
-  (make-directory (resolve-path "../libraries") t)
-  (dolist (file files)
-    (let* ((basename (file-name-nondirectory file))
-           (destination (resolve-path (concat "../libraries/" basename))))
-      (when (null (file-exists-p destination))
-        (with-current-buffer (url-retrieve-synchronously file)
-          (strip-headers)
-          (write-file destination))))))
+  (kill-paragraph 1) ; The headers are 1 paragraph.  I hope.
+  (kill-line))       ; A line separates the headers from the file's content.
+
+(defun download-dependencies-get-dependencies ()
+  "Read the `dependencies' file as a list of URLs."
+  (with-temp-buffer
+    (insert-file-contents (download-dependencies-resolve-path "./dependencies"))
+    (split-string (buffer-substring-no-properties (point-min) (point-max)))))
+
+(defun download-dependencies ()
+  "Download dependencies for development."
+  (let ((files (download-dependencies-get-dependencies)))
+    (make-directory (download-dependencies-resolve-path "../libraries") t)
+    (dolist (file files)
+      (let* ((basename (file-name-nondirectory file))
+             (destination (download-dependencies-resolve-path
+                           (concat "../libraries/" basename))))
+        (unless (file-exists-p destination)
+          (with-current-buffer (url-retrieve-synchronously file)
+            (download-dependencies-strip-headers)
+            (write-file destination)))))))
+
+;;; download-dependencies.el ends here