Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tailwind + ability of options + nubank/workspaces #8

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .lsp/sqlite.db
Binary file not shown.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
A Leiningen template for FIXME.

## Usage

### Base only
`lein new xiana DEFPROJECT-NAME --to-dir ../CUSTOM-DIR`

### With [nubank/workspaces](https://github.com/nubank/workspaces) :
`+workspaces`
Example:
`lein new xiana xi-example +workspaces`

`lein new xiana xi-example --to-dir ../lein-xiana-example`

Expand Down
2 changes: 1 addition & 1 deletion resources/leiningen/new/xiana/dev/cljs/user.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
development."
(:require
[cljs.repl :refer (Error->map apropos dir doc error->str ex-str ex-triage
find-doc print-doc pst source)]
find-doc print-doc pst source)]
[clojure.pprint :refer (pprint)]
[clojure.string :as str]))
1 change: 1 addition & 0 deletions resources/leiningen/new/xiana/gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ pom.xml.asc
.hgignore
.hg/
.idea/
.lsp/
33 changes: 33 additions & 0 deletions resources/leiningen/new/xiana/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"scripts": {
"repl": "shadow-cljs node-repl",
"clean": "rm -rf node_modules/ && rm -rf package-lock.json && rm -rf .shadow-cljs/ && rm -rf resources/public/js && rm -rf .lsp/",
"tests": "shadow-cljs compile ci && npx karma start --single-run",
"build": "shadow-cljs release app",
"serve": "shadow-cljs watch app",
"prebuild": "rm ./resources/public/main.css ; postcss ./src/frontend/base.css -o ./resources/public/main.css --env production",
"preserve": "rm ./rsources/public/main.css ; postcss ./src/frontend/base.css -o ./resources/public/main.css"
},
"dependencies": {
"highlight.js": "9.18.5",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-grid-layout": "1.2.4",
"react-icons": "4.2.0",
"reakit": "1.3.6"
},
"devDependencies": {
"@fullhuman/postcss-purgecss": "^4.0.2",
"autoprefixer": "^10.2.4",
"cssnano": "^4.1.10",
"postcss": "^8.2.8",
"postcss-cli": "^8.3.1",
"postcss-discard-comments": "^4.0.2",
"shadow-cljs": "^2.11.26",
"source-map-support": "^0.4.18",
"tailwindcss": "^2.0.3",
"@sinonjs/fake-timers": "^7.0.2",
"@testing-library/react": "^11.2.5",
"@testing-library/user-event": "^13.0.15"
}
}
24 changes: 24 additions & 0 deletions resources/leiningen/new/xiana/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const tailwindcss = require('tailwindcss');
const discard = require('postcss-discard-comments');
const cssnano = require('cssnano')({
preset: 'default',
})
const purgecss = require('@fullhuman/postcss-purgecss')({
content: [
'./src/frontend/**/*.css',
'./src/frontend/**/*.cljs',
'./resources/public/**/*.css',
],

defaultExtractor: (content) => content.match(/[\w-/:]+(?<!:)/g) || [],
});

