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