Skip to content

Commit d12a9ef

Browse files
committed
try to deploy new package in new format; alpha release
1 parent 3c219fc commit d12a9ef

File tree

8 files changed

+137
-44
lines changed

8 files changed

+137
-44
lines changed

.github/workflows/npm-publish.yaml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: npm publish
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
publish-npm:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- uses: docker://timbru31/java-node:latest
13+
- uses: actions/setup-node@v1
14+
with:
15+
node-version: 12
16+
registry-url: https://registry.npmjs.org/
17+
18+
- name: Get yarn cache
19+
id: yarn-cache
20+
run: echo "::set-output name=dir::$(yarn cache dir)"
21+
22+
- uses: actions/cache@v1
23+
name: Cache node modules of yarn
24+
with:
25+
path: ${{ steps.yarn-cache.outputs.dir }}
26+
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
27+
restore-keys: |
28+
${{ runner.os }}-yarn-
29+
30+
- name: Cache Clojars
31+
uses: actions/cache@v1
32+
env:
33+
cache-name: cache-clojars
34+
with:
35+
path: ~/.m2
36+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('shadow-cljs.edn') }}
37+
restore-keys: |
38+
${{ runner.os }}-clojars
39+
40+
- run: yarn && yarn shadow-cljs release server && npm publish
41+
env:
42+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}

.github/workflows/upload.yaml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Upload Assets
2+
3+
on:
4+
push: {}
5+
6+
jobs:
7+
upload-assets:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- uses: docker://timbru31/java-node:latest
12+
13+
- name: Get yarn cache
14+
id: yarn-cache
15+
run: echo "::set-output name=dir::$(yarn cache dir)"
16+
17+
- uses: actions/cache@v1
18+
name: Cache node modules of yarn
19+
with:
20+
path: ${{ steps.yarn-cache.outputs.dir }}
21+
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
22+
restore-keys: |
23+
${{ runner.os }}-yarn-
24+
25+
- name: Cache Clojars
26+
uses: actions/cache@v1
27+
env:
28+
cache-name: cache-clojars
29+
with:
30+
path: ~/.m2
31+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('shadow-cljs.edn') }}
32+
restore-keys: |
33+
${{ runner.os }}-clojars
34+
35+
- run: yarn && yarn build
36+
name: Build web assets
37+
38+
- name: Deploy to server
39+
id: deploy
40+
uses: Pendect/action-rsyncer@v1.1.0
41+
env:
42+
DEPLOY_KEY: ${{secrets.rsync_private_key}}
43+
with:
44+
flags: '-avzr --progress'
45+
options: ''
46+
ssh_options: ''
47+
src: 'dist/*'
48+
dest: 'rsync-user@fe.jimu.io:/web-assets/repo/${{ github.repository }}'
49+
50+
- name: Display status from deploy
51+
run: echo "${{ steps.deploy.outputs.status }}"

ir.edn

+5-5
Original file line numberDiff line numberDiff line change
@@ -2416,7 +2416,8 @@
24162416
["[]" "respo.render.html" ":refer" ["[]" "make-string"]]
24172417
["[]" "app.comp.container" ":refer" ["[]" "comp-container"]]
24182418
["[]" "shell-page.core" ":refer" ["[]" "make-page" "slurp" "spit"]]
2419-
["[]" "app.schema" ":as" "schema"]]],
2419+
["[]" "app.schema" ":as" "schema"]
2420+
["[]" "cljs.reader" ":refer" ["[]" "read-string"]]]],
24202421
:defs {"main!" ["defn"
24212422
"main!"
24222423
[]
@@ -2437,15 +2438,14 @@
24372438
[]
24382439
["let"
24392440
[["html-content" ["make-string" ["comp-container" "schema/store"]]]
2440-
["manifest" ["js/JSON.parse" ["slurp" "|dist/manifest.json"]]]]
2441+
["assets" ["read-string" ["slurp" "|dist/assets.edn"]]]]
24412442
["make-page"
24422443
"html-content"
24432444
["merge"
24442445
"base-info"
24452446
["{}"
2446-
[":styles" ["[]" ["aget" "manifest" "|main.css"]]]
2447-
[":scripts"
2448-
["[]" ["aget" "manifest" "|vendor.js"] ["aget" "manifest" "|main.js"]]]]]]]],
2447+
[":styles" ["[]"]]
2448+
[":scripts" ["map" ["fn" ["x"] [":output-name" "x"]] "assets"]]]]]]],
24492449
"dev-page" ["defn"
24502450
"dev-page"
24512451
[]

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "stack-editor",
3-
"version": "0.1.0",
3+
"version": "0.4.0-a1",
44
"description": "Stack editor",
55
"main": "index.js",
66
"scripts": {
@@ -9,7 +9,8 @@
99
"page": "yarn shadow-cljs compile page && env=dev node target/page.js",
1010
"del": "rm -rf dist/*",
1111
"serve": "serve dist",
12-
"build": "yarn del && yarn release && yarn webpack && yarn html && yarn serve"
12+
"html": "shadow-cljs compile page && node target/page.js",
13+
"build": "yarn del && shadow-cljs release client && yarn html"
1314
},
1415
"bin": {
1516
"stack-editor": "./dist/server.js",

server/app/server.cljs

+22-23
Original file line numberDiff line numberDiff line change
@@ -5,56 +5,55 @@
55
[cljs.core.async :refer [<! >! timeout chan]]
66
[shallow-diff.patch :refer [patch]]
77
[cirru-sepal.analyze :refer [write-file ns->path]]
8+
[cirru-edn.core :as cirru-edn]
89
[fipp.edn :refer [pprint]]
9-
[app.walk :refer [walk]])
10+
[app.walk :refer [walk]]
11+
["fs" :as fs]
12+
["http" :as http]
13+
["path" :as path]
14+
["mkdirp" :as mkdirp])
1015
(:require-macros [cljs.core.async.macros :refer [go]]))
1116

