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.

127 lines
4.4 KiB

  1. ;;; vlocitemacs.el --- Vlocity Build Tool :: Emacs integration
  2. ;;; Commentary:
  3. ;;
  4. ;; Essentially the following commands are abstracted into elisp and made dynamic:
  5. ;;
  6. ;; vlocity packDeploy -propertyfile build.properties -job job.yaml -key VlocityUITemplate/Test-test
  7. ;; vlocity packExport -propertyfile build.properties -job job.yaml -key VlocityUITemplate/Test-test
  8. ;;
  9. ;;
  10. ;;; Code:
  11. (require 'transient)
  12. (use-package json
  13. :ensure t
  14. :straight (:host github :repo "ryancrum/json.el" :branch "master"))
  15. (defun vlo/generate-sfdx-login-list ()
  16. "This function is used to give a list of choices (Orgs) to the user when deploying/exporting."
  17. ;; 1. make temp file to put the output of `sfdx force:org:list --json` in
  18. ;; 2. read that into the following
  19. ;;
  20. ;; let* means the variables can ref each other
  21. (let* ((json-object-type 'hash-table)
  22. (json-array-type 'list)
  23. (json-key-type 'string)
  24. (json (json-read-file "tempfile-location.json")))
  25. ;; this is how we access the first item of the "result" json member
  26. (car (gethash "result" json))
  27. )
  28. )
  29. (defvar vlo/orgs '(("build.properties" . "job.yaml"))
  30. "List of cons-es that relate a properties file to a job file.")
  31. (defvar vlo/project-file-name ".vemacs"
  32. "The name of the VlocitEmacs file.")
  33. (defvar vlo/store-user nil "Store SFDX user for current session.")
  34. (defun vlo/get-user ()
  35. "Prompt for sfdx username or use stored."
  36. (if vlo/store-user
  37. vlo/store-user
  38. (read-string
  39. ;; (defun vlo/get-propertyfile-name ()
  40. ;; "The name of the build.properties file."
  41. ;; (car (nth 0 vlo/orgs)))
  42. ;; (defun vlo/get-jobfile-name ()
  43. ;; "The name of the job.yaml file."
  44. ;; (cdr (nth 0 vlo/orgs)))
  45. (defun vlo/get-deployment-key ()
  46. "Return the \"key\" used by vlocity to specify what to deploy/export."
  47. (vlo/ensure-init-file)
  48. (let ((path-list (delete "" (split-string (file-name-directory (buffer-file-name)) "/"))))
  49. (format "%s/%s"
  50. (nth (- (length path-list) 2) path-list)
  51. (nth (- (length path-list) 1) path-list))))
  52. (defun vlo/project-path ()
  53. "Return path to the project file, or nil.
  54. If project file exists in the current working directory, or a
  55. parent directory recursively, return its path. Otherwise, return
  56. nil."
  57. (let ((dir (locate-dominating-file default-directory vlo/project-file-name)))
  58. (unless dir
  59. (error (concat "Error: cannot find " vlo/project-file-name)))
  60. dir))
  61. (defun vlo/ensure-init-file ()
  62. "Asserts that you're currently inside a vlocity project."
  63. (vlo/project-path))
  64. (defun leo/exec-process (cmd &optional comint)
  65. "Execute a process running CMD and optionally pass COMINT as t to put buffer in `comint-mode'."
  66. (let ((compilation-buffer-name-function
  67. (lambda (mode)
  68. (format "*exec-process*"))))
  69. (message (concat "Running " cmd))
  70. (compile cmd comint)))
  71. (defun vlo/packExport ()
  72. "Run the packExport command."
  73. (interactive)
  74. (if (and (file-exists-p (vlo/get-propertyfile-name))
  75. (file-exists-p (vlo/get-jobfile-name)))
  76. (leo/exec-process
  77. (format "cd %s; vlocity packExport -sfdx.username %s -job %s -key %s"
  78. (vlo/ensure-init-file)
  79. (vlo/get-user)
  80. (vlo/get-jobfile-name)
  81. (vlo/get-deployment-key)))
  82. (error (format "Error: cannot find either %s or %s" (vlo/get-propertyfile-name) (vlo/get-jobfile-name)))))
  83. (defun vlo/packDeploy ()
  84. "Run the packDeploy command."
  85. (interactive)
  86. (if (and (file-exists-p (vlo/get-propertyfile-name))
  87. (file-exists-p (vlo/get-jobfile-name)))
  88. (leo/exec-process
  89. (format "cd %s; vlocity packDeploy -sfdx.username %s -job %s -key %s"
  90. (vlo/ensure-init-file)
  91. (vlo/get-user)
  92. (vlo/get-jobfile-name)
  93. (vlo/get-deployment-key)))
  94. (error (format "Error: cannot find either %s or %s" (vlo/get-propertyfile-name) (vlo/get-jobfile-name)))))
  95. (define-transient-command vlo/transient-action ()
  96. "Vlocity Build Tool CLI Actions"
  97. ["Actions"
  98. ("e" "export" vlo/packExport)
  99. ("d" "deploy" vlo/packDeploy)])
  100. (provide 'vlocitemacs)
  101. ;;; vlocitemacs.el ends here