mirror of
https://github.com/penpot/penpot.git
synced 2025-04-04 19:11:20 -05:00
Remove backend code and adapt scripts to new structure.
This commit is contained in:
parent
92a83c2506
commit
32cbe2c1a5
13 changed files with 34 additions and 388 deletions
|
@ -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)))
|
|
@ -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/<! in)
|
||||
result (exc/try-on (decode received))]
|
||||
(if (and (exc/success? result)
|
||||
(= (:cmd @result) :hello))
|
||||
(a/>! out (encode {:cmd :hello}))
|
||||
(do
|
||||
(a/<! (send-decode-error context))
|
||||
(a/close! out))))))
|
||||
|
||||
(def ^:private
|
||||
pong-frames-xform
|
||||
(comp
|
||||
(map decode)
|
||||
(filter #(= (:cmd %) :pong))))
|
||||
|
||||
(def ^:private
|
||||
user-frames-xform
|
||||
(comp
|
||||
(map decode)
|
||||
(filter #(not= (:cmd %) :pong))))
|
||||
|
||||
(defn- pong-frames
|
||||
[mult context]
|
||||
(let [ch (a/chan 1 pong-frames-xform (fn [_] (send-decode-error context)))]
|
||||
(a/tap mult ch true)))
|
||||
|
||||
(defn- user-frames
|
||||
[mult context]
|
||||
(let [ch (a/chan 1 user-frames-xform (fn [_] (send-decode-error context)))]
|
||||
(a/tap mult ch true)))
|
||||
|
||||
(defn- keepalive-loop
|
||||
[{:keys [out] :as context} mult]
|
||||
(let [in (ping-frames mult context)]
|
||||
(a/go-loop []
|
||||
(let [frame {:cmd :ping :id (random-uuid)}]
|
||||
(a/>! out (encode frame))
|
||||
(let [[v ch] (a/alts! [in (a/timeout 1000)])]
|
||||
(if (= ch in)
|
||||
(do
|
||||
(a/<! (a/timeout 1000))
|
||||
(recur))
|
||||
(a/close! out)))))))
|
||||
|
||||
(defn- messages-loop
|
||||
[{:keys [out] :as context} mult]
|
||||
(let [in (user-frames mult context)]
|
||||
(a/go-loop []
|
||||
(when-let [frame (a/<! in)]
|
||||
(let [result (exc/try-on (decode frame))]
|
||||
(if (exc/success? result)
|
||||
(handle-frame @result handler context options)
|
||||
(a/<! (send-decode-error context))))
|
||||
(recur)))))
|
||||
|
||||
(defn- dispatcher-loop
|
||||
[{:keys [in] :as context} handler options]
|
||||
(let [mult (a/mult in)]
|
||||
(keepalive-loop context mult)
|
||||
(messages-loop context mult)))
|
||||
|
||||
(defn- dispatcher
|
||||
[{:keys [in out ctrl] :as context} handler options]
|
||||
(a/go-loop []
|
||||
(when-let [msg (a/<! ctrl)]
|
||||
(if (= msg :close)
|
||||
(let [container (::on-close-handlers context)]
|
||||
(doseq [item @container]
|
||||
(exc/try-on (item)))
|
||||
(reset! container []))
|
||||
(recur))))
|
||||
(a/go
|
||||
(a/<! (initialize context options))
|
||||
|
||||
;; Start dispatcher loop
|
||||
(a/<! (dispatcher-loop context handler options))
|
||||
|
||||
;; closing in any case
|
||||
(a/close! out)))
|
||||
|
||||
(extend-type java.util.concurrent.CompletableFuture
|
||||
IHandlerResponse
|
||||
(-handle-response [response context frameid options]
|
||||
(letfn [(on-resolve [response]
|
||||
(-handle-response response context frameid options))
|
||||
(on-reject [error]
|
||||
(handle-error error frameid context options))]
|
||||
(-> 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))))))
|
|
@ -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))))))
|
||||
|
|
@ -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)))
|
|
@ -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))
|
56
profiles.clj
56
profiles.clj
|
@ -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"]]}]}
|
||||
|
28
project.clj
28
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"]
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue