mirror of
https://github.com/doomemacs/doomemacs
synced 2025-09-14 15:46:56 -05:00
refactor(cli): doom make
Redesigns the 'doom make' command and the CODEOWNERS rule in .doom (which is now obeyed on 'doom make .github/CODEOWNERS').
This commit is contained in:
7
.doom
7
.doom
@@ -26,12 +26,13 @@
|
|||||||
|
|
||||||
(make
|
(make
|
||||||
(".github/CODEOWNERS"
|
(".github/CODEOWNERS"
|
||||||
"# Auto-generated by 'doom make .github/CODEOWNERS', do not edit it by hand.")
|
"# Auto-generated by 'doom make .github/CODEOWNERS', do not edit it by hand.\n"
|
||||||
"*\t@doomemacs/maintainers" ; default until another takes precedence
|
"* @doomemacs/maintainers\n" ; default until another takes precedence
|
||||||
|
"# Module maintainers"
|
||||||
,@(cl-sort
|
,@(cl-sort
|
||||||
(cl-loop for path in (doom-module-load-path (list doom-modules-dir))
|
(cl-loop for path in (doom-module-load-path (list doom-modules-dir))
|
||||||
if (string-match "/modules/\\([^/]+\\)/\\([^/]+\\)$" path)
|
if (string-match "/modules/\\([^/]+\\)/\\([^/]+\\)$" path)
|
||||||
collect (format "%s\t@doomemacs/%s-%s"
|
collect (format "%-35s @doomemacs/%s-%s"
|
||||||
(substring (match-string 0 path) 1)
|
(substring (match-string 0 path) 1)
|
||||||
(match-string 1 path)
|
(match-string 1 path)
|
||||||
(match-string 2 path)))
|
(match-string 2 path)))
|
||||||
|
@@ -10,62 +10,37 @@
|
|||||||
;;
|
;;
|
||||||
;;; Variables
|
;;; Variables
|
||||||
|
|
||||||
(defvar doom-make-codeowners-file ".github/CODEOWNERS"
|
|
||||||
"Where to write the CODEOWNERS file, relative to the repo's toplevel.")
|
|
||||||
|
|
||||||
(defvar doom-make-codeowners ()
|
|
||||||
"An alist of codeowners for this project.
|
|
||||||
|
|
||||||
Each entry can either be a string (inserted verbatim, surrounded by newlines) or
|
|
||||||
a pair of strings (in a cons cell) consisting of: (GLOB . CODEOWNERS).
|
|
||||||
|
|
||||||
The contents of this variable are inserted in reverse.")
|
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;;; Commands
|
;;; Commands
|
||||||
|
|
||||||
(defcli! make ()
|
(defcli! make
|
||||||
"(Re)Generate project files and boilerplate."
|
((dryrun? ("--dryrun"))
|
||||||
:partial t)
|
(output ("-o" "--output" path))
|
||||||
|
&args targets)
|
||||||
(defcli! (make codeowners)
|
"Run make targets (defined in .doom)."
|
||||||
((outfile ("-o" "--file" (file stdout)) "Where to write the codeowners file")
|
|
||||||
(dryrun? ("--dryrun")))
|
|
||||||
"Generate (or update) a CODEOWNERS file.
|
|
||||||
|
|
||||||
By default, this means $GIT_WORK_TREE/.github/CODEOWNERS. This will throw an
|
|
||||||
error if not run in a Git repo.
|
|
||||||
|
|
||||||
OPTIONS:
|
|
||||||
-o, --file
|
|
||||||
Pass this option a dash to print the codeowners file to stdout."
|
|
||||||
(when dryrun?
|
(when dryrun?
|
||||||
(setq outfile "-")
|
(print! (warn "Running dry run")))
|
||||||
(print! (warn "Running dry run; will only print to stdout:")))
|
(let* ((root (doom-git-toplevel))
|
||||||
(with-temp-buffer
|
(rc (doom-rcfile-read `(project make) root)))
|
||||||
(let ((codeowners-file
|
(dolist (target targets)
|
||||||
(cond ((equal outfile "-") nil)
|
(with-temp-buffer
|
||||||
(outfile (expand-file-name outfile))
|
(let* ((outfile
|
||||||
((file-name-concat (doom-git-toplevel) doom-make-codeowners-file)))))
|
(unless (equal output "-")
|
||||||
(insert "# -*- mode: conf -*-\n"
|
(expand-file-name target)))
|
||||||
"# Each line is a file pattern followed by one or more owners.\n"
|
(name (file-relative-name (file-truename target) root))
|
||||||
"# This file was generated by 'doom make codeowners', do not edit it by hand.\n")
|
(rule (assoc name rc)))
|
||||||
(dolist (entry (nreverse doom-make-codeowners))
|
(if (null rule)
|
||||||
(if (stringp entry)
|
(print! (warn "No known make rule for: %s" name))
|
||||||
(insert "\n" entry "\n")
|
(dolist (entry rule)
|
||||||
(insert (format "%-35s %s" (car entry) (cdr entry)) "\n")))
|
(when (stringp entry)
|
||||||
(insert "\n# End of CODEOWNERS")
|
(insert entry "\n")))
|
||||||
(setq indent-tabs-mode nil) ; align w/ spaces, not tabs
|
(if (null outfile)
|
||||||
(align-regexp (point-min) (point-max) "/\\(\\s-+\\)@" 1)
|
(print! "%s --" (buffer-string))
|
||||||
(if (null codeowners-file)
|
(print! (start "Wrote %s") name)
|
||||||
(print! "%s" (buffer-string))
|
(unless dryrun?
|
||||||
(print! (start "%s codeowners file at: %s")
|
(write-region (buffer-string) nil outfile)))))))))
|
||||||
(if (file-exists-p codeowners-file)
|
|
||||||
"Regenerated"
|
|
||||||
"Generated")
|
|
||||||
(relpath codeowners-file))
|
|
||||||
(write-region (buffer-string) nil codeowners-file)))))
|
|
||||||
|
|
||||||
;; TODO Finish me
|
;; TODO Finish me
|
||||||
(defcli-stub! (make changelog))
|
(defcli-stub! (make changelog))
|
||||||
|
Reference in New Issue
Block a user