My attempt to optimize my emacs load time <1 second
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
4.6 KiB

  1. ;;; sfdx --- Emacs wrapper for basic sfdx cli commands
  2. ;;; Commentary:
  3. ;;; Code:
  4. (defvar sfdx-create-css)
  5. (setq-default sfdx-create-css t)
  6. (defun sfdx/next-component-file ()
  7. "Find next file with the same name, but different file extension."
  8. (interactive)
  9. (let (
  10. (current-file-name (file-name-sans-extension (buffer-file-name)))
  11. (current-ext (file-name-extension (buffer-file-name)))
  12. )
  13. (when (string= current-ext "js")
  14. (find-file (concat current-file-name ".html")))
  15. (when (string= current-ext "html")
  16. (if (file-exists-p (concat current-file-name ".css"))
  17. (find-file (concat current-file-name ".css"))
  18. (if (and sfdx-create-css (yes-or-no-p "Do you want to create a CSS file?"))
  19. (find-file (concat current-file-name ".css"))
  20. (setq-local sfdx-create-css nil)
  21. (find-file (concat current-file-name ".js")))))
  22. (when (string= current-ext "css")
  23. (find-file (concat current-file-name ".js")))
  24. ))
  25. (defun sfdx--goto-project (project-path)
  26. "Internal function to load the PROJECT-PATH in current window."
  27. ;; DEBUG - this isn't working to auto-open the folder.
  28. ;; (find-file project-path)
  29. (message project-path))
  30. (defun sfdx/create-project ()
  31. "Create a new 'standard' SFDX project."
  32. (interactive)
  33. (let (
  34. (process "sfdx-create-project")
  35. (project-name (read-string "Project Name: "))
  36. (project-dir (read-directory-name "Directory: " "~/Projects"))
  37. )
  38. (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"))
  39. ))
  40. (defun sfdx/create-component ()
  41. "Create a new Lightning Web Component."
  42. (interactive)
  43. (if (locate-dominating-file buffer-file-name "force-app")
  44. (let ((process "*sfdx-create-component-process*")
  45. (buffer "*sfdx*")
  46. (output-path (concat (locate-dominating-file buffer-file-name "force-app") "force-app/main/default/lwc"))
  47. (comp-name (read-string "Component Name: "))
  48. )
  49. (call-process (concat "sfdx force:lightning:component:create --type lwc --componentname " comp-name " --outputdir " output-path) nil buffer)
  50. (find-file (concat output-path "/" comp-name "/" comp-name ".js"))
  51. )
  52. (message "You must be in an SFDX project to run that command!")))
  53. (defun sfdx--deploy (component comp-name)
  54. "Internal function to deploy COMP-NAME asyncronously or project if COMPONENT is nil after validations."
  55. (let ((process "sfdx-deploy-output")
  56. (cd-dir (locate-dominating-file buffer-file-name "force-app"))
  57. (output-path (concat (locate-dominating-file buffer-file-name "force-app") "force-app/main/default"))
  58. )
  59. (if component
  60. (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"))
  61. (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"))
  62. )
  63. )
  64. )
  65. (defun sfdx/deploy-component-or-project ()
  66. "Deploy the current component or project to target."
  67. (interactive)
  68. (let ((current-folder (file-name-nondirectory
  69. (directory-file-name
  70. (file-name-directory (buffer-file-name))))))
  71. (if (locate-dominating-file buffer-file-name "lwc")
  72. (prog1
  73. ;; Possibly in a component folder, but lets makes sure its not just the LWC folder.
  74. (if (string= current-folder "lwc")
  75. (prog1
  76. ;; Not in a component, deploy project.
  77. (message "Deploying Project...")
  78. (sfdx--deploy nil current-folder))
  79. ;; In a component, deploy component.
  80. (message "Deploying Component...")
  81. (sfdx--deploy t current-folder)))
  82. (prog1
  83. ;; Are we in a project?
  84. (if (locate-dominating-file buffer-file-name "force-app")
  85. (prog1
  86. ;; In project, deploy project.
  87. (message "Deploying Project...")
  88. (sfdx--deploy nil current-folder))
  89. (prog1
  90. ;; Not in an SFDX project.
  91. (message "You are not in a component folder or an SFDX project!"))
  92. )
  93. )
  94. )
  95. )
  96. )
  97. (provide 'sfdx)
  98. ;;; sfdx.el ends here