From dd5f6611dc4c701d4bad03ccd879cdcaa7e2fca3 Mon Sep 17 00:00:00 2001 From: Jen-Chieh Shen Date: Sun, 19 Mar 2023 03:15:01 -0700 Subject: [PATCH] feat(generate): Add command to generate ignore file (#169) * feat(generate): Add command to generate ignore file * Changelog * fix comment * update doc * Add generate test --- CHANGELOG.md | 1 + cmds/generate/ignore.js | 43 +++++++++++++ docs/content/en/Development API/_index.md | 16 +++++ .../Getting Started/Commands and options.md | 52 +++++++++++----- lisp/_prepare.el | 4 +- lisp/core/cat.el | 1 - lisp/generate/ignore.el | 61 +++++++++++++++++++ lisp/generate/license.el | 4 +- test/commands/local/run.sh | 6 ++ 9 files changed, 168 insertions(+), 20 deletions(-) create mode 100644 cmds/generate/ignore.js create mode 100644 lisp/generate/ignore.el diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b01e11a..f7e45153 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/cmds/generate/ignore.js b/cmds/generate/ignore.js new file mode 100644 index 00000000..e0bcac43 --- /dev/null +++ b/cmds/generate/ignore.js @@ -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 ']; +exports.desc = 'Generate ignore file using .gitignore templates'; +exports.builder = yargs => yargs + .positional( + '', { + 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)); +}; diff --git a/docs/content/en/Development API/_index.md b/docs/content/en/Development API/_index.md index 8d32dbe8..c37dc1a0 100644 --- a/docs/content/en/Development API/_index.md +++ b/docs/content/en/Development API/_index.md @@ -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. diff --git a/docs/content/en/Getting Started/Commands and options.md b/docs/content/en/Getting Started/Commands and options.md index 0be365b4..76b57881 100644 --- a/docs/content/en/Getting Started/Commands and options.md +++ b/docs/content/en/Getting Started/Commands and options.md @@ -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 @@ -350,34 +358,54 @@ $ eask [GLOBAL-OPTIONS] generate license `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 +``` + +{{< 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] ``` @@ -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] ``` @@ -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. diff --git a/lisp/_prepare.el b/lisp/_prepare.el index 9b39df62..5c18ab5b 100644 --- a/lisp/_prepare.el +++ b/lisp/_prepare.el @@ -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." @@ -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) diff --git a/lisp/core/cat.el b/lisp/core/cat.el index ae4d16e3..07b60797 100644 --- a/lisp/core/cat.el +++ b/lisp/core/cat.el @@ -27,7 +27,6 @@ ;; Preparation (eask-with-archives "melpa" (eask-package-install 'e2ansi)) - (package-activate-all) (eask-msg "") ;; Start the task diff --git a/lisp/generate/ignore.el b/lisp/generate/ignore.el new file mode 100644 index 00000000..c38dfd8a --- /dev/null +++ b/lisp/generate/ignore.el @@ -0,0 +1,61 @@ +;;; generate/ignore.el --- Generate ignore file -*- lexical-binding: t; -*- + +;;; Commentary: +;; +;; Command use generate ignore file, +;; +;; $ eask generate ignore +;; +;; +;; Positionals: +;; +;; 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 diff --git a/lisp/generate/license.el b/lisp/generate/license.el index e9f60c1e..ae28a078 100644 --- a/lisp/generate/license.el +++ b/lisp/generate/license.el @@ -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 diff --git a/test/commands/local/run.sh b/test/commands/local/run.sh index 3030979c..097b1f33 100644 --- a/test/commands/local/run.sh +++ b/test/commands/local/run.sh @@ -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