Fix demo site build script, stop usinn lein profile merging

This commit is contained in:
Juho Teperi 2017-10-18 14:25:41 +03:00
parent 03ff2ffe87
commit 52b0b2eba4
17 changed files with 164 additions and 112 deletions

9
.gitignore vendored
View File

@ -4,21 +4,14 @@ pom.xml
pom.xml.asc pom.xml.asc
.nrepl-port .nrepl-port
demo/empty.cljs demo/empty.cljs
outsite/public/index.html
outsite/public/js
outsite/public/news
outsite/public/css
out out
tmp
figwheel_server.log figwheel_server.log
reagent.iml reagent.iml
.idea .idea
.lein-failures .lein-failures
outsite/bundle.js
outsite/bundle.min.js
node_modules node_modules
pre-render
test-environments/*/outsite
test-environments/*/junit test-environments/*/junit

39
build-example-site.sh Executable file
View File

@ -0,0 +1,39 @@
#!/bin/bash
set -ex
SHA=$(git rev-parse HEAD)
# sanity check
rm -fr tmp
git clone git@github.com:reagent-project/reagent-project.github.io.git tmp
rm -fr tmp/*
# Prerendering seems to work best on React 16
cd test-environments/browser-node-react-16
lein do clean, cljsbuild once prod
cp -r target/cljsbuild/prod/public/* ../../tmp/
lein cljsbuild once prerender
node target/cljsbuild/prerender/main.js
cp -r target/prerender/public/* ../../tmp/
cd ../..
test -f tmp/index.html
test -f tmp/js/main.js
test ! -e tmp/js/out
lein codox
mkdir -p tmp/docs/master/
cp -r target/doc/* tmp/docs/master/
cd tmp
git checkout -- README.md
git add .
git commit -m "Built site from $SHA"
# git push
# rm -rf tmp

View File

@ -14,3 +14,9 @@ dependencies:
test: test:
override: override:
- ./run-tests.sh - ./run-tests.sh
deployment:
master:
# branch: master
branch: new-test-runner
commands:
- ./build-example-site.sh

View File

@ -5,9 +5,7 @@
[reagentdemo.common :as common :refer [demo-component]] [reagentdemo.common :as common :refer [demo-component]]
[reagentdemo.intro :as intro] [reagentdemo.intro :as intro]
[reagentdemo.news :as news] [reagentdemo.news :as news]
[reagenttest.runtests :as tests] [reagent.debug :refer-macros [dbg println]]))
[reagent.debug :refer-macros [dbg println]]
[doo.runner :as doo]))
(def github {:href "https://github.com/reagent-project/reagent"}) (def github {:href "https://github.com/reagent-project/reagent"})
@ -23,8 +21,7 @@
(tools/register-page index-page [#'intro/main] title) (tools/register-page index-page [#'intro/main] title)
(defn demo [& [test-component]]
(defn demo []
[:div [:div
[:div.nav>ul.nav [:div.nav>ul.nav
[:li.brand [link {:href index-page} "Reagent:"]] [:li.brand [link {:href index-page} "Reagent:"]]
@ -32,16 +29,12 @@
[:li [link {:href news/url} "News"]] [:li [link {:href news/url} "News"]]
[:li>a github "GitHub"] [:li>a github "GitHub"]
[:li [:a {:href "http://reagent-project.github.io/docs/master/"} "API"]]] [:li [:a {:href "http://reagent-project.github.io/docs/master/"} "API"]]]
[:div @tests/test-results-component] [:div test-component]
[tools/main-content] [tools/main-content]
[github-badge]]) [github-badge]])
(defn init! [] (defn init! [& [test-component]]
(doo/set-exit-point! (fn [success?] nil)) (tools/start! {:body [#'demo test-component]
(tests/init!)
(tools/start! {:body [#'demo]
:title-prefix "Reagent: " :title-prefix "Reagent: "
:css-infiles ["site/public/css/examples.css" :css-infiles ["site/public/css/examples.css"
"site/public/css/main.css"]})) "site/public/css/main.css"]}))
(init!)

View File

@ -0,0 +1,9 @@
(ns reagentdemo.dev
"Initializes the demo app, and runs the tests."
(:require [reagentdemo.core :as core]
[reagenttest.runtests :as tests]))
(defn init! []
(core/init! (tests/init!)))
(init!)

View File

@ -16,7 +16,7 @@
(defonce config (r/atom {:body [#'main-content] (defonce config (r/atom {:body [#'main-content]
:pages {"/index.html" {:content [:div] :pages {"/index.html" {:content [:div]
:title ""}} :title ""}}
:site-dir "outsite/public" :site-dir "target/prerender/public/"
:css-infiles ["site/public/css/main.css"] :css-infiles ["site/public/css/main.css"]
:css-file "css/built.css" :css-file "css/built.css"
:js-file "js/main.js" :js-file "js/main.js"

View File

@ -2,10 +2,11 @@
(:require [reagent.debug :refer-macros [log]] (:require [reagent.debug :refer-macros [log]]
[sitetools.core :as tools] [sitetools.core :as tools]
[sitetools.server :as server] [sitetools.server :as server]
reagentdemo.core)) [reagentdemo.core :as demo]))
(defn -main [& args] (defn -main [& args]
(log "Generating site") (log "Generating site")
(demo/init!)
(let [conf @tools/config (let [conf @tools/config
conf (assoc conf :timestamp (str "?" (js/Date.now))) conf (assoc conf :timestamp (str "?" (js/Date.now)))
{:keys [site-dir pages]} conf] {:keys [site-dir pages]} conf]
@ -13,6 +14,7 @@
(server/write-file (->> f tools/to-relative (server/path-join site-dir)) (server/write-file (->> f tools/to-relative (server/path-join site-dir))
(server/gen-page f conf))) (server/gen-page f conf)))
(server/write-resources site-dir conf)) (server/write-resources site-dir conf))
(log "Wrote site")) (log "Wrote site")
(js/process.exit 0))
(set! *main-cli-fn* -main) (set! *main-cli-fn* -main)

View File

@ -1,4 +1,5 @@
{ {
"private": true,
"devDependencies": { "devDependencies": {
"karma": "^1.7.1", "karma": "^1.7.1",
"karma-chrome-launcher": "^2.2.0", "karma-chrome-launcher": "^2.2.0",

View File

@ -15,7 +15,8 @@
:plugins [[lein-cljsbuild "1.1.7"] :plugins [[lein-cljsbuild "1.1.7"]
[lein-doo "0.1.8"] [lein-doo "0.1.8"]
[lein-codox "0.10.3"]] [lein-codox "0.10.3"]
[lein-figwheel "0.5.14"]]
:source-paths ["src"] :source-paths ["src"]
@ -23,79 +24,86 @@
:exclude clojure.string :exclude clojure.string
:source-paths ["src"]} :source-paths ["src"]}
:profiles {:node-test [:test {:cljsbuild :profiles {:react-16 {:dependencies [[cljsjs/react "16.0.0-0"]
{:builds {:client {:compiler {:target :nodejs
:process-shim false}}}}}]
:test {:cljsbuild
{:builds {:client {:compiler {:main "reagenttest.runtests"}}}}}
:react-16 {:dependencies [[cljsjs/react "16.0.0-0"]
[cljsjs/react-dom "16.0.0-0"] [cljsjs/react-dom "16.0.0-0"]
[cljsjs/react-dom-server "16.0.0-0"]]} [cljsjs/react-dom-server "16.0.0-0"]]}
:site {:resource-paths ^:replace ["outsite"]
:figwheel {:css-dirs ^:replace ["outsite/public/css"]}}
:prod [:site
{:cljsbuild
{:builds {:client
{:compiler {:optimizations :advanced
:elide-asserts true
:pretty-print false
;; :pseudo-names true
:output-dir "target/client"}}}}}]
:prerender [:prod
{:cljsbuild
{:builds {:client
{:compiler {:main "sitetools.prerender"
:target :nodejs
;; Undefine module and exports so React UMD modules work on Node
:output-to "pre-render/main.js"
:output-dir "pre-render/out"}}}}}]
:prod-test [:prod :test]
:dev {:dependencies [[figwheel "0.5.14"] :dev {:dependencies [[figwheel "0.5.14"]
[doo "0.1.8"]] [doo "0.1.8"]]
:plugins [[lein-figwheel "0.5.14"]] :source-paths ["demo" "examples/todomvc/src" "examples/simple/src" "examples/geometry/src"]
:source-paths ["demo"] ;; for lighttable :resource-paths ["site" "target/cljsbuild/client"]}}
:resource-paths ["site" "outsite"]
:figwheel {:css-dirs ["site/public/css"]}
:cljsbuild
{:builds
{:client
{:figwheel true
:compiler {:source-map true
:optimizations :none
;; :recompile-dependents false
:output-dir "outsite/public/js/out"
:asset-path "js/out"}}}}}}
:clean-targets ^{:protect false} [:target-path :compile-path :clean-targets ^{:protect false} [:target-path :compile-path "out"]
"outsite/public/js"
"outsite/public/site"
"outsite/public/news"
"outsite/public/css"
"outsite/public/index.html"
"out"
"pre-render"]
:cljsbuild {:builds {:client
{:source-paths ["src"
"demo"
"test"
"examples/todomvc/src"
"examples/simple/src"
"examples/geometry/src"]
:compiler {:parallel-build true
:main "reagentdemo.core"
:output-to "outsite/public/js/main.js"
:language-in :ecmascript6
:language-out :ecmascript3
;; Add process.env.NODE_ENV preload
:process-shim true}}}}
:figwheel {:http-server-root "public" ;; assumes "resources" :figwheel {:http-server-root "public" ;; assumes "resources"
:repl false}) :css-dirs ["site/public/css"]
:repl false}
;; No profiles and merging - just manual configuration for each build type
:cljsbuild
{:builds
{:client
{:source-paths ["demo" "test"]
:figwheel true
:compiler {:parallel-build true
:source-map true
:optimizations :none
; :main "reagentdemo.core"
:main "reagentdemo.dev"
:output-dir "target/cljsbuild/client/public/js/out"
:output-to "target/cljsbuild/client/public/js/main.js"
:asset-path "js/out"
;; add process.env.node_env preload
:process-shim true}}
:test
{:source-paths ["test"]
:compiler {:parallel-build true
:source-map true
:optimizations :none
:main "reagenttest.runtests"
:asset-path "js/out"
:output-dir "target/cljsbuild/test/out"
:output-to "target/cljsbuild/test/main.js"
;; add process.env.node_env preload
:process-shim true}}
:prerender
{:source-paths ["demo"]
:compiler {:main "sitetools.prerender"
:target :nodejs
:process-shim false
:output-dir "target/cljsbuild/prerender/out"
:output-to "target/cljsbuild/prerender/main.js"}}
:node-test
{:source-paths ["test"]
:compiler {:main "reagenttest.runtests"
:target :nodejs
:parallel-build true
:source-map true
:optimizations :none
:output-dir "target/cljsbuild/node-test/out"
:output-to "target/cljsbuild/node-test/main.js"}}
:prod
{:source-paths ["demo"]
:compiler {:main "reagentdemo.core"
:optimizations :advanced
:elide-asserts true
:pretty-print false
;; :pseudo-names true
:output-to "target/cljsbuild/prod/public/js/main.js"
:output-dir "target/cljsbuild/prod/out" ;; Outside of public, not published
:closure-warnings {:global-this :off}}}
:prod-test
{:source-paths ["demo"]
:compiler {:main "reagenttest.runtests"
:optimizations :advanced
:elide-asserts true
:pretty-print false
;; :pseudo-names true
:output-to "target/cljsbuild/prod-test/main.js"
:output-dir "target/cljsbuild/prod-test/out"
:closure-warnings {:global-this :off}}}}})

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/bash
set -ex set -ex
lein with-profile test do clean, doo chrome-headless client once lein do clean, doo chrome-headless test once
test -f out/node_modules/react/index.js test -f target/cljsbuild/test/out/node_modules/react/index.js

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/bash
set -ex set -ex
lein with-profile test do clean, doo chrome-headless client once lein do clean, doo chrome-headless test once
test -f out/node_modules/react/react.js test -f target/cljsbuild/test/out/node_modules/react/react.js

View File

@ -1,3 +1,4 @@
#!/bin/bash #!/bin/bash
set -ex set -x
lein with-profile prod-test do clean, doo chrome-headless client once lein do clean, doo chrome-headless prod-test once
test -f target/cljsbuild/prod-test/main.js

View File

@ -1,3 +1,3 @@
#!/bin/bash #!/bin/bash
set -x set -x
lein with-profile dev,react-16 figwheel lein with-profile react-16 figwheel

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/bash
set -ex set -ex
lein with-profile react-16,test do clean, doo chrome-headless client once lein with-profile dev,react-16 do clean, doo chrome-headless test once
test -f out/cljsjs/react/development/react.inc.js test -f target/cljsbuild/test/out/cljsjs/react/development/react.inc.js

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/bash
set -ex set -ex
lein with-profile test do clean, doo chrome-headless client once lein do clean, doo chrome-headless test once
test -f out/cljsjs/react/development/react.inc.js test -f target/cljsbuild/test/out/cljsjs/react/development/react.inc.js

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
set -ex set -ex
lein with-profile node-test do clean, doo node client once lein do clean, doo node node-test once
test ! -f out/node_modules/react/index.js test ! -f target/cljsbuild/node-test/out/node_modules/react/index.js
grep "reagent.impl.template.node\$module\$react = require('react')" out/reagent/impl/template.js grep "reagent.impl.template.node\$module\$react = require('react')" target/cljsbuild/node-test/out/reagent/impl/template.js

View File

@ -8,7 +8,7 @@
[reagenttest.testwithlet] [reagenttest.testwithlet]
[reagenttest.testwrap] [reagenttest.testwrap]
[cljs.test :as test :include-macros true] [cljs.test :as test :include-macros true]
[doo.runner :refer-macros [doo-tests]] [doo.runner :as doo :refer-macros [doo-tests]]
[reagent.core :as r] [reagent.core :as r]
[reagent.debug :refer-macros [dbg log]] [reagent.debug :refer-macros [dbg log]]
[sitetools.server])) [sitetools.server]))
@ -49,13 +49,13 @@
(:fail res) " failures, " (:error res) " errors."]) (:fail res) " failures, " (:error res) " errors."])
"testing")])) "testing")]))
(def test-results-component (r/atom nil))
(defn init! [] (defn init! []
;; This function is only used when running tests from the demo app.
;; Which is why exit-point is set manually.
(when (some? (test/deftest empty-test)) (when (some? (test/deftest empty-test))
;; Only run with :load-tests true (doo/set-exit-point! (fn [success?] nil))
(reset! test-results-component [#'test-output-mini]) (run-tests)
(run-tests))) [#'test-output-mini]))
(doo-tests 'reagenttest.testreagent (doo-tests 'reagenttest.testreagent
'reagenttest.testcursor 'reagenttest.testcursor