-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbun-install.el
77 lines (61 loc) · 2.87 KB
/
bun-install.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
;;; bun-install.el --- Run your bun workflows -*- lexical-binding: t; -*-
;; Copyright (C) 2024 Shane Kennedy
;; Author: Shane Kennedy
;; Homepage: https://github.com/shaneikennedy/bun.el
;; Keywords: tools
;; Version: 0
;; 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 of the License, 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/>.
;;; Commentary:
;; Functions for installing bun packages.
;;; Code:
(require 'bun-common)
(transient-define-prefix bun-install-menu ()
"Open bun install transient menu pop up."
["Arguments"
("-f" "Force fetching even if copy exists on disk" "--force")
("-g" "Save as global dependency" "--global")
("-p" "Save as production dependency" "--production")
("-d" "Save as development dependency" "--dev")
("-o" "Save as optional dependency" "--optional")
("-e" "Save exact version" "--exact")
("-n" "Do not save to package.json" "--no-save")]
[["Command"
("i" "Install new package" bun-install)
("I" "Install current packages (in package.json)" bun-install-current)]]
(interactive)
(transient-setup 'bun-install-menu))
(defconst bun-install--prefix-command "bun install")
(defun bun-install--get-install-command (package-name)
"Construct the shell command for a given PACKAGE-NAME."
(concat bun-install--prefix-command " " package-name))
(defun bun-install--choose-package ()
"Let user choose which package to install."
(interactive)
(completing-read "Type the name of the package you want to install: " ()))
(defun bun-install-menu-arguments nil
"Arguments function for transient."
(transient-args 'bun-install-menu))
(defun bun-install-current (&optional args)
"Invoke the compile mode with the install prefix-command and ARGS if provided but no packages."
(interactive)
(let ((arguments (string-join args " "))
(bun-command (bun-install--get-install-command "")))
(bun-common--compile bun-command arguments)))
;;;###autoload
(defun bun-install (&optional args)
"Invoke the compile mode with the install prefix-command and ARGS if provided."
(interactive (list (bun-install-menu-arguments)))
(let* ((arguments (string-join args " "))
(bun-command (bun-install--get-install-command (bun-install--choose-package))))
(bun-common--compile bun-command arguments)))
(provide 'bun-install)
;;; bun-install.el ends here