diff --git a/backend/uxbox/config.clj b/backend/uxbox/config.clj deleted file mode 100644 index cd459f096..000000000 --- a/backend/uxbox/config.clj +++ /dev/null @@ -1,7 +0,0 @@ -(ns uxbox.config - (:require [clojure.java.io :as io] - [nomad :refer [read-config]])) - -(defn component - [path] - (nomad/read-config (io/resource path))) diff --git a/backend/uxbox/impl/routing.clj b/backend/uxbox/impl/routing.clj deleted file mode 100644 index bc89463fb..000000000 --- a/backend/uxbox/impl/routing.clj +++ /dev/null @@ -1,196 +0,0 @@ -(ns uxbox.impl.routing - (:require [clojure.core.async :as a] - [cats.monad.exception :as exc] - [cats.core :as m] - [promissum.core :as p] - [catacumba.core :as ct] - [catacumba.serializers :as sz] - [catacumba.impl.websocket :as ws] - [catacumba.impl.handlers :as hs])) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Helpers -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defn encode - [data] - (sz/bytes->str (sz/encode data :transit+json))) - -(defn decode - [data] - (sz/decode (sz/str->bytes data) :transit+json)) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Protocol Definition -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defprotocol IHandlerResponse - (-handle-response [_ context frameid options] "Handle the response.")) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Implementation -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(declare response) - -(defn- generic-error-handler - [context error] - (if (instance? clojure.lang.ExceptionInfo error) - (response :error {:message (.getMessage error) - :data (ex-data error)}) - (response :error {:message (str error)}))) - -(defn- handle-error - [error frameid context options] - (let [on-error (::on-error options generic-error-handler) - response (on-error context error)] - (-handle-response response context frameid options))) - -(defmulti handle-frame - (fn [frame handler context options] - (:cmd frame))) - -(defmethod handle-frame :default - [frame handler context options] - (let [frameid (:id frame) - response (exc/try-on (handler context frame))] - (if (exc/success? response) - (-handle-response @response context frameid options) - (let [error (m/extract response)] - (handle-error error frameid context options))))) - -(defmethod handle-frame :pong - [frame _ context options] - (let [state (:state context)] - -(defn- send-decode-error - [{:keys [out]}] - (let [frame {:cmd :error :id nil :data "Error on deserializing frame."}] - (a/go (a/>! out (encode frame))))) - -(defn- initialize - [{:keys [in out ctrl] :as context} options] - (a/go - (let [received (a/! out (encode {:cmd :hello})) - (do - (a/! out (encode frame)) - (let [[v ch] (a/alts! [in (a/timeout 1000)])] - (if (= ch in) - (do - (a/ response - (p/then on-resolve) - (p/catch on-reject))))) - -(defrecord Response [data cmd] - IHandlerResponse - (-handle-response [this context frameid options] - (let [frame (into {:id frameid} this) - output (:out context)] - (a/put! output (encode frame))))) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Public Api -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defn response - ([data] - (response :response data)) - ([type data] - (map->Response {:data data :cmd type}))) - -(defn on-close - [context handler] - {:pre [(fn? handler) (::on-close-handlers context)]} - (let [container (::on-close-handlers context)] - (swap! container conj handler))) - -(defn router - ([handler] - (router handler {})) - ([handler options] - (fn [context] - (let [context (assoc context - ::on-close-handlers (atom []) - :state (atom {}))] - (ws/websocket context #(dispatcher % handler options)))))) diff --git a/backend/uxbox/impl/websocket.clj b/backend/uxbox/impl/websocket.clj deleted file mode 100644 index 9ed5de5ae..000000000 --- a/backend/uxbox/impl/websocket.clj +++ /dev/null @@ -1,62 +0,0 @@ -(ns uxbox.impl.websocket - (:require [promissum.core :as p] - [catacumba.impl.context :as ctx] - [catacumba.impl.handlers :as hs]) - (:import ratpack.handling.Handler - ratpack.handling.Context - ratpack.func.Action - ratpack.exec.ExecController - java.util.concurrent.ExecutorService - io.netty.buffer.ByteBuf - catacumba.impl.context.DefaultContext - catacumba.websocket.WebSocketHandler - catacumba.websocket.WebSocketMessage - catacumba.websocket.WebSockets - catacumba.websocket.WebSocket)) - -;; (defrecord WebSocketSession [context state handler wsholder] -;; WebSocketHandler -;; (^void onOpen [this ^WebSocket ws] -;; (vreset! wsholder ws) -;; (let [context (merge context {:state state :ws this})] -;; (handler :open context))) - -;; (^void onMessage [_ ^WebSocketMessage msg ^Action callback] -;; (let [message (.getData msg) -;; context (merge context {:state state :ws this})] -;; (-> (handler :message (assoc context :message message)) -;; (p/then (fn [_] (.execute callback nil))) -;; (p/catch (fn [e] -;; (letfn [(on-error [_] -;; (.execute callback nil) -;; (.close @wsholder 400 (str e)) -;; (vreset! wsholder nil))] -;; (-> (handler :error (assoc context :error e)) -;; (p/then on-error) -;; (p/catch on-error)))))))) - -;; (^void onClose [this] -;; (let [context {:state state :ws this} -;; on-close (fn [_] (vreset! wsholder nil))] -;; (-> (handler :close context) -;; (p/then on-close) -;; (p/catch on-close))))) - -;; (defn send! -;; [ws data] -;; (assert (string? data) "data should be string") -;; (let [sock @(:wsholder ws)] -;; (.send sock data))) - -;; (defn websocket -;; [^DefaultContext context handler] -;; (->> (WebSocketSession. context (atom {}) handler (volatile! nil)) -;; (WebSockets/websocket ^Context (:catacumba/context context))))) - -;; ;; (defmethod hs/adapter :uxbox/websocket -;; ;; [handler] -;; ;; (reify Handler -;; ;; (^void handle [_ ^Context ctx] -;; ;; (hs/hydrate-context ctx (fn [^DefaultContext context] -;; ;; (websocket context handler)))))) - diff --git a/backend/uxbox/main.clj b/backend/uxbox/main.clj deleted file mode 100644 index 15184eb5f..000000000 --- a/backend/uxbox/main.clj +++ /dev/null @@ -1,16 +0,0 @@ -(ns uxbox.main - (:require [com.stuartsierra.component :as component] - [environ.core :refer [env]] - [uxbox.router] - [uxbox.config]) - (:gen-class)) - -(defn system - [] - (component/system-map - :config (uxbox.config/component (:config env)) - :web (uxbox.router/component))) - -(defn -main - [& args] - (component/start (system))) diff --git a/backend/uxbox/router.clj b/backend/uxbox/router.clj deleted file mode 100644 index 6ae683db9..000000000 --- a/backend/uxbox/router.clj +++ /dev/null @@ -1,41 +0,0 @@ -(ns uxbox.router - (:refer-clojure :exclude [error-handler]) - (:require [uxbox.impl.routing :as rt] - [com.stuartsierra.component :as component] - [catacumba.components :refer (catacumba-server assoc-routes!)] - [cats.core :as m] - [promissum.core :as p])) - -(defmulti handler - (fn [context frame] - [(:cmd frame) - (:dest frame)])) - -;; (defmethod handler [:novelty :auth] -;; [context frame] -;; (let [state (:state context) -;; body (:body frame)] -;; (m/mlet [user (authenticate body)] -;; (swap! state assoc :user user) -;; (m/return (rt/response {:ok true}))))) - -;; (defmethod handler [:query :project] -;; [context frame] -;; (let [state (:state context) -;; body (:body frame)] -;; (m/mlet [proj (query-project body)] -;; (m/return (rt/response proj))))) - -(defrecord WebComponent [config server] - component/Lifecycle - (start [this] - (let [routes [[:any "api" (rt/router handler)]]] - (assoc-routes! server ::web routes))) - - (stop [this] - ;; noop - )) - -(defn component - [] - (WebComponent. nil nil)) diff --git a/profiles.clj b/profiles.clj deleted file mode 100644 index ff2cc611f..000000000 --- a/profiles.clj +++ /dev/null @@ -1,56 +0,0 @@ -{ - ;; Development dependencies - :dev - {:dependencies [[org.clojure/tools.namespace "0.2.11"] - [figwheel-sidecar "0.5.0-2" :scope "test"]] - - ;; :plugins [[lein-ancient "0.6.7" :exclusions [org.clojure/tools.reader]]] - :clean-targets ^{:protect false} ["resources/public/js" "target"] - - :env {:config "config.edn"}} - - ;; Common dependencies - - :common - {:dependencies [[org.clojure/clojure "1.7.0"] - [funcool/cats "1.2.1"]]} - - ;; Backend profile - - :back - [:common - {:source-paths ["backend"] - :test-paths ["test/backend"] - :dependencies [[org.clojure/clojure "1.7.0" :scope "provided"] - [org.slf4j/slf4j-simple "1.7.12" :scope "provided"] - [com.stuartsierra/component "0.3.0"] - [funcool/catacumba "0.10.0"] - [jarohen/nomad "0.7.2" :exclusions [org.clojure/tools.reader]] - [danlentz/clj-uuid "0.1.6"] - [com.datomic/datomic-free "0.9.5302" - :exclusions [commons-codec joda-time]] - [environ "1.0.1"] - [aleph "0.4.0"]]}] - - ;; Frontend profile - - :front - [:common - {:source-paths ["frontend"] - :test-paths ["test/frontend"] - :dependencies [[org.clojure/clojurescript "1.7.228"] - [funcool/cuerdas "0.7.1"] - [rum "0.6.0" :exclusions [sablono]] - [sablono "0.5.3"] - [cljsjs/react "0.14.3-0"] - [cljsjs/react-dom "0.14.3-1"] - [cljsjs/react-dom-server "0.14.3-0"] - - [bouncer "1.0.0"] - [funcool/promesa "0.7.0"] - [funcool/beicon "0.5.1"] - [cljsjs/moment "2.10.6-0"] - [figwheel-sidecar "0.5.0-2" :scope "test"] - [bidi "1.21.0"] - [funcool/hodgepodge "0.1.4"]]}]} - diff --git a/project.clj b/project.clj index 562a38909..869b50024 100644 --- a/project.clj +++ b/project.clj @@ -1,6 +1,30 @@ (defproject uxbox "0.1.0-SNAPSHOT" :description "UXBox client" :url "http://uxbox.github.io" - :license {:name "" - :url ""}) + :license {:name "" :url ""} + + :dependencies [[org.clojure/clojure "1.7.0" :scope "provided"] + [org.clojure/clojurescript "1.7.228" :scope "provided"] + [figwheel-sidecar "0.5.0-2" :scope "test"] + + ;; runtime + [rum "0.6.0" :exclusions [sablono]] + [sablono "0.5.3"] + [cljsjs/react "0.14.3-0"] + [cljsjs/react-dom "0.14.3-1"] + [cljsjs/react-dom-server "0.14.3-0"] + [cljsjs/moment "2.10.6-0"] + [funcool/promesa "0.7.0"] + [funcool/beicon "0.5.1"] + [funcool/cats "1.2.1"] + [funcool/cuerdas "0.7.1"] + [funcool/hodgepodge "0.1.4"] + [bouncer "1.0.0"] + [bidi "1.21.0"]] + + :clean-targets ^{:protect false} ["resources/public/js" "target"] + ) + + + diff --git a/scripts/build b/scripts/build index 960e026c7..0b894a2fb 100755 --- a/scripts/build +++ b/scripts/build @@ -1,2 +1,2 @@ #!/bin/sh -lein with-profile +front trampoline run -m clojure.main scripts/build.clj +lein trampoline run -m clojure.main scripts/build.clj diff --git a/scripts/build.clj b/scripts/build.clj index 26307ff41..e5697721e 100644 --- a/scripts/build.clj +++ b/scripts/build.clj @@ -8,11 +8,11 @@ (let [start (System/nanoTime)] (b/build - (b/inputs "frontend") + (b/inputs "src") {:main 'uxbox.core :output-to "resources/public/js/main.js" :output-dir "resources/public/js" - :parallel-build true + :parallel-build false :optimizations :advanced :language-in :ecmascript5 :language-out :ecmascript5 diff --git a/scripts/figwheel b/scripts/figwheel index dee98050f..c26026191 100755 --- a/scripts/figwheel +++ b/scripts/figwheel @@ -1,2 +1,2 @@ #!/bin/bash -rlwrap lein with-profile +front run -m clojure.main scripts/figwheel.clj +rlwrap lein trampoline run -m clojure.main scripts/figwheel.clj diff --git a/scripts/figwheel.clj b/scripts/figwheel.clj index 49fb2a7c9..07c5534de 100644 --- a/scripts/figwheel.clj +++ b/scripts/figwheel.clj @@ -11,7 +11,7 @@ :all-builds [{:id "dev" :figwheel true - :source-paths ["frontend"] + :source-paths ["src"] :compiler {:main 'uxbox.core :asset-path "js" :parallel-build false diff --git a/scripts/watch b/scripts/watch index a2e843f9f..6958be417 100755 --- a/scripts/watch +++ b/scripts/watch @@ -1,2 +1,2 @@ #!/bin/sh -lein with-profile +front trampoline run -m clojure.main scripts/watch.clj +lein trampoline run -m clojure.main scripts/watch.clj diff --git a/scripts/watch.clj b/scripts/watch.clj index 86146f6e3..7b9d36272 100644 --- a/scripts/watch.clj +++ b/scripts/watch.clj @@ -4,11 +4,11 @@ (alter-var-root #'cljs.tagged-literals/*cljs-data-readers* assoc 'ux/tr (fn [v] `(uxbox.locales/tr ~v))) -(b/watch (b/inputs "frontend") +(b/watch (b/inputs "src") {:main 'uxbox.core :output-to "resources/public/js/main.js" :output-dir "resources/public/js" - :parallel-build true + :parallel-build false :asset-path "/js" :optimizations :none :pretty-print true