12-
(def fs (js/require "fs"))
13-
(def http (js/require "http"))
14-
(def path (js/require "path"))
15-
(def mkdirp (js/require "mkdirp"))
16-
1717
(def ir-path
1818
(or
1919
(get (js->clj js/process.argv) 2)
20-
(if (fs.existsSync "ir.edn") "ir.edn")
21-
(if (fs.existsSync "stack-sepal.ir") "stack-sepal.ir")
20+
(if (fs/existsSync "stack.cirru") "stack.cirru")
2221
(do
23-
(println "Missing file: ir.edn or stack-sepal.ir not found!")
22+
(println "Missing file: stack.cirru not found!")
2423
(.exit js/process 1))))
2524

2625
(def ref-sepal
2726
(atom
28-
(if (fs.existsSync ir-path)
29-
(read-string (fs.readFileSync ir-path "utf8"))
27+
(if (fs/existsSync ir-path)
28+
(cirru-edn/parse (fs/readFileSync ir-path "utf8"))
3029
(do (.log js/console (str "Error: " ir-path " does not exist!"))
3130
(.exit js/process 1)))))
3231

3332
(def extension (or js/process.env.extension (:extension @ref-sepal) ".cljs"))
3433
(def out-folder (or js/process.env.out (get-in @ref-sepal [:options :src]) "src/"))
3534
(def port (js/parseInt (or js/process.env.port (get-in @ref-sepal [:options :port]) "7010")))
3635

37-
(defn read-body [req]
36+
(defn read-body [^js req]
3837
(let [body-ref (atom "")
3938
body-chan (chan)]
4039
(.on req "data" (fn [chunk] (swap! body-ref str chunk)))
4140
(.on req "end" (fn [] (go (>! body-chan @body-ref))))
4241
body-chan))
4342

4443
(defn rewrite-file! [content]
45-
(fs.writeFileSync ir-path (with-out-str (pprint content {:width 120}))))
44+
(fs/writeFileSync ir-path (cirru-edn/write content)))
4645

4746
(defn write-by-file [pkg ns-part file-info]
4847
(let [file-name (str (ns->path pkg ns-part) extension)
4948
content (write-file file-info)
50-
file-target (path.join out-folder file-name)
51-
container (path.dirname file-target)]
49+
file-target (path/join out-folder file-name)
50+
container (path/dirname file-target)]
5251
(println "File compiled:" file-name)
53-
(if (not (fs.existsSync container))
52+
(if (not (fs/existsSync container))
5453
(do
5554
(println "Creating folder:" container)
56-
(mkdirp.sync container)))
57-
(fs.writeFileSync file-target content)))
55+
(mkdirp/sync container)))
56+
(fs/writeFileSync file-target content)))
5857

5958
(defn compare-write-source! [sepal-data]
6059
(doseq [entry (:files sepal-data)]
@@ -68,7 +67,7 @@
6867
(let [[ns-part file-info] entry]
6968
(write-by-file (:package sepal-data) ns-part file-info))))
7069

