Skip to content

Commit

Permalink
init project from existing cumulo-util
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Feb 25, 2021
0 parents commit e752790
Show file tree
Hide file tree
Showing 12 changed files with 1,730 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

calcit.cirru -diff linguist-generated
yarn.lock -diff linguist-generated
26 changes: 26 additions & 0 deletions .github/workflows/compile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Compiles only

on:
push:
branches:
- master
pull_request: {}

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: wget
run: mkdir ci-bin/ && wget -O ci-bin/cr_once http://repo.calcit-lang.org/binaries/linux/cr_once
- name: "permission"
run: chmod +x ci-bin/cr_once

- name: "prepare modules"
run: >
mkdir -p ~/.config/calcit/modules/ && cd ~/.config/calcit/modules/
- name: "compiles to js"
run: >
./ci-bin/cr_once --emit-js
&& ./ci-bin/cr_once --emit-js --emit-path:out-page/ --init-fn:cumulo-util.client/main! --reload-fn:cumulo-util.client/reload!
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

.compact-inc.cirru
.calcit-error.cirru

js-out/
node_modules/
dist/
out-page/
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

cumulo-util in calcit-js
---

```cirru
cumulo-util.core/on-page-tough $ fn ()
cumulo-util.core/id!
cumulo-util.core/delay! 0.1 $ fn ()
cumulo-util.core/repeat! 0.1 $ fn ()
cumulo-util.file/sh! "|echo demo"
cumulo-util.file/write-mildly! path content
cumulo-util.file/get-backup-path!
cumulo-util.file/merge-local-edn! base filepath $ fn (found?)
```

### License

MIT
588 changes: 588 additions & 0 deletions calcit.cirru

Large diffs are not rendered by default.

97 changes: 97 additions & 0 deletions compact.cirru
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@

{} (:package |cumulo-util)
:configs $ {} (:init-fn |cumulo-util.app/main!) (:reload-fn |cumulo-util.app/reload!)
:modules $ []
:version nil
:files $ {}
|cumulo-util.app $ {}
:ns $ quote
ns cumulo-util.app $ :require
[] cumulo-util.core :refer $ [] delay!
[] cumulo-util.file :refer $ [] chan-pick-port write-mildly!
:defs $ {}
|main! $ quote
defn main! () (println "\"Started") (task!) (write-mildly! "\"a/a/a" "\"a")
|reload! $ quote
defn reload! () (println "\"Reload") (task!)
|task! $ quote
defn task! () $ echo "\"Task..."
:proc $ quote ()
|cumulo-util.client $ {}
:ns $ quote
ns cumulo-util.client $ :require
[] cumulo-util.core :refer $ [] on-page-touch
:defs $ {}
|main! $ quote
defn main! () $ on-page-touch
fn () $ println "\"called"
|reload! $ quote
defn reload! $
:proc $ quote ()
|cumulo-util.core $ {}
:ns $ quote
ns cumulo-util.core $ :require ([] "\"shortid" :as shortid)
:defs $ {}
|delay! $ quote
defn delay! (duration task)
js/setTimeout task $ * 1000 duration
|id! $ quote
defn id! () $ shortid/generate
|on-page-touch $ quote
defn on-page-touch (listener) (reset! *cooling false)
let
call-listener $ fn ()
when (not @*cooling) (listener) (reset! *cooling true)
delay! 0.8 $ fn () (reset! *cooling false)
.addEventListener js/window "\"focus" $ fn (event) (call-listener)
.addEventListener js/window "\"visibilitychange" $ fn (event)
when
= "\"visible" $ .-visibilityState js/document
call-listener
|repeat! $ quote
defn repeat! (duration task)
js/setInterval task $ * 1000 duration
|unix-time! $ quote
defn unix-time! () $ .valueOf (new js/Date)
|*cooling $ quote (defatom *cooling false)
:proc $ quote ()
|cumulo-util.file $ {}
:ns $ quote
ns cumulo-util.file $ :require ([] "\"path" :as path) ([] "\"fs" :as fs) ([] "\"child_process" :as cp) ([] "\"net" :as net)
:defs $ {}
|get-backup-path! $ quote
defn get-backup-path! () $ let
now $ new js/Date
path/join js/__dirname "\"backups"
str $ inc (.getMonth now)
str (.getDate now) "\"-snapshot.edn"
|merge-local-edn! $ quote
defn merge-local-edn! (x0 filepath handler)
merge x0 $ let
found? $ fs/existsSync filepath
if (fn? handler) (handler found?)
if found?
extract-cirru-edn $ parse-cirru (fs/readFileSync filepath |utf8)
, nil
|sh! $ quote
defn sh! (command) (println command)
println $ .toString (cp/execSync command)
|write-mildly! $ quote
defn write-mildly! (file-path content)
let
dir $ path/dirname file-path
filename $ path/basename file-path
temp-name $ str "\"/tmp/" (.now js/Date) "\"-" (.random js/Math) "\"-" filename
do-write! $ fn () (fs/writeFileSync temp-name content) (fs/renameSync temp-name file-path) (println "\"Write to file:" file-path)
if (fs/existsSync file-path)
let
old-content $ fs/readFileSync file-path "\"utf8"
if (not= content old-content) (do-write!) (; println "\"same file, skipping:" file-path)
do
when
and (not= "\"." dir)
not $ fs/existsSync dir
fs/mkdirSync dir $ to-js-data
{} $ :recursive true
do-write!
:proc $ quote ()
14 changes: 14 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@


<body>

<div class="app" ></div>
<style type="text/css">
body {
margin: 0;
}
</style>

<script type="module" src="./main.js" ></script>

</body>
10 changes: 10 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

import { main_BANG_ } from "./out-page/cumulo-util.client.js"

main_BANG_()

if (import.meta.hot) {
import.meta.hot.accept('./out-page/cumulo-util.client.js', (main) => {
main.reload_BANG_()
})
}
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"dependencies": {
"@calcit/procs": "^0.2.62"
},
"scripts": {
"watch-server": "cr --emit-js",
"build-server": "target=node entry=./server.js yarn webpack && node js-out/bundle.js",
"watch-page": "cr --emit-js --emit-path:out-page/ --init-fn:cumulo-util.client/main! --reload-fn:cumulo-util.client/reload!"
},
"devDependencies": {
"shortid": "^2.2.16",
"vite": "^2.0.0",
"webpack": "^5.24.0",
"webpack-cli": "^4.5.0",
"ws": "^7.4.3"
},
"version": "0.0.1"
}
10 changes: 10 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

import { main_BANG_ } from "./js-out/cumulo-util.app.js"

main_BANG_()

if (import.meta.hot) {
import.meta.hot.accept('./js-out/cumulo-util.app.js', (main) => {
main.reload_BANG_()
})
}
22 changes: 22 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
let path = require("path");

let bundleTarget = process.env.target === "node" ? "node" : "web";
console.log("Bundle target:", bundleTarget);

let entry = process.env.entry ?? '"./main.js"';
console.log("Entry:", entry);

module.exports = {
entry: entry,
target: bundleTarget,
mode: "development",
devtool: "hidden-source-map",
externals: {
ws: "commonjs ws",
shortid: "commonjs shortid",
},
output: {
path: path.resolve(__dirname, "js-out/"),
filename: "bundle.js",
},
};
Loading

0 comments on commit e752790

Please sign in to comment.