From 64125dff4bc2f70cc4b298bc9baf1a6f0a977077 Mon Sep 17 00:00:00 2001 From: Chris McCormick Date: Sun, 13 May 2018 11:53:36 +0800 Subject: [PATCH] Fix dev/prod build settings. Fixes #7 --- env/prod/cljs/omgnata/prod.cljs | 2 +- project.clj | 45 +++++++-------------------------- src/clj/omgnata/env.clj | 6 ----- src/cljc/omgnata/util.cljc | 6 ----- src/cljs/omgnata/core.cljs | 21 ++++++++------- 5 files changed, 22 insertions(+), 58 deletions(-) delete mode 100644 src/clj/omgnata/env.clj delete mode 100644 src/cljc/omgnata/util.cljc diff --git a/env/prod/cljs/omgnata/prod.cljs b/env/prod/cljs/omgnata/prod.cljs index 4ad0ead..7074911 100644 --- a/env/prod/cljs/omgnata/prod.cljs +++ b/env/prod/cljs/omgnata/prod.cljs @@ -4,4 +4,4 @@ ;;ignore println statements in prod (set! *print-fn* (fn [& _])) -(core/init!) +(core/init! true) diff --git a/project.clj b/project.clj index 48534b3..9bbf6bf 100644 --- a/project.clj +++ b/project.clj @@ -40,20 +40,19 @@ [:cljsbuild :builds :app :compiler :output-dir] [:cljsbuild :builds :app :compiler :output-to]] - :source-paths ["src/clj" "src/cljc"] + :source-paths ["src/clj"] :resource-paths ["resources" "target/cljsbuild"] - :minify-assets - {:assets - {"resources/public/css/site.min.css" "resources/public/css/site.css"}} + :minify-assets {:assets {"build/css/site.min.css" "resources/public/css/site.css"}} - :cljsbuild {:builds {:app {:source-paths ["src/cljs" "src/cljc"] + :cljsbuild {:builds {:app {:source-paths ["env/dev/cljs" "src/cljs"] :compiler {:output-to "target/cljsbuild/public/js/app.js" :output-dir "target/cljsbuild/public/js/out" :asset-path "js/out" + :main "omgnata.dev" :optimizations :none :pretty-print true}} - :min {:source-paths ["env/prod/cljs" "src/cljs" "src/cljc"] + :min {:source-paths ["env/prod/cljs" "src/cljs"] :compiler {:output-to "build/js/app.js" :main "omgnata.prod" :optimizations :advanced @@ -76,8 +75,7 @@ org.clojure/tools.analyzer.jvm]] [org.clojure/tools.nrepl "0.2.12"] [com.cemerick/piggieback "0.2.1"] - [pjstadig/humane-test-output "0.7.1"] - ] + [pjstadig/humane-test-output "0.7.1"]] :source-paths ["env/dev/clj"] :plugins [[lein-figwheel "0.5.0-6" @@ -89,8 +87,7 @@ org.clojure/tools.reader org.clojure/clojurescript org.clojure/core.async - org.clojure/tools.analyzer.jvm]] - ] + org.clojure/tools.analyzer.jvm]]] :injections [(require 'pjstadig.humane-test-output) (pjstadig.humane-test-output/activate!)] @@ -98,31 +95,7 @@ :figwheel {:http-server-root "public" :server-port 3449 :nrepl-port 7002 - :nrepl-middleware ["cemerick.piggieback/wrap-cljs-repl" - ] + :nrepl-middleware ["cemerick.piggieback/wrap-cljs-repl"] :css-dirs ["resources/public/css"] - :ring-handler omgnata.handler/app} + :ring-handler omgnata.handler/app}}}) - :env {:dev "true"} - - :cljsbuild {:builds {:app {:source-paths ["env/dev/cljs"] - :compiler {:main "omgnata.dev" - :source-map true}} - - - - } - }} - - :uberjar {:hooks [minify-assets.plugin/hooks] - :source-paths ["env/prod/clj"] - :prep-tasks ["compile" ["cljsbuild" "once"]] - :env {:production "true"} - :aot :all - :omit-source true - :cljsbuild {:jar true - :builds {:app - {:source-paths ["env/prod/cljs"] - :compiler - {:optimizations :advanced - :pretty-print false}}}}}}) diff --git a/src/clj/omgnata/env.clj b/src/clj/omgnata/env.clj deleted file mode 100644 index 84c4b24..0000000 --- a/src/clj/omgnata/env.clj +++ /dev/null @@ -1,6 +0,0 @@ -(ns omgnata.env - (:require [environ.core :refer [env]])) - -(defmacro get-env [kw] - (env kw)) - diff --git a/src/cljc/omgnata/util.cljc b/src/cljc/omgnata/util.cljc deleted file mode 100644 index 34c94ea..0000000 --- a/src/cljc/omgnata/util.cljc +++ /dev/null @@ -1,6 +0,0 @@ -(ns omgnata.util) - -(defn foo-cljc [x] - "I don't do a whole lot." - [x] - (println x "Hello, World!")) diff --git a/src/cljs/omgnata/core.cljs b/src/cljs/omgnata/core.cljs index 57b234a..8a89d20 100644 --- a/src/cljs/omgnata/core.cljs +++ b/src/cljs/omgnata/core.cljs @@ -7,15 +7,13 @@ [goog.events :as events] [goog.history.EventType :as EventType]) (:require-macros - [omgnata.env :refer [get-env]] [cljs.core.async.macros :refer [go]]) (:import goog.History)) (enable-console-print!) -; NOTE: these don't actually work in prod mode yet -(def server-url (if (get-env :dev) (str (.replace (-> js/document .-location .-href) ":3449" ":8000") "server.php") "server.php")) -(def poller-time (if (get-env :dev) 5 30)) +(def server (atom {:url (str (.replace (-> js/document .-location .-href) ":3449" ":8000") "server.php") + :poller-time 5})) (secretary/set-config! :prefix "#") @@ -141,10 +139,10 @@ Server blocks if none since timestamp. Returns a dictionary of :filename to text mappings." (let [c (chan)] - (ajax-request {:uri server-url + (ajax-request {:uri (@server :url) :method :get :params {:timestamp timestamp - :live_for poller-time} + :live_for (@server :poller-time)} :with-credentials true :response-format (json-response-format) :handler #(put! c %)}) @@ -152,7 +150,7 @@ (defn update-file [fname text] "Ask the server to update a particular text file with text contents." - (ajax-request {:uri server-url + (ajax-request {:uri (@server :url) :method :post :format (url-request-format) :params {:filename (str fname ".txt") @@ -168,7 +166,7 @@ (defn delete-file [fname] "Ask the server to delete a single file." ; not RESTful because PHP doesn't support DELETE parameters well - (ajax-request {:uri server-url + (ajax-request {:uri (@server :url) :method :get :params {:delete (str fname ".txt")} :with-credentials true @@ -432,6 +430,11 @@ (defn mount-root [] (reagent/render [current-page] (.getElementById js/document "app"))) -(defn init! [] +(defn init! [& [prod]] + (if prod + (swap! server assoc + :url "server.php" + :poller-time 30) + (js/console.log "dev mode")) (hook-browser-navigation!) (mount-root))