From 21724467e0a5d55d7a799dac1031b52c022725b1 Mon Sep 17 00:00:00 2001 From: Jen-Chieh Shen Date: Mon, 13 Nov 2023 00:57:13 -0800 Subject: [PATCH] feat: Add `bump` command (#204) * feat: Add bump command * changelog * add test and docs * rm en translation * docs * fix doc trans * improve string sexp * rm msg --- CHANGELOG.md | 1 + cmds/core/bump.js | 32 +++++ docs/content/en/Development-API/_index.md | 14 ++- .../Getting-Started/Commands-and-options.md | 12 ++ docs/content/zh-TW/Development-API/_index.md | 14 ++- .../Getting-Started/Commands-and-options.md | 14 ++- lisp/_prepare.el | 39 ++++--- lisp/core/bump.el | 110 ++++++++++++++++++ lisp/help/core/bump | 8 ++ test/commands/local/run.sh | 1 + 10 files changed, 217 insertions(+), 28 deletions(-) create mode 100644 cmds/core/bump.js create mode 100644 lisp/core/bump.el create mode 100644 lisp/help/core/bump diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ceb6106..ca6b7455 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how * Merge the two commands `run` and `command` (#196) * Add `melpazoid` command (#202) * Add `source` command and its subcommands (#203) +* Add `bump` command (#204) ## 0.8.x > Released Mar 08, 2023 diff --git a/cmds/core/bump.js b/cmds/core/bump.js new file mode 100644 index 00000000..e75afda4 --- /dev/null +++ b/cmds/core/bump.js @@ -0,0 +1,32 @@ +/** + * Copyright (C) 2023 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 = ['bump [levels..]']; +exports.desc = UTIL.hide_cmd('Bump version for your project'); +exports.builder = yargs => yargs + .positional( + '[levels..]', { + description: "version level to bump; accept `major', `minor' or `patch'", + type: 'array', + }); + +exports.handler = async (argv) => { + await UTIL.e_call(argv, 'core/bump' + , argv.levels); +}; diff --git a/docs/content/en/Development-API/_index.md b/docs/content/en/Development-API/_index.md index 1acd6b1c..e630cf7f 100644 --- a/docs/content/en/Development-API/_index.md +++ b/docs/content/en/Development-API/_index.md @@ -834,10 +834,6 @@ This will kill Emacs process. # 🚩 File -## πŸ” Function: eask-guess-package-name () - -Return the possible package name. - ## πŸ” Function: eask-package-files () Return a list of package files. @@ -912,3 +908,13 @@ Print help manual located under `lisp/help/` directory. {{< hint info >}} πŸ’‘ This is used when a command fails, and would like to give users some tips! {{< /hint >}} + +# 🚩 Utilities + +## πŸ” Function: eask-guess-package-name () + +Return the possible package name. + +## πŸ” Function: eask-guess-entry-point () + +Return the possible package's entry point. diff --git a/docs/content/en/Getting-Started/Commands-and-options.md b/docs/content/en/Getting-Started/Commands-and-options.md index ef165edf..48b25455 100644 --- a/docs/content/en/Getting-Started/Commands-and-options.md +++ b/docs/content/en/Getting-Started/Commands-and-options.md @@ -255,6 +255,18 @@ List available keywords that can be used in the header section. $ eask [GLOBAL-OPTIONS] keywords ``` +## πŸ” eask bump + +Bump version for your project and/or Eask-file. + +```sh +$ eask [GLOBAL-OPTIONS] bump [LEVELS..] +``` + +{{< hint info >}} +πŸ’‘ Argument **[LEVELS..]** accepts **major**, **minor** and/or **patch**! +{{< /hint >}} + ## πŸ” eask cat View filename(s). diff --git a/docs/content/zh-TW/Development-API/_index.md b/docs/content/zh-TW/Development-API/_index.md index e9d734d0..0fee88da 100644 --- a/docs/content/zh-TW/Development-API/_index.md +++ b/docs/content/zh-TW/Development-API/_index.md @@ -824,10 +824,6 @@ This will kill Emacs process. # 🚩 ζ–‡δ»Ά -## πŸ” 函式: eask-guess-package-name () - -θΏ”ε›žε―θƒ½ηš„εŒ…εη¨±γ€‚ - ## πŸ” 函式: eask-package-files () θΏ”ε›žεŒ…ζ–‡δ»Άεˆ—θ‘¨γ€‚ @@ -902,3 +898,13 @@ This will kill Emacs process. {{< hint info >}} πŸ’‘ ι€™ζ˜―εœ¨ε‘½δ»€ε€±ζ•—ζ™‚δ½Ώη”¨ηš„οΌŒζƒ³η΅¦η”¨ζˆΆδΈ€δΊ›ζη€ΊοΌ {{< /hint >}} + +# 🚩 實用ε·₯ε…· + +## πŸ” 函式: eask-guess-package-name () + +θΏ”ε›žε―θƒ½ηš„εŒ…εη¨±γ€‚ + +## πŸ” Function: eask-guess-entry-point () + +θΏ”ε›žε―θƒ½ηš„εŒ…ηš„ε…₯ε£ι»žγ€‚ 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 515f57a8..0347cedf 100644 --- a/docs/content/zh-TW/Getting-Started/Commands-and-options.md +++ b/docs/content/zh-TW/Getting-Started/Commands-and-options.md @@ -252,6 +252,18 @@ $ eask [GLOBAL-OPTIONS] recipe [FILES..] $ eask [GLOBAL-OPTIONS] keywords ``` +## πŸ” eask bump + +η‚Ίδ½ ηš„ε°ˆζ‘ˆζˆ– Eask-file ιžε’žη‰ˆζœ¬θ™Ÿγ€‚ + +```sh +$ eask [GLOBAL-OPTIONS] bump [LEVELS..] +``` + +{{< hint info >}} +πŸ’‘ 參數 **[LEVELS..]** ζŽ₯受 **major**、**minor** ε’Œ/ζˆ– **patch**! +{{< /hint >}} + ## πŸ” eask cat ζŸ₯ηœ‹ζ–‡δ»Άεγ€‚ @@ -818,7 +830,7 @@ $ eask [GLOBAL-OPTIONS] upgrade-eask $ eask [GLOBAL-OPTIONS] locate ``` -# 🚩 Checker +# 🚩 ζͺ’ζŸ₯器 ζͺ’ζŸ₯ζ‚¨ηš„ Eask ζ–‡δ»Άηš„ε‘½δ»€γ€‚ diff --git a/lisp/_prepare.el b/lisp/_prepare.el index 3807a3e1..e1892b3d 100644 --- a/lisp/_prepare.el +++ b/lisp/_prepare.el @@ -139,7 +139,7 @@ will return `lint/checkdoc' with a dash between two subcommands." "Return t if the command that can be run without Eask-file existence." (member (eask-command) '("init/cask" "init/eldev" "init/keg" "init/source" - "cat" "keywords" + "bump" "cat" "keywords" "generate/ignore" "generate/license" "test/melpazoid"))) @@ -199,6 +199,14 @@ Argument BODY are forms for execution." "Convert OBJ to string." (format "%s" obj)) +(defun eask-2url (url) + "Convert secure/insecure URL." + (if (and url + (gnutls-available-p) + (eask-network-insecure-p)) + (eask-s-replace "https://" "http://" url) + url)) + (defun eask-listify (obj) "Turn OBJ to list." (if (listp obj) obj (list obj))) @@ -242,11 +250,18 @@ The function `directory-empty-p' only exists 28.1 or above; copied it." ;; 27.2 or lower! (null (directory-files dir nil directory-files-no-dot-files-regexp t))))) -(defun eask-guess-entry-point (project-name) +(defun eask-guess-package-name () + "Return the possible package name." + (or (eask-package-name) + (ignore-errors (file-name-nondirectory + (file-name-sans-extension eask-package-file))))) + +(defun eask-guess-entry-point (&optional project-name) "Return the guess entry point by its PROJECT-NAME." - (if (string-suffix-p ".el" project-name) - project-name - (format "%s.el" project-name))) + (let ((project-name (or project-name (eask-guess-package-name)))) + (if (string-suffix-p ".el" project-name) + project-name + (format "%s.el" project-name)))) (defun eask-read-string (prompt &optional initial-input @@ -1118,14 +1133,6 @@ This uses function `locate-dominating-file' to look up directory tree." (nongnu-devel . "https://elpa.nongnu.org/nongnu-devel/")) "Mapping of source name and url.") -(defun eask-2url (url) - "Convert secure/insecure URL." - (if (and url - (gnutls-available-p) - (eask-network-insecure-p)) - (eask-s-replace "https://" "http://" url) - url)) - (defun eask-source-url (name &optional location) "Get the source url by it's NAME and LOCATION." (setq location (or location (cdr (assq (intern (eask-2str name)) eask-source-mapping))) @@ -1643,12 +1650,6 @@ Arguments FNC and ARGS are used for advice `:around'." ;; ;;; File -(defun eask-guess-package-name () - "Return the possible package name." - (or (eask-package-name) - (ignore-errors (file-name-nondirectory - (file-name-sans-extension eask-package-file))))) - (defun eask-files-spec () "Return files spec." (or eask-files package-build-default-files-spec)) diff --git a/lisp/core/bump.el b/lisp/core/bump.el new file mode 100644 index 00000000..96e1b070 --- /dev/null +++ b/lisp/core/bump.el @@ -0,0 +1,110 @@ +;;; core/bump.el --- Bump version for your project -*- lexical-binding: t; -*- + +;;; Commentary: +;; +;; Command use to bump version, +;; +;; $ eask bump +;; +;; +;; Positionals: +;; +;; [levels..] version level to bump; accept `major', `minor' or `patch' +;; + +;;; 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-bump-version--version (version index) + "Bump VERSION with INDEX." + (let ((lst (if (stringp version) (version-to-list version) version))) + (setf (nth index lst) (cl-incf (nth index lst))) + (mapconcat #'eask-2str lst version-separator))) + +(defun eask-bump-version--major-version (version) + "Bump VERSION major level." + (eask-bump-version--version version 0)) + +(defun eask-bump-version--minor-version (version) + "Bump VERSION minor level." + (eask-bump-version--version version 1)) + +(defun eask-bump-version--patch-level (version) + "Bump VERSION patch level." + (eask-bump-version--version version 2)) + +(eask-start + (let ((package-file (or eask-package-file + (eask-guess-entry-point))) + (levels (eask-args)) + (desc) + (version) + (tasks (if eask-file 2 1))) + (unless eask-package-file + (eask-info "πŸ’‘ Detect package file `%s'..." package-file)) + (cond + ((and (not (member "major" levels)) + (not (member "minor" levels)) + (not (member "patch" levels))) + (eask-help "core/bump")) + ((not (file-exists-p package-file)) + (eask-info "(No package file found)")) + (t + (with-current-buffer (find-file package-file) + (setq desc (package-buffer-info))) + (setq version (package-desc-version desc)) + (when (member "major" levels) + (setq version (eask-bump-version--major-version version))) + (when (member "minor" levels) + (setq version (eask-bump-version--minor-version version))) + (when (member "patch" levels) + (setq version (eask-bump-version--patch-level version))) + (eask-msg "New version: %s" version) + (let (success) + (eask-with-progress + (format " - [1/%s] Bump version for package-file (%s)... " + tasks + (eask-root-del package-file)) + (with-current-buffer (find-file package-file) + (goto-char (point-min)) + (cond ((re-search-forward ";;[ \t]*Version:[ \t]*" nil t) + (delete-region (point) (line-end-position)) + (insert version) + (setq success t) + (save-buffer)) + (t + (eask-error + "Failed to bump version to package file; invalid search string: %s" + package-file)))) + (if success "done βœ“" "skipped βœ—"))) + (when eask-file + (let (success) + (eask-with-progress + (format " - [1/%s] Bump version for Eask-file (%s)... " + tasks + (eask-root-del eask-file)) + (with-current-buffer (find-file eask-file) + (goto-char (point-min)) + (cond ((re-search-forward "(package[ \t\r\n\"]*" nil t) + (forward-char -1) + (forward-thing 'sexp) + (forward-thing 'sexp) + (forward-sexp -1) + (delete-region (1+ (point)) (save-excursion + (forward-thing 'sexp) + (1- (point)))) + (forward-char 1) + (insert version) + (setq success t) + (save-buffer)) + (t + (eask-error + "Failed to bump version to Eask-file; invalid search string: %s" + eask-file)))) + (if success "done βœ“" "skipped βœ—")))))))) + +;;; core/bump.el ends here diff --git a/lisp/help/core/bump b/lisp/help/core/bump new file mode 100644 index 00000000..671402db --- /dev/null +++ b/lisp/help/core/bump @@ -0,0 +1,8 @@ + +πŸ’‘ You need to specify version level(s) in order to make this command work: + + $ eask bump major + +πŸ’‘ The `bump` command accepts multiple values: + + $ eask bump major diff --git a/test/commands/local/run.sh b/test/commands/local/run.sh index a253d2ee..7eb9e369 100644 --- a/test/commands/local/run.sh +++ b/test/commands/local/run.sh @@ -38,6 +38,7 @@ eask list --depth=0 eask cat package.json --insecure eask cat package.json --number --insecure eask concat +eask bump major minor patch # PATH environment eask path