all repos — archive/dotfiles @ db81c0b127dd23c71ca498aad40764bd0cb63be3

Superseded by nixfiles

Emacs: Make yarn- commands DWIM w.r.t. yarn/npm
Alan Pearce alan@alanpearce.eu
Thu, 05 Oct 2017 14:32:31 +0200
commit

db81c0b127dd23c71ca498aad40764bd0cb63be3

parent

691833dcc0e68729a63e28acd20e61f39f6407c0

1 files changed, 20 insertions(+), 5 deletions(-)

jump to
M emacs/.emacs.d/main.elemacs/.emacs.d/main.el
@@ -490,28 +490,43 @@             (defun yarn-install (&optional arg)
               (interactive "P")
               (projectile-with-default-dir (projectile-project-root)
-                (cmd-to-echo "yarn" "install")))
+                (cond
+                 ((string-equal (projectile-project-type) "node-yarn")
+                  (cmd-to-echo "yarn" "install"))
+                 (t (cmd-to-echo "npm" "install")))))
 
             (defun yarn-add-dev (package)
               (interactive "spackage: ")
               (projectile-with-default-dir (projectile-project-root)
-                (cmd-to-echo "yarn" (concat "add --dev " package))))
+                (cond
+                 ((string-equal (projectile-project-type) "node-yarn")
+                  (cmd-to-echo "yarn" (concat "add --dev " package)))
+                 (t (cmd-to-echo "npm" (concat "install --save-dev " package))))))
 
             (defun yarn-add (package)
               (interactive "spackage: ")
               (projectile-with-default-dir (projectile-project-root)
-                (cmd-to-echo "yarn" (concat "add " package))))
+                (cond
+                 ((string-equal (projectile-project-type) "node-yarn")
+                  (cmd-to-echo "yarn" (concat "add " package)))
+                 (t (cmd-to-echo "npm" (concat "install --save " package))))))
 
             (defun yarn-remove (package)
               (interactive "spackage: ")
               (projectile-with-default-dir (projectile-project-root)
-                (cmd-to-echo "yarn" (concat "remove " package))))
+                (cond
+                 ((string-equal (projectile-project-type) "node-yarn")
+                  (cmd-to-echo "yarn" (concat "remove " package)))
+                 (t (cmd-to-echo "npm" (concat "remove " package))))))
 
             (defun yarn-run (cmd)
               (interactive (list
                             (projectile-completing-read "command: " (alist-get 'scripts (json-read-file (expand-file-name "package.json" (projectile-project-root)))))))
               (projectile-with-default-dir (projectile-project-root)
-                (cmd-to-echo "yarn" (concat "run " cmd))))
+                (cond
+                 ((string-equal (projectile-project-type) "node-yarn")
+                  (cmd-to-echo "yarn" (concat "run " cmd)))
+                 (t (cmd-to-echo "npm" (concat "run " cmd))))))
 
             (defun ap/open-project (&optional arg)
               (interactive "P")