From 0faeca4b344ba1f76631d8e64a6e03687611e098 Mon Sep 17 00:00:00 2001 From: Jen-Chieh Shen Date: Fri, 13 Oct 2023 06:38:31 -0700 Subject: [PATCH] feat(init): Add init from Eldev (#193) * feat(init): Add init from Eldev * rm msg --- CHANGELOG.md | 1 + cmds/core/init.js | 1 + .../Getting-Started/Commands-and-options.md | 17 ++- .../Getting-Started/Commands-and-options.md | 15 ++- lisp/_prepare.el | 2 +- lisp/help/init/eldev | 6 + lisp/init/eldev.el | 112 ++++++++++++++++++ 7 files changed, 144 insertions(+), 10 deletions(-) create mode 100644 lisp/help/init/eldev create mode 100644 lisp/init/eldev.el diff --git a/CHANGELOG.md b/CHANGELOG.md index b853c0a4..40b79391 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/cmds/core/init.js b/cmds/core/init.js index 76d4100e..d0124c5a 100644 --- a/cmds/core/init.js +++ b/cmds/core/init.js @@ -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 diff --git a/docs/content/en/Getting-Started/Commands-and-options.md b/docs/content/en/Getting-Started/Commands-and-options.md index d855670e..6906926f 100644 --- a/docs/content/en/Getting-Started/Commands-and-options.md +++ b/docs/content/en/Getting-Started/Commands-and-options.md @@ -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 >}} @@ -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 diff --git a/docs/content/zh-TW/Getting-Started/Commands-and-options.md b/docs/content/zh-TW/Getting-Started/Commands-and-options.md index 8d557fa6..fae437be 100644 --- a/docs/content/zh-TW/Getting-Started/Commands-and-options.md +++ b/docs/content/zh-TW/Getting-Started/Commands-and-options.md @@ -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 >}} @@ -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 diff --git a/lisp/_prepare.el b/lisp/_prepare.el index 056f49a3..a57f8477 100644 --- a/lisp/_prepare.el +++ b/lisp/_prepare.el @@ -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"))) diff --git a/lisp/help/init/eldev b/lisp/help/init/eldev new file mode 100644 index 00000000..640b073f --- /dev/null +++ b/lisp/help/init/eldev @@ -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 diff --git a/lisp/init/eldev.el b/lisp/init/eldev.el new file mode 100644 index 00000000..3a8deabb --- /dev/null +++ b/lisp/init/eldev.el @@ -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