Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add bump command #204

Merged
merged 8 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions cmds/core/bump.js
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

"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);
};
14 changes: 10 additions & 4 deletions docs/content/en/Development-API/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
12 changes: 12 additions & 0 deletions docs/content/en/Getting-Started/Commands-and-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
14 changes: 10 additions & 4 deletions docs/content/zh-TW/Development-API/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -824,10 +824,6 @@ This will kill Emacs process.

# 🚩 文件

## 🔍 函式: eask-guess-package-name ()

返回可能的包名稱。

## 🔍 函式: eask-package-files ()

返回包文件列表。
Expand Down Expand Up @@ -902,3 +898,13 @@ This will kill Emacs process.
{{< hint info >}}
💡 這是在命令失敗時使用的,想給用戶一些提示!
{{< /hint >}}

# 🚩 實用工具

## 🔍 函式: eask-guess-package-name ()

返回可能的包名稱。

## 🔍 Function: eask-guess-entry-point ()

返回可能的包的入口點。
14 changes: 13 additions & 1 deletion docs/content/zh-TW/Getting-Started/Commands-and-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

查看文件名。
Expand Down Expand Up @@ -818,7 +830,7 @@ $ eask [GLOBAL-OPTIONS] upgrade-eask
$ eask [GLOBAL-OPTIONS] locate
```

# 🚩 Checker
# 🚩 檢查器

檢查您的 Eask 文件的命令。

Expand Down
39 changes: 20 additions & 19 deletions lisp/_prepare.el
Original file line number Diff line number Diff line change
Expand Up @@ -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")))

Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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))
Expand Down
110 changes: 110 additions & 0 deletions lisp/core/bump.el
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions lisp/help/core/bump
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions test/commands/local/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading