Skip to content

Commit

Permalink
feat(init): Add init from Eldev (#193)
Browse files Browse the repository at this point in the history
* feat(init): Add init from Eldev

* rm msg
  • Loading branch information
jcs090218 authored Oct 13, 2023
1 parent f4540bd commit 0faeca4
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
* Add docker command (#188)
* Enter docker directly when no arguments (#191)
* Add command to generate recipe (#192)
* Add option to init from `Eldev`-file (#193)

## 0.8.x
> Released Mar 08, 2023
Expand Down
1 change: 1 addition & 0 deletions cmds/core/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ exports.handler = async (argv) => {
if (argv.from) {
switch (argv.from) {
case 'cask':
case 'eldev':
case 'keg':
case 'source':
await UTIL.e_call(argv, 'init/' + argv.from
Expand Down
17 changes: 12 additions & 5 deletions docs/content/en/Getting-Started/Commands-and-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,29 @@ Eask will generate the file like this:
(depends-on "emacs" "26.1")
```

**[RECOMMENDED]** If you already have an elisp project, you can convert the
`.el` file to Eask-file:

```
$ eask init --from source /path/to/source.el
```

If you already have a [Cask][] project, you can convert Cask-file to Eask-file:

```
$ eask init --from cask /path/to/Cask
```

If you already have a [Keg][] project, you can convert Keg-file to Eask-file:
If you already have a [Eldev][] project, you can convert Eldev-file to Eask-file:

```
$ eask init --from keg /path/to/Keg
$ eask init --from eldev /path/to/Eldev
```

**[RECOMMENDED]** If you already have an elisp project, you can convert the
`.el` file to Eask-file:
If you already have a [Keg][] project, you can convert Keg-file to Eask-file:

```
$ eask init --from source /path/to/source.el
$ eask init --from keg /path/to/Keg
```

{{< hint ok >}}
Expand Down Expand Up @@ -931,4 +937,5 @@ Do not use a proxy for any URL matching pattern.


[Cask]: https://github.com/cask/cask
[Eldev]: https://emacs-eldev.github.io/eldev/
[Keg]: https://github.com/conao3/keg.el
15 changes: 11 additions & 4 deletions docs/content/zh-TW/Getting-Started/Commands-and-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,28 @@ Eask 將生成這樣的文件:
(depends-on "emacs" "26.1")
```

**[推薦]** 如果您已有 elisp 項目,您可以將 `.el` 文件轉換為 Eask 文件:

```
$ eask init --from source /path/to/source.el
```

如果您已有 [Cask][] 項目,您可以將 Cask 文件轉換為 Eask 文件:

```
$ eask init --from cask /path/to/Cask
```

如果您已有 [Keg][] 項目,您可以將 Keg 文件轉換為 Eask 文件:
如果您已有 [Eldev][] 項目,您可以將 Eldev 文件轉換為 Eask 文件:

```
$ eask init --from keg /path/to/Keg
$ eask init --from eldev /path/to/Eldev
```

**[推薦]** 如果您已有 elisp 項目,您可以將 `.el` 文件轉換為 Eask 文件:
如果您已有 [Keg][] 項目,您可以將 Keg 文件轉換為 Eask 文件:

```
$ eask init --from source /path/to/source.el
$ eask init --from keg /path/to/Keg
```

{{< hint ok >}}
Expand Down Expand Up @@ -918,4 +924,5 @@ $ eask --proxy "localhost:8888" [COMMAND]


[Cask]: https://github.com/cask/cask
[Eldev]: https://emacs-eldev.github.io/eldev/
[Keg]: https://github.com/conao3/keg.el
2 changes: 1 addition & 1 deletion lisp/_prepare.el
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ will return `lint/checkdoc' with a dash between two subcommands."

(defun eask-special-p ()
"Return t if the command that can be run without Eask-file existence."
(member (eask-command) '("init/cask" "init/keg"
(member (eask-command) '("init/cask" "init/eldev" "init/keg"
"init/source"
"cat" "keywords"
"generate/ignore" "generate/license")))
Expand Down
6 changes: 6 additions & 0 deletions lisp/help/init/eldev
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

💡 Make sure you have a valid Eldev-file in your directory

💡 Or specify Eldev-file explicitly, like:

$ eask init --from=eldev /path/to/Eldev
112 changes: 112 additions & 0 deletions lisp/init/eldev.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
;;; init/eldev.el --- Initialize Eask from Eldev -*- lexical-binding: t; -*-

;;; Commentary:
;;
;; Commmand use to convert Eldev-file to Eask-file
;;
;; $ eask init --from eldev
;;

;;; Code:

(let ((dir (file-name-directory (nth 1 (member "-scriptload" command-line-args)))))
(load (expand-file-name "_prepare.el"
(locate-dominating-file dir "_prepare.el"))
nil t))

(defun eask--eldev-map-elpa (name)
"Convert Eldev mapping to Eask mapping."
(pcase name
("melpa-unstable" 'melpa)
(_ name)))

(defun eask--convert-eldev (filename)
"Convert Eldev FILENAME to Eask."
(let* ((filename (expand-file-name filename))
(file (file-name-nondirectory (eask-root-del filename)))
(new-file (eask-s-replace "Eldev" "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 "Eldev" file))
(eask-debug "✗ Invalid Eldev filename, the file should start with `Eldev`"))
(t
(with-current-buffer (find-file new-filename)
(erase-buffer)
(goto-char (point-min))

(let* ((project-name (file-name-nondirectory (directory-file-name default-directory)))
(package-name (eask-read-string (format "\npackage name: (%s) " project-name) nil nil project-name))
(version (eask-read-string "version: (1.0.0) " nil nil "1.0.0"))
(description (eask-read-string "description: "))
(guess-entry-point (eask-guess-entry-point project-name))
(entry-point (eask-read-string (format "entry point: (%s) " guess-entry-point)
nil nil guess-entry-point))
(emacs-version (eask-read-string "emacs version: (26.1) " nil nil "26.1"))
(website (eask-read-string "website: "))
(keywords (eask-read-string "keywords: "))
(keywords (split-string keywords "[, ]"))
(keywords (string-join keywords "\" \""))
(content (format
"(package \"%s\"
\"%s\"
\"%s\")
(website-url \"%s\")
(keywords \"%s\")
(package-file \"%s\")
(script \"test\" \"echo \\\"Error: no test specified\\\" && exit 1\")
"
package-name version description website keywords
entry-point)))
(insert content)

(when-let* ((names (mapcar #'car package-archives))
(sources (mapcar #'eask--eldev-map-elpa names)))
(insert "\n")
(dolist (source sources)
(insert "(source '" (eask-2str source) ")\n"))))
(save-buffer))
(setq converted t))))
(if converted "done ✓" "skipped ✗"))
converted))

(eask-start
;; Preparation
(eask-with-archives "melpa"
(eask-package-install 'eldev))

;; Start Converting
(require 'eldev)
(let* ((patterns (eask-args))
(files (if patterns
(eask-expand-file-specs patterns)
(directory-files default-directory t "Eldev")))
(files (cl-remove-if-not (lambda (file)
(string= "Eldev" (file-name-nondirectory file)))
files))
(converted 0))
(cond
;; Files found, do the action!
(files
(eldev--set-up) ; XXX: Load once!
(dolist (file files)
(when (eask--convert-eldev file)
(cl-incf converted)))
(eask-msg "")
(eask-info "(Total of %s Eldev-file%s converted)" converted
(eask--sinr converted "" "s")))
;; Pattern defined, but no file found!
(patterns
(eask-info "(No files match wildcard: %s)"
(mapconcat #'identity patterns " ")))
;; Default, print help!
(t
(eask-info "(No Eldev-files have been converted to Eask)")
(eask-help "init/eldev")))))

;;; init/eldev.el ends here

0 comments on commit 0faeca4

Please sign in to comment.