From db81c0b127dd23c71ca498aad40764bd0cb63be3 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Thu, 5 Oct 2017 14:32:31 +0200 Subject: Emacs: Make yarn- commands DWIM w.r.t. yarn/npm --- emacs/.emacs.d/main.el | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/emacs/.emacs.d/main.el b/emacs/.emacs.d/main.el index 1ad0cb23..f837c836 100644 --- a/emacs/.emacs.d/main.el +++ b/emacs/.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") -- cgit 1.4.1