module.exports = {
plugins: [
tailwindcss('./tailwind.config.js'),
require('autoprefixer'),
...process.env.NODE_ENV === 'production'
? [purgecss, discard, cssnano]
: [],
],
};
86 changes: 38 additions & 48 deletions resources/leiningen/new/xiana/project.clj
Original file line number Diff line number Diff line change
@@ -1,49 +1,39 @@
(defproject {{sanitized-name}} "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:min-lein-version "2.0.0"
:dependencies [[org.clojure/clojure "1.10.1"]
[com.flexiana/framework "0.1.4"]
[thheller/shadow-cljs "2.11.7"]
[clj-http "3.12.0"]
[reagent "0.10.0"]
[re-frame "1.1.2"]]
:plugins [[lein-shadow "0.3.1"]
[lein-shell "0.5.0"]]
:main ^:skip-aot {{name}}
:uberjar-name "{{name}}.jar"
:source-paths ["src/backend" "src/backend/app" "src/frontend" "src/shared"]
:clean-targets ^{:protect false} ["resources/public/js/compiled" "target"]
:profiles {:dev {:resource-paths ["config/dev"]
:dependencies [[binaryage/devtools "1.0.2"]]}
:local {:resource-paths ["config/local"]}
:prod {:resource-paths ["config/prod"]}
:test {:resource-paths ["config/test"]
:dependencies [[kerodon "0.9.1"]]}}
:shadow-cljs {:nrepl {:port 8777}

:builds {:app {:target :browser
:output-dir "resources/public/js/compiled"
:asset-path "/js/compiled"
:modules {:app {:init-fn {{sanitized-name}}.core/init
:preloads [devtools.preload]}}}}}

;:devtools {:http-root "resources/public"
; :http-port 8280
; :http-handler {{name}}.handler/dev-handler
; }


:aliases {"ci" ["do" "clean," "cloverage," "lint," "uberjar"]
"kondo" ["run" "-m" "clj-kondo.main" "--lint" "src" "test"]
"lint" ["do" "kondo," "eastwood," "kibit"]
"watch" ["with-profile" "dev" "do"
["shadow" "watch" "app" "browser-test" "karma-test"]]
"release" ["with-profile" "prod" "do"
["shadow" "release" "app"]]}
:migratus {:store :database
:migration-dir "migrations"
:db {:classname "com.mysql.jdbc.Driver"
:subprotocol "postgres"
:subname "//localhost/controllers"
:user "postgres"
:password "postgres"}})
:description "FIXME: write description"
:min-lein-version "2.0.0"
:dependencies [[org.clojure/clojure "1.10.1"]
[com.flexiana/framework "0.1.4"]
[thheller/shadow-cljs "2.11.26"]
[clj-http "3.12.0"]
[reagent "0.10.0"]
[re-frame "1.1.2"]]
:plugins [[migratus-lein "0.7.3"]
[lein-shell "0.5.0"]]
:main ^:skip-aot {{name}}
:uberjar-name "{{name}}.jar"
:source-paths ["src/backend" "src/backend/app" "src/frontend" "src/shared"]
:clean-targets ^{:protect false} ["resources/public/js/compiled" "target"]
:profiles {:dev {:resource-paths ["config/dev"]
:dependencies [[binaryage/devtools "1.0.2"]]}
:local {:resource-paths ["config/local"]}
:prod {:resource-paths ["config/prod"]}
:test {:resource-paths ["config/test"]
:dependencies [{{#workspaces?}}[nubank/workspaces "1.0.16"]{{/workspaces?}}
[binaryage/devtools "1.0.2"]
[nubank/matcher-combinators "3.1.4"]
[day8.re-frame/test "0.1.5"]
[kerodon "0.9.1"]]}}
:aliases {"ci" ["do" "clean," "cloverage," "lint," "uberjar"]
"kondo" ["run" "-m" "clj-kondo.main" "--lint" "src" "test"]
"repl" ["with-profile" "+test" "run" "-m" "shadow.cljs.devtools.cli" "server"]
"workspaces" ["with-profile" "+test" "run" "-m" "shadow.cljs.devtools.cli" "watch" "workspaces"]
"app" ["with-profile" "+test" "run" "-m" "shadow.cljs.devtools.cli" "watch" "app"]
"lint" ["do" "kondo," "eastwood," "kibit"]
"release" ["with-profile" "prod" "run" "-m" "shadow.cljs.devtools.cli" "release" "app"]}
:migratus {:store :database
:migration-dir "migrations"
:db {:classname "com.mysql.jdbc.Driver"
:subprotocol "postgres"
:subname "//localhost:5433/frankie"
:user "postgres"
:password "postgres"}})
14 changes: 14 additions & 0 deletions resources/leiningen/new/xiana/resources/public/workspaces.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
</head>
<body>
<div id="app"></div>
<!-- you might need to change the js path depending on your configuration -->
<script src="assets/js/workspaces/main.js" type="text/javascript"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css">
</body>
</html>
17 changes: 17 additions & 0 deletions resources/leiningen/new/xiana/shadow-cljs.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{:lein true
:nrepl {:port 8777}
:builds {:app
{:target :browser
:build-hooks [(hooks/purge-css)
(hooks/npm-init)]
:output-dir "resources/public/js/app"
:asset-path "/js/app"
:modules {:main {:init-fn {{sanitized-name}} .core/init
:preloads [devtools.preload]}}}
{{#workspaces?}}
:workspaces
{:target :browser
:output-dir "resources/public/js/workspaces"
:asset-path "/js/workspaces"
:modules {:main {:entries [{{sanitized-name}}.workspaces]
:preloads [devtools.preload]}}} {{/workspaces?}}}}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
(ns controllers.index
(:require [xiana.core :as xiana]
[ring.util.response :as ring]))
(:require
[ring.util.response :as ring]
[xiana.core :as xiana]))


(defn handle-index
[state]
(xiana/ok
(assoc state
:response
(ring/response "Index page"))))
:response
(ring/response "Index page"))))
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
(ns controllers.re-frame
(:require [xiana.core :as xiana]
[ring.util.response :as ring]))

