Skip to content

Commit 2172446

Browse files
authored
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
1 parent bde0518 commit 2172446

File tree

10 files changed

+217
-28
lines changed

10 files changed

+217
-28
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
3737
* Merge the two commands `run` and `command` (#196)
3838
* Add `melpazoid` command (#202)
3939
* Add `source` command and its subcommands (#203)
40+
* Add `bump` command (#204)
4041

4142
## 0.8.x
4243
> Released Mar 08, 2023

cmds/core/bump.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Copyright (C) 2023 the Eask authors.
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 3, or (at your option)
7+
* any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
"use strict";
19+
20+
exports.command = ['bump [levels..]'];
21+
exports.desc = UTIL.hide_cmd('Bump version for your project');
22+
exports.builder = yargs => yargs
23+
.positional(
24+
'[levels..]', {
25+
description: "version level to bump; accept `major', `minor' or `patch'",
26+
type: 'array',
27+
});
28+
29+
exports.handler = async (argv) => {
30+
await UTIL.e_call(argv, 'core/bump'
31+
, argv.levels);
32+
};

docs/content/en/Development-API/_index.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -834,10 +834,6 @@ This will kill Emacs process.
834834

835835
# 🚩 File
836836

837-
## 🔍 Function: eask-guess-package-name ()
838-
839-
Return the possible package name.
840-
841837
## 🔍 Function: eask-package-files ()
842838

843839
Return a list of package files.
@@ -912,3 +908,13 @@ Print help manual located under `lisp/help/` directory.
912908
{{< hint info >}}
913909
💡 This is used when a command fails, and would like to give users some tips!
914910
{{< /hint >}}
911+
912+
# 🚩 Utilities
913+
914+
## 🔍 Function: eask-guess-package-name ()
915+
916+
Return the possible package name.
917+
918+
## 🔍 Function: eask-guess-entry-point ()
919+
920+
Return the possible package's entry point.

docs/content/en/Getting-Started/Commands-and-options.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,18 @@ List available keywords that can be used in the header section.
255255
$ eask [GLOBAL-OPTIONS] keywords
256256
```
257257

258+
## 🔍 eask bump
259+
260+
Bump version for your project and/or Eask-file.
261+
262+
```sh
263+
$ eask [GLOBAL-OPTIONS] bump [LEVELS..]
264+
```
265+
266+
{{< hint info >}}
267+
💡 Argument **[LEVELS..]** accepts **major**, **minor** and/or **patch**!
268+
{{< /hint >}}
269+
258270
## 🔍 eask cat
259271

260272
View filename(s).

docs/content/zh-TW/Development-API/_index.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -824,10 +824,6 @@ This will kill Emacs process.
824824

825825
# 🚩 文件
826826

827-
## 🔍 函式: eask-guess-package-name ()
828-
829-
返回可能的包名稱。
830-
831827
## 🔍 函式: eask-package-files ()
832828

833829
返回包文件列表。
@@ -902,3 +898,13 @@ This will kill Emacs process.
902898
{{< hint info >}}
903899
💡 這是在命令失敗時使用的,想給用戶一些提示!
904900
{{< /hint >}}
901+
902+
# 🚩 實用工具
903+
904+
## 🔍 函式: eask-guess-package-name ()
905+
906+
返回可能的包名稱。
907+
908+
## 🔍 Function: eask-guess-entry-point ()
909+
910+
返回可能的包的入口點。

docs/content/zh-TW/Getting-Started/Commands-and-options.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,18 @@ $ eask [GLOBAL-OPTIONS] recipe [FILES..]
252252
$ eask [GLOBAL-OPTIONS] keywords
253253
```
254254

255+
## 🔍 eask bump
256+
257+
為你的專案或 Eask-file 遞增版本號。
258+
259+
```sh
260+
$ eask [GLOBAL-OPTIONS] bump [LEVELS..]
261+
```
262+
263+
{{< hint info >}}
264+
💡 參數 **[LEVELS..]** 接受 **major****minor** 和/或 **patch**
265+
{{< /hint >}}
266+
255267
## 🔍 eask cat
256268

257269
查看文件名。
@@ -818,7 +830,7 @@ $ eask [GLOBAL-OPTIONS] upgrade-eask
818830
$ eask [GLOBAL-OPTIONS] locate
819831
```
820832

821-
# 🚩 Checker
833+
# 🚩 檢查器
822834

823835
檢查您的 Eask 文件的命令。
824836

lisp/_prepare.el

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ will return `lint/checkdoc' with a dash between two subcommands."
139139
"Return t if the command that can be run without Eask-file existence."
140140
(member (eask-command) '("init/cask" "init/eldev" "init/keg"
141141
"init/source"
142-
"cat" "keywords"
142+
"bump" "cat" "keywords"
143143
"generate/ignore" "generate/license"
144144
"test/melpazoid")))
145145

@@ -199,6 +199,14 @@ Argument BODY are forms for execution."
199199
"Convert OBJ to string."
200200
(format "%s" obj))
201201

202+
(defun eask-2url (url)
203+
"Convert secure/insecure URL."
204+
(if (and url
205+
(gnutls-available-p)
206+
(eask-network-insecure-p))
207+
(eask-s-replace "https://" "http://" url)
208+
url))
209+
202210
(defun eask-listify (obj)
203211
"Turn OBJ to list."
204212
(if (listp obj) obj (list obj)))
@@ -242,11 +250,18 @@ The function `directory-empty-p' only exists 28.1 or above; copied it."
242250
;; 27.2 or lower!
243251
(null (directory-files dir nil directory-files-no-dot-files-regexp t)))))
244252

245-
(defun eask-guess-entry-point (project-name)
253+
(defun eask-guess-package-name ()
254+
"Return the possible package name."
255+
(or (eask-package-name)
256+
(ignore-errors (file-name-nondirectory
257+
(file-name-sans-extension eask-package-file)))))
258+
259+
(defun eask-guess-entry-point (&optional project-name)
246260
"Return the guess entry point by its PROJECT-NAME."
247-
(if (string-suffix-p ".el" project-name)
248-
project-name
249-
(format "%s.el" project-name)))
261+
(let ((project-name (or project-name (eask-guess-package-name))))
262+
(if (string-suffix-p ".el" project-name)
263+
project-name
264+
(format "%s.el" project-name))))
250265

251266
(defun eask-read-string (prompt &optional
252267
initial-input
@@ -1118,14 +1133,6 @@ This uses function `locate-dominating-file' to look up directory tree."
11181133
(nongnu-devel . "https://elpa.nongnu.org/nongnu-devel/"))
11191134
"Mapping of source name and url.")
11201135

