|
|
- ;;; sfdx --- Emacs wrapper for basic sfdx cli commands
-
- ;;; Commentary:
-
- ;;; Code:
-
- (defvar sfdx-create-css)
- (setq-default sfdx-create-css t)
-
- (defun sfdx/next-component-file ()
- "Find next file with the same name, but different file extension."
- (interactive)
- (let (
- (current-file-name (file-name-sans-extension (buffer-file-name)))
- (current-ext (file-name-extension (buffer-file-name)))
- )
- (when (string= current-ext "js")
- (find-file (concat current-file-name ".html")))
- (when (string= current-ext "html")
- (if (file-exists-p (concat current-file-name ".css"))
- (find-file (concat current-file-name ".css"))
- (if (and sfdx-create-css (yes-or-no-p "Do you want to create a CSS file?"))
- (find-file (concat current-file-name ".css"))
- (setq-local sfdx-create-css nil)
- (find-file (concat current-file-name ".js")))))
- (when (string= current-ext "css")
- (find-file (concat current-file-name ".js")))
- ))
-
- (defun sfdx--goto-project (project-path)
- "Internal function to load the PROJECT-PATH in current window."
- ;; DEBUG - this isn't working to auto-open the folder.
- ;; (find-file project-path)
- (message project-path))
-
- (defun sfdx/create-project ()
- "Create a new 'standard' SFDX project."
- (interactive)
- (let (
- (process "sfdx-create-project")
- (project-name (read-string "Project Name: "))
- (project-dir (read-directory-name "Directory: " "~/Projects"))
- )
- (async-start-process process "sh" `(lambda (result) (sfdx--goto-project (concat (expand-file-name ',project-dir) ',project-name))) "-c" (concat "sfdx force:project:create --projectname " project-name " --outputdir " (expand-file-name project-dir) " --template standard"))
- ))
-
- (defun sfdx/create-component ()
- "Create a new Lightning Web Component."
- (interactive)
- (if (locate-dominating-file buffer-file-name "force-app")
- (let ((process "*sfdx-create-component-process*")
- (buffer "*sfdx*")
- (output-path (concat (locate-dominating-file buffer-file-name "force-app") "force-app/main/default/lwc"))
- (comp-name (read-string "Component Name: "))
- )
- (call-process (concat "sfdx force:lightning:component:create --type lwc --componentname " comp-name " --outputdir " output-path) nil buffer)
- (find-file (concat output-path "/" comp-name "/" comp-name ".js"))
- )
- (message "You must be in an SFDX project to run that command!")))
-
- (defun sfdx--deploy (component comp-name)
- "Internal function to deploy COMP-NAME asyncronously or project if COMPONENT is nil after validations."
- (let ((process "sfdx-deploy-output")
- (cd-dir (locate-dominating-file buffer-file-name "force-app"))
- (output-path (concat (locate-dominating-file buffer-file-name "force-app") "force-app/main/default"))
- )
- (if component
- (async-start-process process "sh" (lambda (result) (message "Deploy Process Finished")) "-c" (concat "cd " cd-dir "; sfdx force:source:deploy --sourcepath force-app/main/default/lwc/" comp-name " --loglevel fatal"))
- (async-start-process process "sh" (lambda (result) (message "Deploy Process Finished")) "-c" (concat "cd " cd-dir "; sfdx force:source:deploy --sourcepath force-app/main/default/ --loglevel fatal"))
- )
- )
- )
-
- (defun sfdx/deploy-component-or-project ()
- "Deploy the current component or project to target."
- (interactive)
- (let ((current-folder (file-name-nondirectory
- (directory-file-name
- (file-name-directory (buffer-file-name))))))
- (if (locate-dominating-file buffer-file-name "lwc")
- (prog1
- ;; Possibly in a component folder, but lets makes sure its not just the LWC folder.
- (if (string= current-folder "lwc")
- (prog1
- ;; Not in a component, deploy project.
- (message "Deploying Project...")
- (sfdx--deploy nil current-folder))
- ;; In a component, deploy component.
- (message "Deploying Component...")
- (sfdx--deploy t current-folder)))
-
- (prog1
- ;; Are we in a project?
- (if (locate-dominating-file buffer-file-name "force-app")
- (prog1
- ;; In project, deploy project.
- (message "Deploying Project...")
- (sfdx--deploy nil current-folder))
- (prog1
- ;; Not in an SFDX project.
- (message "You are not in a component folder or an SFDX project!"))
- )
- )
- )
- )
- )
-
- (provide 'sfdx)
- ;;; sfdx.el ends here
|