(defn handle-index
{{#workspaces?}}
(defn handle-workspaces
[state]
(xiana/ok
(assoc state
:response
(-> "index.html"
(-> "workspaces.html"
(ring/resource-response {:root "public"})
(ring/header "Content-Type" "text/html; charset=utf-8")))))
(ring/header "Content-Type" "text/html; charset=utf-8"))))){{/workspaces?}}

(defn handle-index
[state]
(xiana/ok
(assoc state
:response
(-> "index.html"
(ring/resource-response {:root "public"})
(ring/header "Content-Type" "text/html; charset=utf-8")))))
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
[potemkin :refer [import-vars]]
[xiana.core :as xiana]))


(comment
(import-vars
[framework.components.app.interceptors
sample-router-interceptor
sample-controller-interceptor]))

(def sample-{{sanitized-name}}-controller-interceptor

(def sample-
{{sanitized-name}} -controller-interceptor
{:enter (fn [{request :request {:keys [handler controller match]} :request-data :as state}]
(xiana/ok state))})
(xiana/ok state))})
14 changes: 14 additions & 0 deletions resources/leiningen/new/xiana/src/backend/app_name.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
(def routes
[["/" {:controller index/handle-index}]
["/re-frame" {:controller re-frame/handle-index}]
{{#workspaces?}}["/workspaces" {:controller re-frame/handle-workspaces}]{{/workspaces?}}
["/assets/*" (ring/create-resource-handler)]])

(defn system
Expand All @@ -39,3 +40,16 @@
[& _args]
(let [config (config/edn)]
(component/start (system config))))

(def st
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My preference is defonce in this place

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed it to defonce

(-> (config/edn)
system
atom))

(defn- start-dev-system
[]
(swap! st component/start))

(defn- stop-dev-system
[]
(swap! st component/stop))
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
(defn main-panel []
(let [name (re-frame/subscribe [::subs/name])]
[:div
[:h1 "Hello from " @name]
[:h1 {:data-testid "hello"}
"Hello from " @name]
]))
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(ns {{sanitized-name}}.workspaces
(:require
[{{sanitized-name}}.events :as events]
[{{sanitized-name}}.views :as views]
[nubank.workspaces.card-types.react :refer [react-card]]
[nubank.workspaces.core :as ws]
[nubank.workspaces.model :as wsm]
[re-frame.core :as re-frame]
[reagent.core :as r]))

(defonce init (ws/mount))

(re-frame/clear-subscription-cache!)

(ws/defcard init-card
(re-frame/dispatch-sync [::events/initialize-db])
(react-card
(r/as-element [views/main-panel])))
3 changes: 3 additions & 0 deletions resources/leiningen/new/xiana/src/frontend/base.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
46 changes: 46 additions & 0 deletions resources/leiningen/new/xiana/src/frontend/hooks.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
(ns hooks
(:require
[clojure.java.io :as io]
[clojure.java.shell :refer [sh]]
[clojure.string :as s]))


(defn exec
[& cmd]
(let [cmd (s/split (s/join " " (flatten cmd)) #"\s+")
_ (println (s/join " " cmd))
{:keys [exit out err]} (apply sh cmd)]
(if (zero? exit)
(when-not (s/blank? out)
(println out))
(println err))))


(defn npm-init
{:shadow.build/stage :configure}
[build-state]
(if-not (and (.isDirectory (io/file "node_modules"))
(not (= 0 (count (.list (io/file "node_modules"))))))
(do (println ";;=>> 'Installing node_modules...")
(exec "npm install")
build-state)
(do (println ";;=>> 'npm is already initialized in the current project'")
build-state)))


(defn purge-css
{:shadow.build/stage :flush}
[build-state]
(case (:shadow.build/mode build-state)
:release
(do
(println ";;=> 'Running prebuild script with -env production'")
(exec "npm run-script prebuild")
build-state)
:dev
(if (not (.exists (io/file "resources/public/main.css")))
(do
(println ";;=> 'Runnnig preserve script'")
(exec "npm run-script preserve")
build-state)
build-state)))
13 changes: 13 additions & 0 deletions resources/leiningen/new/xiana/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const colors = require('tailwindcss/colors')

module.exports ={
darkMode: 'class',
theme: {},
variants: {},
plugins: [],
purge: {enabled: false},
future: {
removeDeprecatedGapUtilities: true,
prugeLayersByDefault: true,
},
};
Loading