Skip to content

Commit

Permalink
feat(generate): Add command to generate ignore file (#169)
Browse files Browse the repository at this point in the history
* feat(generate): Add command to generate ignore file

* Changelog

* fix comment

* update doc

* Add generate test
  • Loading branch information
jcs090218 authored Mar 19, 2023
1 parent f3bc197 commit dd5f661
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
* Add `clean` option for clean compile environment (#166)
* Split up `config` and `global` space into two different environments (#167)
* Add use of `--show-hidden` option (#168)
* Add command to generate `ignore` file (#169)

## 0.8.x
> Released Mar 08, 2023
Expand Down
43 changes: 43 additions & 0 deletions cmds/generate/ignore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* 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 = ['ignore <name>'];
exports.desc = 'Generate ignore file using .gitignore templates';
exports.builder = yargs => yargs
.positional(
'<name>', {
description: 'name of the ignore template',
type: 'string',
})
.options({
'output': {
description: 'output result to a file; the default is `.gitignore`',
alias: 'o',
type: 'string',
group: TITLE_CMD_OPTION,
},
});

exports.handler = async (argv) => {
await UTIL.e_call(argv, 'generate/ignore'
, argv.name
, UTIL.def_flag(argv.output, '--output', argv.output));
};
16 changes: 16 additions & 0 deletions docs/content/en/Development API/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,26 @@ Command entry point. Each command file should contain this macro somewhere in th

Points to `lisp` directory from the project root.

```elisp
(message "%s" eask-lisp-root) ; path/to/eask/cli/lisp/
```

## 🔍 Function: eask-command ()

Return the current command in string.

Suppose the command is:

```sh
$ eask init
```

then,

```elisp
(message "%s" (eask-command)) ; init
```

## 🔍 Function: eask-special-p ()

Return `t` if the command that can be run without Eask-file existence.
Expand Down
52 changes: 36 additions & 16 deletions docs/content/en/Getting Started/Commands and options.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,20 @@ Generate files that are used for the development.

Generate autoload file.

Write a package autoloads to `project-autoloads.el` in the project root.

```sh
$ eask [GLOBAL-OPTIONS] generate autoloads
```

`project` is the project name, as declared in `Eask`-file. See
[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 pkg-file

Generate pkg file.

Write a package descriptor file to `project-pkg.el` in the project root.

```sh
Expand All @@ -350,34 +358,54 @@ $ eask [GLOBAL-OPTIONS] generate license <name>
`name` is the type of the license, see https://api.github.com/licenses for all
the choices.

{{< hint info >}}
💡 This command uses the package [license-templates](https://github.com/jcs-elpa/license-templates)
to generate ignore file.
{{< /hint >}}

## 🔍 eask generate ignore

Generate ignore file.

```sh
$ eask [GLOBAL-OPTIONS] generate ignore <name>
```

{{< hint info >}}
💡 This command uses the package [gitignore-templates](https://github.com/xuchunyang/gitignore-templates.el)
to generate ignore file.
{{< /hint >}}

## 🔍 eask generate workflow circle-ci

Generate CircleCI workflow yaml file.

The default filename is `config.yml`.

```sh
$ eask [GLOBAL-OPTIONS] generate workflow circle-ci [--file]
```

{{< hint info >}}
💡 This will generate the yaml file under `.circleci/`!
{{< /hint >}}
This will generate the yaml file under `.circleci/`!

## 🔍 eask generate workflow github

Generate GitHub Actions workflow yaml file.

The default filename is `test.yml`.

```sh
$ eask [GLOBAL-OPTIONS] generate workflow github [--file]
```

{{< hint info >}}
💡 This will generate the yaml file under `.github/workflow/`!
{{< /hint >}}
This will generate the yaml file under `.github/workflow/`!

## 🔍 eask generate workflow gitlab

Generate GitLab Runner workflow yaml file.

The default filename is `.gitlab-ci.yml`.

```sh
$ eask [GLOBAL-OPTIONS] generate workflow gitlab [--file]
```
Expand All @@ -386,6 +414,8 @@ $ eask [GLOBAL-OPTIONS] generate workflow gitlab [--file]

Generate Travis CI workflow yaml file.

The default filename is `.travis.yml`.

```sh
$ eask [GLOBAL-OPTIONS] generate workflow travis-ci [--file]
```
Expand Down Expand Up @@ -725,16 +755,6 @@ Force to uninstall the package `dash` even it's a dependency from another packag
$ eask -f [COMMAND]
```

## 🔍 --development, --dev

Notify command with development scope enabled.

If we attempt to install development dependencies:

```sh
$ eask --dev [COMMAND]
```

## 🔍 --debug

Enable debug information.
Expand Down
4 changes: 3 additions & 1 deletion lisp/_prepare.el
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ will return `lint/checkdoc' with a dash between two subcommands."

(defun eask-special-p ()
"Return t if the command that can be run without Eask-file existence."
(member (eask-command) '("init/cask" "cat" "keywords" "generate/license")))
(member (eask-command) '("init/cask" "cat" "keywords"
"generate/ignore" "generate/license")))

(defun eask-checker-p ()
"Return t if running Eask as the checker."
Expand Down Expand Up @@ -779,6 +780,7 @@ This uses function `locate-dominating-file' to look up directory tree."
(eask-msg "✓ Loading global Eask file in %s... done!" eask-file)
(eask-msg "✗ Loading global Eask file... missing!"))
(message "")
(package-activate-all)
(ignore-errors (make-directory package-user-dir t))
(eask--with-hooks ,@body))))
((eask-config-p)
Expand Down
1 change: 0 additions & 1 deletion lisp/core/cat.el
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
;; Preparation
(eask-with-archives "melpa"
(eask-package-install 'e2ansi))
(package-activate-all)
(eask-msg "")

;; Start the task
Expand Down
61 changes: 61 additions & 0 deletions lisp/generate/ignore.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
;;; generate/ignore.el --- Generate ignore file -*- lexical-binding: t; -*-

;;; Commentary:
;;
;; Command use generate ignore file,
;;
;; $ eask generate ignore <name>
;;
;;
;; Positionals:
;;
;; <name> Name of the ignore template
;;
;; Optional arguments:
;;
;; --output Output result to a file; the default is `.gitignore`
;;

;;; 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--print-ignore-menu ()
"Print all available ignore."
(eask-msg "available via `eask generate ignore`")
(eask-msg "")
(let ((names (gitignore-templates-names)))
(dolist (data names)
(eask-msg " %s" data))
(eask-msg "")
(eask-info "(Total of %s available ignore file%s)" (length names)
(eask--sinr names "" "s"))))

(eask-start
;; Preparation
(eask-with-archives "melpa"
(eask-package-install 'gitignore-templates))

;; Start the task
(require 'gitignore-templates)
(let* ((name (car (eask-args))) ; type of the ignore
(basename (or (eask-output) ".gitignore"))
(filename (expand-file-name basename)))
(eask-msg "")
(cond ((file-exists-p filename)
(eask-info "(The ignore file already exists `%s`)" filename))
((not (member name (gitignore-templates-names)))
(eask-info "(Invalid ignore type: `%s`)" name)
(eask--print-ignore-menu))
(t
(eask-with-progress
(format "Generating ignore file in %s... " filename)
(with-current-buffer (find-file filename)
(gitignore-templates-insert name)
(save-buffer))
"done ✓")))))

;;; generate/ignore.el ends here
4 changes: 2 additions & 2 deletions lisp/generate/license.el
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
(license-templates-keys) ; trigger request
(eask-msg "")
(cond ((file-exists-p filename)
(eask-info "The license file already exists `%s`" filename))
(eask-info "(The license file already exists `%s`)" filename))
((not (member name (license-templates-keys)))
(eask-info "Invalid license type: `%s`" name)
(eask-info "(Invalid license type: `%s`)" name)
(eask--print-license-menu))
(t
(eask-with-progress
Expand Down
6 changes: 6 additions & 0 deletions test/commands/local/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ eask run -all
# Exection
eask eval "(progn (require 'mini.emacs.pkg.1))"

# Generation
eask generate autoloads
eask generate pkg-file
eask generate license gpl-3.0
eask generate ignore elisp

# Linter
eask lint checkdoc
eask lint declare
Expand Down

0 comments on commit dd5f661

Please sign in to comment.