Browse Source

empty project, frontend and backend

Brandon Wong 4 years ago
commit
e10d728a8d

+ 17 - 0
frontend/.gitignore

@@ -0,0 +1,17 @@
+/target
+/classes
+/checkouts
+profiles.clj
+pom.xml
+pom.xml.asc
+*.jar
+*.class
+/.lein-*
+/.nrepl-port
+/resources/public/js
+/public/js
+/out
+/.repl
+*.log
+/.env
+*.swp

+ 22 - 0
frontend/LICENSE

@@ -0,0 +1,22 @@
+The MIT License (MIT)
+
+Copyright (c) 2014 reagent-project
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+

+ 22 - 0
frontend/README.md

@@ -0,0 +1,22 @@
+
+### Development mode
+To start the Figwheel compiler, navigate to the project folder and run the following command in the terminal:
+
+```
+lein figwheel
+```
+
+Figwheel will automatically push cljs changes to the browser.
+Once Figwheel starts up, you should be able to open the `public/index.html` page in the browser.
+
+### REPL
+
+The project is setup to start nREPL on port `7002` once Figwheel starts.
+Once you connect to the nREPL, run `(cljs)` to switch to the ClojureScript REPL.
+
+### Building for production
+
+```
+lein clean
+lein package
+```

+ 11 - 0
frontend/env/dev/clj/user.clj

@@ -0,0 +1,11 @@
+(ns user
+ (:require [figwheel-sidecar.repl-api :as ra]))
+
+(defn start-fw []
+ (ra/start-figwheel!))
+
+(defn stop-fw []
+ (ra/stop-figwheel!))
+
+(defn cljs []
+ (ra/cljs-repl))

+ 15 - 0
frontend/env/dev/cljs/microtables_frontend/dev.cljs

@@ -0,0 +1,15 @@
+(ns ^:figwheel-no-load microtables-frontend.dev
+  (:require
+    [microtables-frontend.core :as core]
+    [devtools.core :as devtools]))
+
+(extend-protocol IPrintWithWriter
+  js/Symbol
+  (-pr-writer [sym writer _]
+    (-write writer (str "\"" (.toString sym) "\""))))
+
+(enable-console-print!)
+
+(devtools/install!)
+
+(core/init!)

+ 8 - 0
frontend/env/prod/cljs/microtables_frontend/prod.cljs

@@ -0,0 +1,8 @@
+(ns microtables-frontend.prod
+  (:require
+    [microtables-frontend.core :as core]))
+
+;;ignore println statements in prod
+(set! *print-fn* (fn [& _]))
+
+(core/init!)

+ 56 - 0
frontend/project.clj

@@ -0,0 +1,56 @@
+(defproject microtables-frontend "0.1.0-SNAPSHOT"
+  :description "FIXME: write description"
+  :url "http://example.com/FIXME"
+  :license {:name "Eclipse Public License"
+            :url "http://www.eclipse.org/legal/epl-v10.html"}
+
+  :dependencies [[org.clojure/clojure "1.10.1"]
+                 [org.clojure/clojurescript "1.10.520"]
+                 [reagent "0.8.1"]]
+
+  :plugins [[lein-cljsbuild "1.1.7"]
+            [lein-figwheel "0.5.19"]]
+
+  :clean-targets ^{:protect false}
+
+  [:target-path
+   [:cljsbuild :builds :app :compiler :output-dir]
+   [:cljsbuild :builds :app :compiler :output-to]]
+
+  :resource-paths ["public"]
+
+
+  :figwheel {:http-server-root "."
+             :nrepl-port 7002
+             :nrepl-middleware [cider.piggieback/wrap-cljs-repl]
+             :css-dirs ["public/css"]}
+
+  :cljsbuild {:builds {:app
+                       {:source-paths ["src" "env/dev/cljs"]
+                        :compiler
+                        {:main "microtables-frontend.dev"
+                         :output-to "public/js/app.js"
+                         :output-dir "public/js/out"
+                         :asset-path   "js/out"
+                         :source-map true
+                         :optimizations :none
+                         :pretty-print  true}
+                        :figwheel
+                        {:on-jsload "microtables-frontend.core/mount-root"
+                         :open-urls ["http://localhost:3449/index.html"]}}
+                       :release
+                       {:source-paths ["src" "env/prod/cljs"]
+                        :compiler
+                        {:output-to "public/js/app.js"
+                         :output-dir "public/js/release"
+                         :optimizations :advanced
+                         :infer-externs true
+                         :pretty-print false}}}}
+
+  :aliases {"package" ["do" "clean" ["cljsbuild" "once" "release"]]}
+
+  :profiles {:dev {:source-paths ["src" "env/dev/clj"]
+                   :dependencies [[binaryage/devtools "0.9.10"]
+                                  [figwheel-sidecar "0.5.19"]
+                                  [nrepl "0.6.0"]
+                                  [cider/piggieback "0.4.1"]]}})

+ 34 - 0
frontend/public/css/site.css

@@ -0,0 +1,34 @@
+body {
+  font-family: 'Helvetica Neue', Verdana, Helvetica, Arial, sans-serif;
+  max-width: 600px;
+  margin: 0 auto;
+  padding-top: 72px;
+  -webkit-font-smoothing: antialiased;
+  font-size: 1.125em;
+  color: #333;
+  line-height: 1.5em;
+}
+
+h1, h2, h3 {
+  color: #000;
+}
+h1 {
+  font-size: 2.5em
+}
+
+h2 {
+  font-size: 2em
+}
+
+h3 {
+  font-size: 1.5em
+}
+
+a {
+  text-decoration: none;
+  color: #09f;
+}
+
+a:hover {
+  text-decoration: underline;
+}

