refactor new project options a bit to make adding new db choices easier
This commit is contained in:
parent
64ce4c1855
commit
0e3b60b535
|
@ -58,9 +58,11 @@
|
|||
["src/{{path}}/views.clj" (render "src/root_ns/views_webservice.clj" data)]
|
||||
["dev/user.clj" (render "dev/user_webservice.clj" data)]])
|
||||
|
||||
(defn get-sql-files [data]
|
||||
["migrations"])
|
||||
|
||||
(defn get-postgresql-files [data]
|
||||
["migrations"
|
||||
["src/{{path}}/db.clj" (render "src/root_ns/db_postgresql.clj" data)]])
|
||||
[["src/{{path}}/db.clj" (render "src/root_ns/db_postgresql.clj" data)]])
|
||||
|
||||
(defn get-couchdb-files [data]
|
||||
[["src/{{path}}/db.clj" (render "src/root_ns/db_couchdb.clj" data)]])
|
||||
|
@ -72,6 +74,7 @@
|
|||
(get-base-files data)
|
||||
(if (:webapp data) (get-webapp-files data))
|
||||
(if (:webservice data) (get-webservice-files data))
|
||||
(if (:sql data) (get-sql-files data))
|
||||
(if (:postgresql data) (get-postgresql-files data))
|
||||
(if (:couchdb data) (get-couchdb-files data)))))
|
||||
|
||||
|
@ -91,14 +94,29 @@
|
|||
(println "*** If neither 'webapp' or 'webservice' is specified, 'webapp' is assumed")
|
||||
(println "*** Specifying no options will default to use only 'webapp'"))
|
||||
|
||||
(defn add-webapp-default [options]
|
||||
(if-not (or (some #{"webapp"} options)
|
||||
(some #{"webservice"} options))
|
||||
(conj options "webapp")
|
||||
options))
|
||||
|
||||
(defn add-sql-option [options]
|
||||
(if (some #{"postgresql"} options)
|
||||
(conj options "sql")
|
||||
options))
|
||||
|
||||
(defn add-nosql-option [options]
|
||||
(if (some #{"couchdb"} options)
|
||||
(conj options "nosql")
|
||||
options))
|
||||
|
||||
(defn get-final-requested-options [requested-options]
|
||||
(let [options (if (seq requested-options)
|
||||
(set requested-options)
|
||||
default-options)]
|
||||
(if-not (or (some #{"webapp"} options)
|
||||
(some #{"webservice"} options))
|
||||
(conj options "webapp")
|
||||
options)))
|
||||
(->> (if (seq requested-options)
|
||||
(set requested-options)
|
||||
default-options)
|
||||
(add-webapp-default)
|
||||
(add-sql-option)
|
||||
(add-nosql-option)))
|
||||
|
||||
(defn yawt
|
||||
"Creates a new YAWT (web app/service) project."
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
{:dev true
|
||||
{{#postgresql}}
|
||||
{{#sql}}
|
||||
:db {:host "localhost"
|
||||
:name "db_name"
|
||||
:port 5432
|
||||
:username "username"
|
||||
:password "password"}
|
||||
{{/postgresql}}
|
||||
{{/sql}}
|
||||
{{#couchdb}}
|
||||
:db {:url "http://localhost:5984/"
|
||||
:username "username"
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
{:dev true
|
||||
:repl true
|
||||
:auto-start-server? true
|
||||
{{#postgresql}}
|
||||
{{#sql}}
|
||||
:db {:host "localhost"
|
||||
:name "db_name"
|
||||
:port 5432
|
||||
:username "username"
|
||||
:password "password"}
|
||||
{{/postgresql}}
|
||||
{{/sql}}
|
||||
{{#couchdb}}
|
||||
:db {:url "http://localhost:5984/"
|
||||
:username "username"
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
{:release true
|
||||
{{#postgresql}}
|
||||
{{#sql}}
|
||||
:db {:host "localhost"
|
||||
:name "db_name"
|
||||
:port 5432
|
||||
:username "username"
|
||||
:password "password"}
|
||||
{{/postgresql}}
|
||||
{{/sql}}
|
||||
{{#couchdb}}
|
||||
:db {:url "http://localhost:5984/"
|
||||
:username "username"
|
||||
|
|
|
@ -25,10 +25,12 @@
|
|||
{{#webservice}}
|
||||
[hiccup "1.0.5"]
|
||||
{{/webservice}}
|
||||
{{#postgresql}}
|
||||
{{#sql}}
|
||||
[org.clojure/java.jdbc "0.4.2"]
|
||||
[org.postgresql/postgresql "9.4-1202-jdbc42"]
|
||||
[clojurewerkz/ragtime "0.4.0"]
|
||||
{{/sql}}
|
||||
{{#postgresql}}
|
||||
[org.postgresql/postgresql "9.4-1202-jdbc42"]
|
||||
{{/postgresql}}
|
||||
{{#couchdb}}
|
||||
[com.ashafa/clutch "0.4.0"]
|
||||
|
@ -44,9 +46,9 @@
|
|||
{{#webapp}}
|
||||
[lein-cljsbuild "1.1.2"]
|
||||
{{/webapp}}
|
||||
{{#postgresql}}
|
||||
{{#sql}}
|
||||
[clojurewerkz/ragtime.lein "0.4.0"]
|
||||
{{/postgresql}}
|
||||
{{/sql}}
|
||||
[lein-pprint "1.1.1"]]
|
||||
|
||||
{{#webapp}}
|
||||
|
@ -88,10 +90,10 @@
|
|||
:dev {:resource-paths ["env-resources/dev"]
|
||||
:dependencies [{{#webapp}}[com.cemerick/piggieback "0.2.1"]{{/webapp}}
|
||||
[pjstadig/humane-test-output "0.7.1"]]
|
||||
{{#postgresql}}
|
||||
{{#sql}}
|
||||
:ragtime {:migrations ragtime.sql.files/migrations
|
||||
:database "jdbc:postgresql://localhost:5432/db_name?user=username&password=password"}
|
||||
{{/postgresql}}
|
||||
:database "jdbc:{{#postgresql}}postgresql{{/postgresql}}://localhost:5432/db_name?user=username&password=password"}
|
||||
{{/sql}}
|
||||
:injections [(require 'pjstadig.humane-test-output)
|
||||
(pjstadig.humane-test-output/activate!)]}
|
||||
:repl {:resource-paths ["env-resources/repl"]
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
{{/webapp}}
|
||||
[edn-config.core :refer [env]]
|
||||
[prone.middleware :as prone]
|
||||
{{#postgresql}}
|
||||
{{#sql}}
|
||||
[{{root-ns}}.db :as db]
|
||||
{{/postgresql}}
|
||||
{{/sql}}
|
||||
[{{root-ns}}.routes :refer [main-public-routes api-routes]]
|
||||
[{{root-ns}}.middleware :refer [wrap-exceptions not-found-handler]]))
|
||||
|
||||
|
@ -37,14 +37,14 @@
|
|||
(when (env :dev)
|
||||
(info "Running in :dev environment."))
|
||||
{{/webservice}}
|
||||
{{#postgresql}}
|
||||
{{#sql}}
|
||||
|
||||
(try
|
||||
(db/init!)
|
||||
(info "Database access initialized.")
|
||||
(catch Exception ex
|
||||
(throw (Exception. "Database not available or bad connection information specified." ex))))
|
||||
{{/postgresql}}
|
||||
{{/sql}}
|
||||
|
||||
(info "Application init finished."))
|
||||
|
||||
|
|
Reference in a new issue