From e1eb0b5856c3aa16b422da9b1b28eb3b6281d94d Mon Sep 17 00:00:00 2001 From: JenChieh Date: Thu, 6 Jun 2024 20:32:47 -0700 Subject: [PATCH] feat(cmds): Add recompile command --- cmds/core/compile.js | 2 +- cmds/core/recompile.js | 40 +++++++++++++++++++ .../Getting-Started/Basic-Usage/_index.en.md | 5 ++- .../Basic-Usage/_index.zh-tw.md | 5 ++- .../Commands-and-options/_index.en.md | 15 ++++++- .../Commands-and-options/_index.zh-tw.md | 14 ++++++- lisp/core/compile.el | 4 +- lisp/core/recompile.el | 30 ++++++++++++++ test/commands/local/run.sh | 1 + 9 files changed, 107 insertions(+), 9 deletions(-) create mode 100644 cmds/core/recompile.js create mode 100644 lisp/core/recompile.el diff --git a/cmds/core/compile.js b/cmds/core/compile.js index 808696bf..c28abe37 100644 --- a/cmds/core/compile.js +++ b/cmds/core/compile.js @@ -18,7 +18,7 @@ "use strict"; exports.command = ['compile [names..]']; -exports.desc = 'Byte compile all Emacs Lisp files in the package'; +exports.desc = "Byte-compile `.el' files"; exports.builder = yargs => yargs .positional( '[names..]', { diff --git a/cmds/core/recompile.js b/cmds/core/recompile.js new file mode 100644 index 00000000..98b30311 --- /dev/null +++ b/cmds/core/recompile.js @@ -0,0 +1,40 @@ +/** + * Copyright (C) 2022-2024 the Eask authors. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +"use strict"; + +exports.command = ['recompile [names..]']; +exports.desc = "Byte-recompile `.el' files"; +exports.builder = yargs => yargs + .positional( + '[names..]', { + description: 'specify files to byte-compile', + type: 'array', + }) + .options({ + 'clean': { + description: 'clean byte-recompile files individually', + type: 'boolean', + group: TITLE_CMD_OPTION, + }, + }); + +exports.handler = async (argv) => { + await UTIL.e_call(argv, 'core/recompile' + , argv.names + , UTIL.def_flag(argv.clean, '--clean')); +}; diff --git a/docs/content/Getting-Started/Basic-Usage/_index.en.md b/docs/content/Getting-Started/Basic-Usage/_index.en.md index fcec8cbc..6ec1bfbc 100644 --- a/docs/content/Getting-Started/Basic-Usage/_index.en.md +++ b/docs/content/Getting-Started/Basic-Usage/_index.en.md @@ -35,10 +35,10 @@ Commands: analyze [files..] Run Eask checker archives List out all package archives [aliases: sources] clean Delete various files produced during building - compile [names..] Byte compile all Emacs Lisp files in the package + compile [names..] Byte-compile `.el' files create Create a new elisp project docker [args..] Launch specified Emacs version in a Docker container - docs Build documentation [aliases: doc] + docs [names..] Build documentation [aliases: doc] emacs [args..] Execute emacs with the appropriate environment eval [form] Evaluate lisp form with a proper PATH path [patterns..] Print the PATH (exec-path) from workspace [aliases: exec-path] @@ -60,6 +60,7 @@ Commands: package-directory Print path to package directory package [destination] Build a package artifact, and put it into the given destination [aliases: pack] recipe Suggest a recipe format + recompile [names..] Byte-recompile `.el' files refresh Download package archives reinstall [names..] Reinstall packages run Run custom tasks diff --git a/docs/content/Getting-Started/Basic-Usage/_index.zh-tw.md b/docs/content/Getting-Started/Basic-Usage/_index.zh-tw.md index 71e1de71..ac7592a4 100644 --- a/docs/content/Getting-Started/Basic-Usage/_index.zh-tw.md +++ b/docs/content/Getting-Started/Basic-Usage/_index.zh-tw.md @@ -32,10 +32,10 @@ Commands: analyze [files..] Run Eask checker archives List out all package archives [aliases: sources] clean Delete various files produced during building - compile [names..] Byte compile all Emacs Lisp files in the package + compile [names..] Byte-compile `.el' files create Create a new elisp project docker [args..] Launch specified Emacs version in a Docker container - docs Build documentation [aliases: doc] + docs [names..] Build documentation [aliases: doc] emacs [args..] Execute emacs with the appropriate environment eval [form] Evaluate lisp form with a proper PATH path [patterns..] Print the PATH (exec-path) from workspace [aliases: exec-path] @@ -57,6 +57,7 @@ Commands: package-directory Print path to package directory package [destination] Build a package artifact, and put it into the given destination [aliases: pack] recipe Suggest a recipe format + recompile [names..] Byte-recompile `.el' files refresh Download package archives reinstall [names..] Reinstall packages run Run custom tasks diff --git a/docs/content/Getting-Started/Commands-and-options/_index.en.md b/docs/content/Getting-Started/Commands-and-options/_index.en.md index 941ee1b1..1a7ae0d2 100644 --- a/docs/content/Getting-Started/Commands-and-options/_index.en.md +++ b/docs/content/Getting-Started/Commands-and-options/_index.en.md @@ -183,7 +183,7 @@ by default. ## 🔍 eask compile -Byte-compile files. +Byte-compile `.el` files. ```sh $ eask compile [FILES..] @@ -201,6 +201,19 @@ Or compile files that are already specified in your `Eask`-file. $ eask compile ``` +## 🔍 eask recompile + +Byte-recompile `.el` files. + +```sh +$ eask recompile [FILES..] +``` + +{{< hint info >}} +💡 Similar to `eask compile`, but it will also remove old `.elc` files before +compiling. +{{< /hint >}} + ## 🔍 eask package-directory Print path to package directory, where all dependencies are installed. diff --git a/docs/content/Getting-Started/Commands-and-options/_index.zh-tw.md b/docs/content/Getting-Started/Commands-and-options/_index.zh-tw.md index ff1fae8c..9bae50ae 100644 --- a/docs/content/Getting-Started/Commands-and-options/_index.zh-tw.md +++ b/docs/content/Getting-Started/Commands-and-options/_index.zh-tw.md @@ -180,7 +180,7 @@ $ eask package [DESTINATION] ## 🔍 eask compile -字節編譯文件。 +字節編譯 `.el` 文件。 ```sh $ eask compile [FILES..] @@ -198,6 +198,18 @@ $ eask compile file-1.el file-2.el $ eask compile ``` +## 🔍 eask recompile + +重新字節編譯 `.el` 文件。 + +```sh +$ eask recompile [FILES..] +``` + +{{< hint info >}} +💡 與 `eask compile` 類似,但它在編譯前會刪除舊的 `.elc` 檔案。 +{{< /hint >}} + ## 🔍 eask package-directory 打印包目錄的路徑,其中安裝了所有依賴項。 diff --git a/lisp/core/compile.el b/lisp/core/compile.el index 0be2c263..cfa9a7b2 100644 --- a/lisp/core/compile.el +++ b/lisp/core/compile.el @@ -1,8 +1,8 @@ -;;; core/compile.el --- Byte compile all Emacs Lisp files in the package -*- lexical-binding: t; -*- +;;; core/compile.el --- Byte-compile `.el' files -*- lexical-binding: t; -*- ;;; Commentary: ;; -;; Byte compile all Emacs Lisp files in the package +;; Byte-compile `.el' files, ;; ;; $ eask compile [names..] ;; diff --git a/lisp/core/recompile.el b/lisp/core/recompile.el new file mode 100644 index 00000000..f2dc4a24 --- /dev/null +++ b/lisp/core/recompile.el @@ -0,0 +1,30 @@ +;;; core/recompile.el --- Byte-recompile `.el' files -*- lexical-binding: t; -*- + +;;; Commentary: +;; +;; Byte-recompile `.el' files, +;; +;; $ eask recompile [names..] +;; +;; +;; Positionals: +;; +;; [names..] specify files to byte-recompile +;; + +;;; 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)) + +;; +;;; Core + +(eask-start + (eask-call "clean/elc") + (eask-println "") + (eask-call "core/compile")) + +;;; core/recompile.el ends here diff --git a/test/commands/local/run.sh b/test/commands/local/run.sh index 86c21229..47db7bd6 100644 --- a/test/commands/local/run.sh +++ b/test/commands/local/run.sh @@ -59,6 +59,7 @@ eask package # Development eask compile eask compile --clean +eask recompile eask recipe eask keywords eask run script