Skip to content
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 @@ -31,6 +31,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
* fix(vcpkg): Use workaround for `MODULE_NOT_FOUND` error (#187)
* Add docker command (#188)
* Enter docker directly when no arguments (#191)
* Add command to generate recipe (#192)

## 0.8.x
> Released Mar 08, 2023
Expand Down
3 changes: 2 additions & 1 deletion cmds/clean/dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ exports.command = ['dist [destination]', 'distribution [destination]'];
exports.desc = 'Delete dist subdirectory';
exports.builder = yargs => yargs
.positional(
'[destination]', {
'destination', {
description: 'destination path/folder to clean up',
alias: 'dest',
type: 'string',
});

Expand Down
3 changes: 2 additions & 1 deletion cmds/core/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ exports.command = ['package [destination]'];
exports.desc = 'Build a package artifact, and put it into the given destination';
exports.builder = yargs => yargs
.positional(
'[destination]', {
'destination', {
description: 'destination path/folder',
alias: 'dest',
type: 'string',
});

Expand Down
44 changes: 44 additions & 0 deletions cmds/generate/recipe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright (C) 2023 Jen-Chieh Shen
*
* 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 GNU Emacs; see the file COPYING. If not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/

"use strict";

exports.command = ['recipe [destination]'];
exports.desc = 'Generate recipe file';
exports.builder = yargs => yargs
.positional(
'destination', {
description: 'destination path/folder',
alias: 'dest',
type: 'string',
})
.options({
'yes': {
description: 'assume the answer to all prompts is yes',
alias: 'y',
type: 'boolean',
group: TITLE_CMD_OPTION,
},
});

exports.handler = async (argv) => {
await UTIL.e_call(argv, 'generate/recipe'
, argv.dest
, UTIL.def_flag(argv.yes, '--yes'));
};
13 changes: 12 additions & 1 deletion docs/content/en/Getting-Started/Commands-and-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ Build the package artifact.
$ eask package [DESTINATION]
```

If [DESTINATION] is not specified, it will export to the `/dist` folder
If [DESTINATION] is not specified, it will generate to the `/dist` folder
by default.

## 🔍 eask compile
Expand Down Expand Up @@ -423,6 +423,17 @@ $ eask [GLOBAL-OPTIONS] generate pkg-file
[Multi-file Packages (elisp)](https://www.gnu.org/software/emacs/manual/html_node/elisp/Multi_002dfile-Packages.html#Multi_002dfile-Packages)
for details.

## 🔍 eask generate recipe

Generate recipe file.

```sh
$ eask [GLOBAL-OPTIONS] generate recipe [DESTINATION]
```

If [DESTINATION] is not specified, it will generate to the `/recipes` folder
by default.

## 🔍 eask generate license

Generate LICENSE file.
Expand Down
14 changes: 12 additions & 2 deletions docs/content/zh-TW/Getting-Started/Commands-and-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,16 @@ $ eask [GLOBAL-OPTIONS] generate pkg-file
`project` 是在 `Eask` 文件中聲明的項目名稱。 有關詳細信息,請參閱
[多文件包 (elisp)](https://www.gnu.org/software/emacs/manual/html_node/elisp/Multi_002dfile-Packages.html#Multi_002dfile-Packages)。

## 🔍 eask generate recipe

生成 recipe 文件。

```sh
$ eask [GLOBAL-OPTIONS] generate recipe [DESTINATION]
```

如果未指定 [DESTINATION],則默認導出到 `/recipes` 文件夾。

## 🔍 eask generate license

生成 LICENSE 文件。
Expand Down Expand Up @@ -830,9 +840,9 @@ $ eask -f [COMMAND]

## 🔍 --strict

Trigger error instead of warnings.
觸發錯誤代替警告。

For instance, in **eask compile**:
例如,在 **eask compile** 中:

```elisp
(setq byte-compile-error-on-warn t)
Expand Down
20 changes: 16 additions & 4 deletions lisp/_prepare.el
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,9 @@ full detials."
(defun eask-number-p ()
"Non-nil when flag is on (`-n', `--number')."
(eask--flag "--number"))
(defun eask-yes-p ()
"Non-nil when flag is on (`--yes')."
(eask--flag "--yes"))

;;; String (with arguments)
(defun eask-output ()
Expand Down Expand Up @@ -806,7 +809,8 @@ other scripts internally. See function `eask-call'.")
"--no-color"
"--clean"
"--json"
"--number"))
"--number"
"--yes"))
"List of boolean type options.")

(defconst eask--option-args
Expand Down Expand Up @@ -837,16 +841,19 @@ Simply remove `--eask' for each option, like `--eask--strict' to `--strict'."
(eask-s-replace "--eask" "" arg))
eask-argv))

(defun eask-args ()
"Get all arguments except options."
(defun eask-args (&optional index)
"Get all arguments except options

If the optional argument INDEX is non-nil, return the element."
(let ((argv (cl-remove-if (lambda (arg) (member arg eask--option-switches)) eask-argv))
(args) (skip-next))
(dolist (arg argv)
(if skip-next (setq skip-next nil)
(if (member arg eask--option-args)
(setq skip-next t)
(push arg args))))
(reverse args)))
(setq args (reverse args))
(if index (nth 0 args) args)))

(defmacro eask--batch-mode (&rest body)
"Execute forms BODY in batch-mode."
Expand Down Expand Up @@ -1811,6 +1818,11 @@ variable we use to test validation."
:type 'string
:group 'eask)

(defcustom eask-recipe-path "recipes"
"Name of default target directory for placing recipes."
:type 'string
:group 'eask)

;;
;;; Linter

Expand Down
2 changes: 1 addition & 1 deletion lisp/clean/dist.el
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
(- 3 deleted))))

(eask-start
(let* ((eask-dist-path (or (eask-argv 0) eask-dist-path))
(let* ((eask-dist-path (or (eask-args 0) eask-dist-path))
(eask-dist-path (expand-file-name eask-dist-path)))
(if (file-directory-p eask-dist-path)
(eask--clean-dist eask-dist-path)
Expand Down
2 changes: 1 addition & 1 deletion lisp/core/package.el
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Argument VERSION is a string represent the version number of this package."
(eask--packaged-file "el")))

(eask-start
(let* ((eask-dist-path (or (eask-argv 0) eask-dist-path))
(let* ((eask-dist-path (or (eask-args 0) eask-dist-path))
(eask-dist-path (expand-file-name eask-dist-path))
(packaged))
(ignore-errors (make-directory eask-dist-path t))
Expand Down
43 changes: 24 additions & 19 deletions lisp/core/recipe.el
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,34 @@
(locate-dominating-file dir "_prepare.el"))
nil t))

(defun eask--recipe-string ()
"Return the recipe format in string."
(when-let ((url (eask-package-desc-url)))
(let* ((fetcher (cond ((string-match-p "github.com" url) 'github)
((string-match-p "gitlab.com" url) 'gitlab)
(t 'git)))
(url-regex (if (eq fetcher 'github)
"http[s]://github.com/"
"http[s]://gitlab.com/"))
(repo (replace-regexp-in-string url-regex "" url))
(name (eask-guess-package-name))
(recipe `(,(intern name) :fetcher ,fetcher)))
(cond ((memq fetcher '(git hg))
(nconc recipe `(:url ,url)))
((memq fetcher '(gitlab github))
(nconc recipe `(:repo ,repo))))
(when eask-files
(nconc recipe `(:files ,(append '(:defaults) eask-files))))
recipe)))

(eask-start
(if-let ((url (eask-package-desc-url)))
(let* ((fetcher (cond ((string-match-p "github.com" url) 'github)
((string-match-p "gitlab.com" url) 'gitlab)
(t 'git)))
(url-regex (if (eq fetcher 'github)
"http[s]://github.com/"
"http[s]://gitlab.com/"))
(repo (replace-regexp-in-string url-regex "" url))
(name (eask-guess-package-name))
(recipe
`(,(intern name) :fetcher ,fetcher)))
(cond ((memq fetcher '(git hg))
(nconc recipe `(:url ,url)))
((memq fetcher '(gitlab github))
(nconc recipe `(:repo ,repo))))
(when eask-files
(nconc recipe `(:files ,(append '(:defaults) eask-files))))
(if-let ((recipe (eask--recipe-string))
(name (eask-guess-package-name)))
(progn
(eask-msg "")
(eask-msg "recipes/%s:" name)
(eask-msg "")
(eask-msg "%s" (pp-to-string recipe))
(eask-msg ""))
(eask-msg "%s" (pp-to-string recipe)))
(eask-msg "")
(eask-info "(Repository URL is required to form a recipe)")
(eask-help "core/recipe")))
Expand Down
49 changes: 49 additions & 0 deletions lisp/generate/recipe.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
;;; generate/recipe.el --- Generate recipe file -*- lexical-binding: t; -*-

;;; Commentary:
;;
;; Command use generate recipe file,
;;
;; $ eask generate recipe [destination]
;;
;;
;; Positional options:
;;
;; [destination] destination path/folder
;;

;;; 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))

(eask-load "core/recipe")

;;
;;; Core

(eask-start
(if-let ((recipe (eask--recipe-string))
(name (eask-guess-package-name)))
(let* ((eask-recipe-path (or (eask-args 0) eask-recipe-path))
(eask-recipe-path (expand-file-name eask-recipe-path))
(recipe-file (expand-file-name name eask-recipe-path))
(recipe-string (pp-to-string recipe)))
(when (or (eask-yes-p)
(yes-or-no-p (format "%s\nIs this OK? " recipe-string)))
;; XXX: Just to fake the user input!
(when (eask-yes-p)
(eask-msg (format "%s\nIs this OK? (yes or no) yes" recipe-string)))
(ignore-errors (make-directory eask-recipe-path t))
(with-current-buffer (find-file recipe-file)
(erase-buffer)
(insert recipe-string)
(save-buffer))
(eask-info "(Generated in %s)" recipe-file)))
(eask-msg "")
(eask-info "(Repository URL is required to form a recipe)")
(eask-help "core/recipe")))

;;; generate/recipe.el ends here
1 change: 1 addition & 0 deletions test/commands/local/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ eask eval "(progn (require 'mini.emacs.pkg.1))"
# Generation
eask generate autoloads
eask generate pkg-file
eask generate recipe -y
#eask generate license gpl-3.0 # XXX: Avoid API rate limit exceeded error
eask generate ignore elisp

Expand Down