Browse files

pa-create-project creates projects from archetypes

  • Loading branch information...
1 parent dcdde6f commit a57033b4dd1cb70fe9c1dbbcaa54ab9bda7d7069 @magnars committed Apr 19, 2013
View
1 init.el
@@ -157,6 +157,7 @@
(require 'key-bindings)
;; Misc
+(require 'project-archetypes)
(require 'appearance)
(require 'my-misc)
(when is-mac (require 'mac))
View
2 project-archetypes/clj-ring-archetype.el
@@ -9,4 +9,6 @@
(create-clj-ring "test-test")
(find-file-other-window "~/projects/test-test"))
+(pa-declare-project-archetype "clj-ring" 'create-clj-ring)
+
(provide 'clj-ring-archetype)
View
6 project-archetypes/js-buster-browser-archetype.el
@@ -1,7 +1,5 @@
(defun create-js-buster-browser (project-name description global)
- (interactive "sProject name:
-sDescription:
-sGlobal namespace: ")
+ (interactive "sProject name: \nsDescription: \nsGlobal namespace: ")
(pa-with-new-project project-name "js-buster-browser"
((cons "__project-name__" project-name)
(cons "__description__" description)
@@ -11,4 +9,6 @@ sGlobal namespace: ")
(pa-sh "npm link buster")
(pa-sh "npm install")))
+(pa-declare-project-archetype "js-buster-browser" 'create-js-buster-browser)
+
(provide 'js-buster-browser-archetype)
View
30 site-lisp/project-archetypes/project-archetypes.el
@@ -1,12 +1,29 @@
(require 'dash)
(require 's)
-(defvar pa-folder (expand-file-name "project-archetypes" user-emacs-directory))
-(defvar pa-project-folder (expand-file-name "projects" "~"))
-(defvar pa-out "*project-archetypes-output*")
+(defvar pa-project-archetypes nil
+ "The list of available project archetypes.")
+
+(defvar pa-folder (expand-file-name "project-archetypes" user-emacs-directory)
+ "The directory containing project archetypes.")
+
+(defvar pa-project-folder (expand-file-name "projects" "~")
+ "The directory where projects should be created.")
+
+(defvar pa-out "*project-archetypes-output*"
+ "Name of the buffer where output from the running process is displayed.")
+
+(defun pa-declare-project-archetype (name fn)
+ "Add project archetype to the list of available ones."
+ (add-to-list 'pa-project-archetypes (cons name fn)))
+
+(defun pa-create-project ()
+ (interactive)
+ (let ((name (completing-read "Archetype: " (-map 'car pa-project-archetypes) nil t)))
+ (call-interactively (cdr (assoc name pa-project-archetypes)))))
(defun pa--join-patterns (patterns)
- "Turn `ffip-paterns' into a string that `find' can use."
+ "Turn `patterns' into a string that `find' can use."
(mapconcat (lambda (pat) (format "-name \"%s\"" pat))
patterns " -or "))
@@ -32,7 +49,7 @@
(defun pa-instantiate-template-directory (template folder &rest replacements)
(let ((tmp-folder (expand-file-name (concat "__pa_tmp_" template) pa-project-folder)))
(copy-directory (expand-file-name template pa-folder) tmp-folder nil nil t)
- (--each (pa--files-matching (-map 'car replacements) tmp-folder)
+ (--each (pa--files-matching (--map (s-concat "*" (car it) "*") replacements) tmp-folder)
(rename-file it (s-replace-all replacements it)))
(--each (pa--files-matching ["*"] tmp-folder "-type f")
(pa--instantiate-template-file it replacements))
@@ -53,5 +70,8 @@
(put 'pa-with-new-project 'lisp-indent-function 2)
+(when (file-exists-p pa-folder)
+ (-each (directory-files pa-folder nil "^[^#].*el$") 'load))
+
(provide 'project-archetypes)
;;; project-archetypes.el ends here

0 comments on commit a57033b

Please sign in to comment.