From 52b0b2eba40209219c3835322a5b233a7e470670 Mon Sep 17 00:00:00 2001 From: Juho Teperi Date: Wed, 18 Oct 2017 14:25:41 +0300 Subject: [PATCH] Fix demo site build script, stop usinn lein profile merging --- .gitignore | 9 +- build-example-site.sh | 39 +++++ circle.yml | 6 + demo/reagentdemo/core.cljs | 17 +- demo/reagentdemo/dev.cljs | 9 ++ demo/sitetools/core.cljs | 2 +- demo/sitetools/prerender.cljs | 6 +- package.json | 1 + project.clj | 146 +++++++++--------- .../browser-node-react-16/test.sh | 4 +- test-environments/browser-node/test.sh | 4 +- test-environments/browser-umd-prod/test.sh | 5 +- .../browser-umd-react-16/figwheel.sh | 2 +- .../browser-umd-react-16/test.sh | 4 +- test-environments/browser-umd/test.sh | 4 +- test-environments/node/test.sh | 6 +- test/reagenttest/runtests.cljs | 12 +- 17 files changed, 164 insertions(+), 112 deletions(-) create mode 100755 build-example-site.sh create mode 100644 demo/reagentdemo/dev.cljs diff --git a/.gitignore b/.gitignore index c8acff9..8d9967c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,21 +4,14 @@ pom.xml pom.xml.asc .nrepl-port demo/empty.cljs -outsite/public/index.html -outsite/public/js -outsite/public/news -outsite/public/css out +tmp figwheel_server.log reagent.iml .idea .lein-failures -outsite/bundle.js -outsite/bundle.min.js node_modules -pre-render -test-environments/*/outsite test-environments/*/junit diff --git a/build-example-site.sh b/build-example-site.sh new file mode 100755 index 0000000..4cebe26 --- /dev/null +++ b/build-example-site.sh @@ -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 diff --git a/circle.yml b/circle.yml index d948a58..0b9eb23 100644 --- a/circle.yml +++ b/circle.yml @@ -14,3 +14,9 @@ dependencies: test: override: - ./run-tests.sh +deployment: + master: + # branch: master + branch: new-test-runner + commands: + - ./build-example-site.sh diff --git a/demo/reagentdemo/core.cljs b/demo/reagentdemo/core.cljs index 6245034..b8de283 100644 --- a/demo/reagentdemo/core.cljs +++ b/demo/reagentdemo/core.cljs @@ -5,9 +5,7 @@ [reagentdemo.common :as common :refer [demo-component]] [reagentdemo.intro :as intro] [reagentdemo.news :as news] - [reagenttest.runtests :as tests] - [reagent.debug :refer-macros [dbg println]] - [doo.runner :as doo])) + [reagent.debug :refer-macros [dbg println]])) (def github {:href "https://github.com/reagent-project/reagent"}) @@ -23,8 +21,7 @@ (tools/register-page index-page [#'intro/main] title) - -(defn demo [] +(defn demo [& [test-component]] [:div [:div.nav>ul.nav [:li.brand [link {:href index-page} "Reagent:"]] @@ -32,16 +29,12 @@ [:li [link {:href news/url} "News"]] [:li>a github "GitHub"] [:li [:a {:href "http://reagent-project.github.io/docs/master/"} "API"]]] - [:div @tests/test-results-component] + [:div test-component] [tools/main-content] [github-badge]]) -(defn init! [] - (doo/set-exit-point! (fn [success?] nil)) - (tests/init!) - (tools/start! {:body [#'demo] +(defn init! [& [test-component]] + (tools/start! {:body [#'demo test-component] :title-prefix "Reagent: " :css-infiles ["site/public/css/examples.css" "site/public/css/main.css"]})) - -(init!) diff --git a/demo/reagentdemo/dev.cljs b/demo/reagentdemo/dev.cljs new file mode 100644 index 0000000..b679d10 --- /dev/null +++ b/demo/reagentdemo/dev.cljs @@ -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!) diff --git a/demo/sitetools/core.cljs b/demo/sitetools/core.cljs index aa0e227..acf741a 100644 --- a/demo/sitetools/core.cljs +++ b/demo/sitetools/core.cljs @@ -16,7 +16,7 @@ (defonce config (r/atom {:body [#'main-content] :pages {"/index.html" {:content [:div] :title ""}} - :site-dir "outsite/public" + :site-dir "target/prerender/public/" :css-infiles ["site/public/css/main.css"] :css-file "css/built.css" :js-file "js/main.js" diff --git a/demo/sitetools/prerender.cljs b/demo/sitetools/prerender.cljs index e2570d5..20cdc32 100644 --- a/demo/sitetools/prerender.cljs +++ b/demo/sitetools/prerender.cljs @@ -2,10 +2,11 @@ (:require [reagent.debug :refer-macros [log]] [sitetools.core :as tools] [sitetools.server :as server] - reagentdemo.core)) + [reagentdemo.core :as demo])) (defn -main [& args] (log "Generating site") + (demo/init!) (let [conf @tools/config conf (assoc conf :timestamp (str "?" (js/Date.now))) {:keys [site-dir pages]} conf] @@ -13,6 +14,7 @@ (server/write-file (->> f tools/to-relative (server/path-join site-dir)) (server/gen-page f conf))) (server/write-resources site-dir conf)) - (log "Wrote site")) + (log "Wrote site") + (js/process.exit 0)) (set! *main-cli-fn* -main) diff --git a/package.json b/package.json index 11da062..bb67f62 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,5 @@ { + "private": true, "devDependencies": { "karma": "^1.7.1", "karma-chrome-launcher": "^2.2.0", diff --git a/project.clj b/project.clj index 91fce57..6703ee6 100644 --- a/project.clj +++ b/project.clj @@ -15,7 +15,8 @@ :plugins [[lein-cljsbuild "1.1.7"] [lein-doo "0.1.8"] - [lein-codox "0.10.3"]] + [lein-codox "0.10.3"] + [lein-figwheel "0.5.14"]] :source-paths ["src"] @@ -23,79 +24,86 @@ :exclude clojure.string :source-paths ["src"]} - :profiles {:node-test [:test {:cljsbuild - {: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"] + :profiles {:react-16 {:dependencies [[cljsjs/react "16.0.0-0"] [cljsjs/react-dom "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"] [doo "0.1.8"]] - :plugins [[lein-figwheel "0.5.14"]] - :source-paths ["demo"] ;; for lighttable - :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"}}}}}} + :source-paths ["demo" "examples/todomvc/src" "examples/simple/src" "examples/geometry/src"] + :resource-paths ["site" "target/cljsbuild/client"]}} - :clean-targets ^{:protect false} [:target-path :compile-path - "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}}}} + :clean-targets ^{:protect false} [:target-path :compile-path "out"] :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}}}}}) diff --git a/test-environments/browser-node-react-16/test.sh b/test-environments/browser-node-react-16/test.sh index 9821631..de9d206 100755 --- a/test-environments/browser-node-react-16/test.sh +++ b/test-environments/browser-node-react-16/test.sh @@ -1,4 +1,4 @@ #!/bin/bash set -ex -lein with-profile test do clean, doo chrome-headless client once -test -f out/node_modules/react/index.js +lein do clean, doo chrome-headless test once +test -f target/cljsbuild/test/out/node_modules/react/index.js diff --git a/test-environments/browser-node/test.sh b/test-environments/browser-node/test.sh index 0bc23c0..37382b2 100755 --- a/test-environments/browser-node/test.sh +++ b/test-environments/browser-node/test.sh @@ -1,4 +1,4 @@ #!/bin/bash set -ex -lein with-profile test do clean, doo chrome-headless client once -test -f out/node_modules/react/react.js +lein do clean, doo chrome-headless test once +test -f target/cljsbuild/test/out/node_modules/react/react.js diff --git a/test-environments/browser-umd-prod/test.sh b/test-environments/browser-umd-prod/test.sh index c56065a..8b1f932 100755 --- a/test-environments/browser-umd-prod/test.sh +++ b/test-environments/browser-umd-prod/test.sh @@ -1,3 +1,4 @@ #!/bin/bash -set -ex -lein with-profile prod-test do clean, doo chrome-headless client once +set -x +lein do clean, doo chrome-headless prod-test once +test -f target/cljsbuild/prod-test/main.js diff --git a/test-environments/browser-umd-react-16/figwheel.sh b/test-environments/browser-umd-react-16/figwheel.sh index ea936de..c1668bb 100755 --- a/test-environments/browser-umd-react-16/figwheel.sh +++ b/test-environments/browser-umd-react-16/figwheel.sh @@ -1,3 +1,3 @@ #!/bin/bash set -x -lein with-profile dev,react-16 figwheel +lein with-profile react-16 figwheel diff --git a/test-environments/browser-umd-react-16/test.sh b/test-environments/browser-umd-react-16/test.sh index d857147..bb6e43b 100755 --- a/test-environments/browser-umd-react-16/test.sh +++ b/test-environments/browser-umd-react-16/test.sh @@ -1,4 +1,4 @@ #!/bin/bash set -ex -lein with-profile react-16,test do clean, doo chrome-headless client once -test -f out/cljsjs/react/development/react.inc.js +lein with-profile dev,react-16 do clean, doo chrome-headless test once +test -f target/cljsbuild/test/out/cljsjs/react/development/react.inc.js diff --git a/test-environments/browser-umd/test.sh b/test-environments/browser-umd/test.sh index 316d027..247b957 100755 --- a/test-environments/browser-umd/test.sh +++ b/test-environments/browser-umd/test.sh @@ -1,4 +1,4 @@ #!/bin/bash set -ex -lein with-profile test do clean, doo chrome-headless client once -test -f out/cljsjs/react/development/react.inc.js +lein do clean, doo chrome-headless test once +test -f target/cljsbuild/test/out/cljsjs/react/development/react.inc.js diff --git a/test-environments/node/test.sh b/test-environments/node/test.sh index 95c9825..2565701 100755 --- a/test-environments/node/test.sh +++ b/test-environments/node/test.sh @@ -1,5 +1,5 @@ #!/bin/bash set -ex -lein with-profile node-test do clean, doo node client once -test ! -f out/node_modules/react/index.js -grep "reagent.impl.template.node\$module\$react = require('react')" out/reagent/impl/template.js +lein do clean, doo node node-test once +test ! -f target/cljsbuild/node-test/out/node_modules/react/index.js +grep "reagent.impl.template.node\$module\$react = require('react')" target/cljsbuild/node-test/out/reagent/impl/template.js diff --git a/test/reagenttest/runtests.cljs b/test/reagenttest/runtests.cljs index 6760197..43a4e3e 100644 --- a/test/reagenttest/runtests.cljs +++ b/test/reagenttest/runtests.cljs @@ -8,7 +8,7 @@ [reagenttest.testwithlet] [reagenttest.testwrap] [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.debug :refer-macros [dbg log]] [sitetools.server])) @@ -49,13 +49,13 @@ (:fail res) " failures, " (:error res) " errors."]) "testing")])) -(def test-results-component (r/atom nil)) - (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)) - ;; Only run with :load-tests true - (reset! test-results-component [#'test-output-mini]) - (run-tests))) + (doo/set-exit-point! (fn [success?] nil)) + (run-tests) + [#'test-output-mini])) (doo-tests 'reagenttest.testreagent 'reagenttest.testcursor