+ 17 - 0
frontend/public/index.html

@@ -0,0 +1,17 @@
+
+<!DOCTYPE html>
+<html>
+  <head>
+    <meta charset="utf-8">
+    <meta content="width=device-width, initial-scale=1" name="viewport">
+    <link href="/css/site.css" rel="stylesheet" type="text/css">
+  </head>
+  <body>
+    <div id="app">
+      <h3>ClojureScript has not been compiled!</h3>
+      <p>please run <b>lein figwheel</b> in order to start the compiler</p>
+    </div>
+    <script src="/js/app.js" type="text/javascript"></script>
+    
+  </body>
+</html>

+ 18 - 0
frontend/src/microtables_frontend/core.cljs

@@ -0,0 +1,18 @@
+(ns microtables-frontend.core
+    (:require
+      [reagent.core :as r]))
+
+;; -------------------------
+;; Views
+
+(defn home-page []
+  [:div [:h2 "Welcome to Reagent"]])
+
+;; -------------------------
+;; Initialize app
+
+(defn mount-root []
+  (r/render [home-page] (.getElementById js/document "app")))
+
+(defn init! []
+  (mount-root))

+ 9 - 0
server/.babelrc

@@ -0,0 +1,9 @@
+{
+  "presets": ["env"],
+  "plugins": ["transform-runtime", "transform-object-rest-spread"],
+  "env": {
+    "production": {
+      "plugins": ["transform-remove-console"]
+    }
+  }
+}

+ 6 - 0
server/.gitignore

@@ -0,0 +1,6 @@
+.idea
+node_modules
+build
+test-build
+npm-debug*
+*.swp

+ 35 - 0
server/package.json

@@ -0,0 +1,35 @@
+{
+  "name": "@catallaxy/microtables-server",
+  "author": "Brandon Wong <wong.brandon@rcgt.com> (https://catallaxy.rcgt.com/)",
+  "main": "build/service.js",
+  "version": "0.1.0",
+  "scripts": {
+    "test": "node test-build/service.js",
+    "compile-prod": "cross-env NODE_ENV=production npm run compile",
+    "compile": "npm run compile-src && npm run compile-test",
+    "compile-test": "babel test --out-dir test-build",
+    "compile-src": "babel src --out-dir build",
+    "watch": "nodemon --watch src --watch test --exec \"npm run compile --silent\"",
+    "serverwatch": "nodemon --watch src --watch test --exec \"npm run compile --silent && node build/service.js\"",
+    "testwatch": "nodemon --watch src --watch test --exec \"npm run compile --silent && npm test\""
+  },
+  "directories": {
+    "test": "test"
+  },
+  "private": true,
+  "dependencies": {
+    "cross-env": "6.0.3",
+    "express": "4.17.1"
+  },
+  "devDependencies": {
+    "babel-cli": "6.26.0",
+    "babel-plugin-transform-object-rest-spread": "6.26.0",
+    "babel-plugin-transform-remove-console": "6.9.4",
+    "babel-plugin-transform-runtime": "6.23.0",
+    "babel-preset-env": "1.7.0",
+    "isomorphic-fetch": "2.2.1",
+    "nodemon": "1.19.4",
+    "tape": "4.11.0",
+    "tape-promise": "4.0.0"
+  }
+}

+ 22 - 0
server/src/service.js

@@ -0,0 +1,22 @@
+
+import express from 'express';
+import http from 'http';
+
+
+const port = process.env.port ? parseInt(process.env.port) : 8728,
+    app = express(),
+    httpserver = http.createServer(app);
+
+httpserver.listen(port, function listening() {
+    console.log('microtables-server service now listening on port', port);
+});
+
+app.get('/', function serve(req, res) {
+    res.send('microtables-server service');
+});
+
+
+
+
+
+

+ 40 - 0
server/test/service.js

@@ -0,0 +1,40 @@
+
+import {fork} from 'child_process';
+import tape from 'tape';
+import _test from 'tape-promise';
+import fetch from 'isomorphic-fetch';
+
+const tapetest = _test(tape);
+
+const randomPort = Math.floor(Math.random() * 10000) + 20000,
+    server = fork('build/service.js', [], {env: {port: randomPort}}),
+    connstring = `http://localhost:${randomPort}`;
+
+tapetest('service', async function testService(assert) {
+    try {
+        await waitPro();
+        const ret = await fetch(connstring + '/'),
+            data = await ret.text();
+        console.log('data', data);
+        assert.equal(ret.status, 200, 'root should work');
+    }
+    catch(e) {
+        console.log('error in', assert.name, e);
+        assert.fail(`error in ${assert.name}`);
+    }
+
+    assert.end();
+});
+
+tapetest.onFinish(async function cleanup() {
+    server.kill();
+});
+
+
+function waitPro(n = 1000) {
+    return new Promise(function pro(resolve, reject) {
+        setTimeout(resolve, n);
+    });
+}
+
+

File diff suppressed because it is too large
+ 3298 - 0
server/yarn.lock