71-
(defn req-handler [req res]
70+
(defn req-handler [^js req ^js res]
7271
(if (some? req.headers.origin)
7372
(.setHeader res "Access-Control-Allow-Origin" req.headers.origin))
7473
(.setHeader res "Content-Type" "text/edn; charset=UTF-8")
@@ -92,7 +91,7 @@
9291
(.end res (str "Unknown:" req.method))))
9392

9493
(defn create-app! []
95-
(let [app (http.createServer req-handler)]
94+
(let [app (http/createServer req-handler)]
9695
(.listen app port)
9796
(println "File:" ir-path)
9897
(println "Port:" port)
@@ -110,7 +109,7 @@
110109
(map
111110
(fn [ns-part]
112111
(string/replace
113-
(path.join out-folder
112+
(path/join out-folder
114113
(string/replace (:package @ref-sepal) "." "/")
115114
(str (string/replace ns-part "." "/") extension))
116115
"-" "_"))
@@ -128,12 +127,12 @@
128127
; (println "alive-files" alive-files)
129128
; (println "existing-files" existing-files)
130129
(doseq [file-path removed-files]
131-
(fs.unlinkSync file-path)
130+
(fs/unlinkSync file-path)
132131
(println "Redundant file:" file-path)))))
133132

134133
(.on js/process "SIGINT"
135134
(fn []
136-
(if (fs.existsSync out-folder) (check-removed!))
135+
(if (fs/existsSync out-folder) (check-removed!))
137136
(.exit js/process)))
138137

139138
(defn reload! []

server/app/walk.cljs

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11

2-
(ns app.walk)
2+
(ns app.walk
3+
(:require ["fs" :as fs]
4+
["path" :as path]))
35

4-
(def fs (js/require "fs"))
5-
(def path (js/require "path"))
6-
7-
(defn dir? [x] (.isDirectory (fs.statSync x)))
8-
(defn file? [x] (.isFile (fs.statSync x)))
6+
(defn dir? [x] (.isDirectory (fs/statSync x)))
7+
(defn file? [x] (.isFile (fs/statSync x)))
98

109
(defn walk [base-dir collect!]
11-
(let [children (js->clj (fs.readdirSync base-dir))]
10+
(let [children (js->clj (fs/readdirSync base-dir))]
1211
(doall
1312
(map
1413
(fn [child]
15-
(let [child-path (path.join base-dir child)]
14+
(let [child-path (path/join base-dir child)]
1615
(cond
1716
(dir? child-path)
1817
(walk child-path collect!)

shadow-cljs.edn

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
[cljs-ajax "0.8.0"]
1111
[cumulo/shallow-diff "0.1.3"]
1212
[fipp "0.6.22"]
13+
[cirru/edn "0.0.8"]
1314
[cirru/sepal "0.2.7"]
1415
[mvc-works/polyfill "0.1.1"]
1516
]
@@ -21,6 +22,7 @@
2122
:builds {
2223
:client {
2324
:output-dir "target", :target :browser, :asset-path "./"
25+
:compiler-options {:infer-externs :auto}
2426
:modules {
2527
:client {:init-fn app.main/main!}
2628
}
@@ -36,6 +38,7 @@
3638
}
3739
:server {
3840
:target :node-script, :main app.server/main!, :output-to "target/server.js"
41+
:compiler-options {:infer-externs :auto}
3942
:release {:output-to "dist/server.js"}
4043
:devtools {:after-load app.server/reload!}
4144
}

src/app/page.cljs

+4-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
[respo.render.html :refer [make-string]]
66
[app.comp.container :refer [comp-container]]
77
[shell-page.core :refer [make-page slurp spit]]
8-
[app.schema :as schema]))
8+
[app.schema :as schema]
9+
[cljs.reader :refer [read-string]]))
910

1011
(def base-info
1112
{:title "Stack Editor",
@@ -16,13 +17,10 @@
1617

1718
(defn prod-page []
1819
(let [html-content (make-string (comp-container schema/store))
19-
manifest (js/JSON.parse (slurp "dist/manifest.json"))]
20+
assets (read-string (slurp "dist/assets.edn"))]
2021
(make-page
2122
html-content
22-
(merge
23-
base-info
24-
{:styles [(aget manifest "main.css")],
25-
:scripts [(aget manifest "vendor.js") (aget manifest "main.js")]}))))
23+
(merge base-info {:styles [], :scripts (map (fn [x] (:output-name x)) assets)}))))
2624

2725
(defn dev-page [] (make-page "" (merge base-info {:scripts ["/client.js"]})))
2826

0 commit comments

Comments
 (0)