1121-
(defun eask-2url (url)
1122-
"Convert secure/insecure URL."
1123-
(if (and url
1124-
(gnutls-available-p)
1125-
(eask-network-insecure-p))
1126-
(eask-s-replace "https://" "http://" url)
1127-
url))
1128-
11291136
(defun eask-source-url (name &optional location)
11301137
"Get the source url by it's NAME and LOCATION."
11311138
(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'."
16431650
;;
16441651
;;; File
16451652

1646-
(defun eask-guess-package-name ()
1647-
"Return the possible package name."
1648-
(or (eask-package-name)
1649-
(ignore-errors (file-name-nondirectory
1650-
(file-name-sans-extension eask-package-file)))))
1651-
16521653
(defun eask-files-spec ()
16531654
"Return files spec."
16541655
(or eask-files package-build-default-files-spec))

lisp/core/bump.el

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
;;; core/bump.el --- Bump version for your project -*- lexical-binding: t; -*-
2+
3+
;;; Commentary:
4+
;;
5+
;; Command use to bump version,
6+
;;
7+
;; $ eask bump
8+
;;
9+
;;
10+
;; Positionals:
11+
;;
12+
;; [levels..] version level to bump; accept `major', `minor' or `patch'
13+
;;
14+
15+
;;; Code:
16+
17+
(let ((dir (file-name-directory (nth 1 (member "-scriptload" command-line-args)))))
18+
(load (expand-file-name "_prepare.el"
19+
(locate-dominating-file dir "_prepare.el"))
20+
nil t))
21+
22+
(defun eask-bump-version--version (version index)
23+
"Bump VERSION with INDEX."
24+
(let ((lst (if (stringp version) (version-to-list version) version)))
25+
(setf (nth index lst) (cl-incf (nth index lst)))
26+
(mapconcat #'eask-2str lst version-separator)))
27+
28+
(defun eask-bump-version--major-version (version)
29+
"Bump VERSION major level."
30+
(eask-bump-version--version version 0))
31+
32+
(defun eask-bump-version--minor-version (version)
33+
"Bump VERSION minor level."
34+
(eask-bump-version--version version 1))
35+
36+
(defun eask-bump-version--patch-level (version)
37+
"Bump VERSION patch level."
38+
(eask-bump-version--version version 2))
39+
40+
(eask-start
41+
(let ((package-file (or eask-package-file
42+
(eask-guess-entry-point)))
43+
(levels (eask-args))
44+
(desc)
45+
(version)
46+
(tasks (if eask-file 2 1)))
47+
(unless eask-package-file
48+
(eask-info "💡 Detect package file `%s'..." package-file))
49+
(cond
50+
((and (not (member "major" levels))
51+
(not (member "minor" levels))
52+
(not (member "patch" levels)))
53+
(eask-help "core/bump"))
54+
((not (file-exists-p package-file))
55+
(eask-info "(No package file found)"))
56+
(t
57+
(with-current-buffer (find-file package-file)
58+
(setq desc (package-buffer-info)))
59+
(setq version (package-desc-version desc))
60+
(when (member "major" levels)
61+
(setq version (eask-bump-version--major-version version)))
62+
(when (member "minor" levels)
63+
(setq version (eask-bump-version--minor-version version)))
64+
(when (member "patch" levels)
65+
(setq version (eask-bump-version--patch-level version)))
66+
(eask-msg "New version: %s" version)
67+
(let (success)
68+
(eask-with-progress
69+
(format " - [1/%s] Bump version for package-file (%s)... "
70+
tasks
71+
(eask-root-del package-file))
72+
(with-current-buffer (find-file package-file)
73+
(goto-char (point-min))
74+
(cond ((re-search-forward ";;[ \t]*Version:[ \t]*" nil t)
75+
(delete-region (point) (line-end-position))
76+
(insert version)
77+
(setq success t)
78+
(save-buffer))
79+
(t
80+
(eask-error
81+
"Failed to bump version to package file; invalid search string: %s"
82+
package-file))))
83+
(if success "done ✓" "skipped ✗")))
84+
(when eask-file
85+
(let (success)
86+
(eask-with-progress
87+
(format " - [1/%s] Bump version for Eask-file (%s)... "
88+
tasks
89+
(eask-root-del eask-file))
90+
(with-current-buffer (find-file eask-file)
91+
(goto-char (point-min))
92+
(cond ((re-search-forward "(package[ \t\r\n\"]*" nil t)
93+
(forward-char -1)
94+
(forward-thing 'sexp)
95+
(forward-thing 'sexp)
96+
(forward-sexp -1)
97+
(delete-region (1+ (point)) (save-excursion
98+
(forward-thing 'sexp)
99+
(1- (point))))
100+
(forward-char 1)
101+
(insert version)
102+
(setq success t)
103+
(save-buffer))
104+
(t
105+
(eask-error
106+
"Failed to bump version to Eask-file; invalid search string: %s"
107+
eask-file))))
108+
(if success "done ✓" "skipped ✗"))))))))
109+
110+
;;; core/bump.el ends here

lisp/help/core/bump

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
💡 You need to specify version level(s) in order to make this command work:
3+
4+
$ eask bump major
5+
6+
💡 The `bump` command accepts multiple values:
7+
8+
$ eask bump major

test/commands/local/run.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ eask list --depth=0
3838
eask cat package.json --insecure
3939
eask cat package.json --number --insecure
4040
eask concat
41+
eask bump major minor patch
4142

4243
# PATH environment
4344
eask path

0 commit comments

Comments
 (0)