-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
cask.el
66 lines (60 loc) · 2.21 KB
/
cask.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
;;; init/cask.el --- Initialize Eask from Cask -*- lexical-binding: t; -*-
;;; Commentary:
;;
;; Commmand use to convert Cask-file to Eask-file
;;
;; $ eask init --from cask
;;
;;; Code:
(load (expand-file-name
"../_prepare.el"
(file-name-directory (nth 1 (member "-scriptload" command-line-args))))
nil t)
(defun eask--convert-cask (filename)
"Convert Cask FILENAME to Eask."
(let* ((filename (expand-file-name filename))
(file (eask-root-del filename))
(new-file (eask-s-replace "Cask" "Eask" file))
(new-filename (expand-file-name new-file))
(converted))
(eask-with-progress
(format "Converting file `%s` to `%s`... " file new-file)
(eask-with-verbosity 'debug
(cond ((not (string-prefix-p "Cask" file))
(eask-debug "✗ Invalid Cask filename, the file should start with `Cask`"))
((file-exists-p new-filename)
(eask-debug "✗ The file `%s` already presented" new-file))
(t
(with-current-buffer (find-file new-filename)
(insert-file-contents file)
(goto-char (point-min))
(while (re-search-forward "(source " nil t)
(insert "'")) ; make it symbol
(save-buffer))
(setq converted t))))
(if converted "done ✓" "skipped ✗"))
converted))
(eask-start
(let* ((patterns (eask-args))
(files (if patterns
(eask-expand-file-specs patterns)
(directory-files default-directory t "Cask")))
(converted 0))
(cond
;; Files found, do the action!
(files
(dolist (file files)
(when (eask--convert-cask file)
(cl-incf converted)))
(eask-msg "")
(eask-info "(Total of %s Cask-file%s converted)" converted
(eask--sinr converted "" "s")))
;; Pattern defined, but no file found!
(patterns
(eask-info "No files found with wildcard pattern: %s"
(mapconcat #'identity patterns " ")))
;; Default, print help!
(t
(eask-info "(No Cask-files have been converted to Eask)")
(eask-help "init/cask")))))
;;; init/cask.el ends here