Skip to content

Commit

Permalink
Merge pull request #10 from mvc-works/deps-edn
Browse files Browse the repository at this point in the history
add checking for deps.edn
  • Loading branch information
soyaine authored Jul 20, 2020
2 parents b00d672 + e93f23d commit bf7639a
Show file tree
Hide file tree
Showing 7 changed files with 859 additions and 309 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/npm-publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

name: npm publish

on:
release:
types: [created]

jobs:
deploy:
name: Deploy

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- uses: docker://timbru31/java-node:latest
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: https://registry.npmjs.org/

- name: build assets
run: 'yarn && yarn build'

- name: publish
run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
40 changes: 40 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

name: Upload Assets

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

jobs:
upload-assets:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: docker://timbru31/java-node:latest

- name: Get yarn cache
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v1
name: Cache node modules of yarn
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Cache Clojars
uses: actions/cache@v1
env:
cache-name: cache-clojars
with:
path: ~/.m2/repository
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('shadow-cljs.edn') }}
restore-keys: |
${{ runner.os }}-clojars
- run: yarn && yarn shadow-cljs compile app
name: Build web assets
982 changes: 715 additions & 267 deletions calcit.cirru

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mvc-works/clojars-outdated",
"version": "0.1.5",
"version": "0.1.6-a1",
"scripts": {
"watch": "yarn shadow-cljs watch app",
"prepare": "yarn build",
Expand Down
5 changes: 0 additions & 5 deletions shadow-cljs.edn
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{
:source-paths ["src"]
:repositories {
"central" {:url "https://maven.aliyun.com/nexus/content/groups/public/"}
"clojars" {:url "https://mirrors.ustc.edu.cn/clojars/"}
}
:dependencies [
[mvc-works/chan-utils "0.1.1"]
[cljs-node-io "1.1.2"]
[medley "1.3.0"]
[cirru/favored-edn "0.1.3"]
Expand Down
101 changes: 65 additions & 36 deletions src/app/main.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
["chalk" :as chalk]
[clojure.string :as string]
[cljs-node-io.fs :refer [areadFile awriteFile]]
[chan-utils.core :refer [all-once]]
["latest-version" :as latest-version]
[applied-science.js-interop :as j]
[cljs.reader :refer [read-string]]
[favored-edn.core :refer [write-edn]]
[cljs.core.async.interop :refer [<p!]])
[cljs.core.async.interop :refer [<p!]]
[app.util :refer [pad-right all-once]])
(:require-macros [clojure.core.strint :refer [<<]]))

(def envs
Expand Down Expand Up @@ -54,9 +54,7 @@
(<<
"New version ~{npm-version} available, current one is ~{version} . Please upgrade!\n\nyarn global add ~{pkg-name}\n"))))))))

(defn pad-right [x n] (if (>= (count x) n) x (recur (str x " ") n)))

(defn display-results! [results skipped-deps]
(defn display-results! [file-name results skipped-deps]
(let [ok-checks (->> results
(filter (fn [check] (:ok? check)))
(map
Expand All @@ -82,7 +80,7 @@
(.gray chalk (->> latest-packages (string/join " ")))))
(when (not-empty old-packages)
(println)
(println (.yellow chalk "Outdated packages:"))
(println (.yellow chalk "Outdated packages in" file-name ":"))
(let [max-name-length (->> old-packages (map :name) (map str) (map count) (apply max))]
(doseq [info old-packages]
(println
Expand All @@ -102,6 +100,24 @@
[(:pkg cursor) (:to cursor)]
(recur dep (rest new-versions))))))

(defn replace-deps-edn-dep [dep new-versions]
(if (empty? new-versions)
dep
(let [cursor (first new-versions)]
(if (= (first dep) (:pkg cursor))
[(:pkg cursor) {:mvn/version (:to cursor)}]
(recur dep (rest new-versions))))))

(defn replace-deps-numbers [content new-versions]
(let [new-config (-> (read-string content)
(update
:deps
(fn [deps]
(->> deps
(map (fn [dep] (replace-deps-edn-dep dep new-versions)))
(into {})))))]
(write-edn new-config {:indent 2})))

(defn replace-numbers [content new-versions]
(let [new-config (-> (read-string content)
(update
Expand All @@ -110,7 +126,7 @@
(->> deps (map (fn [dep] (replace-dep dep new-versions))) (vec)))))]
(write-edn new-config {:indent 2})))

(defn replace-versions! [results]
(defn replace-versions! [filename results]
(let [new-versions (->> results
(filter
(fn [x]
Expand All @@ -124,37 +140,50 @@
:to (:data x)})))]
(if-not (empty? new-versions)
(go
(let [[err content] (<! (areadFile "shadow-cljs.edn" "utf8"))
new-content (replace-numbers content new-versions)]
(<! (awriteFile "shadow-cljs.edn" new-content nil))
(let [[err content] (<! (areadFile filename "utf8"))
new-content (case filename
"shadow-cljs.edn" (replace-numbers content new-versions)
"deps.edn" (replace-deps-numbers content new-versions)
(do (println "Unknown file:" filename) content))]
(<! (awriteFile filename new-content nil))
(println)
(println (chalk/yellow "File is modified under replace mode!")))))))
(println (chalk/yellow filename "is modified under replace mode!")))))))

(defn task! []
(println (chalk/gray "Reading shadow-cljs.edn"))
(when-not (fs/existsSync "shadow-cljs.edn")
(println (chalk/red "Not found"))
(.exit js/process 1))
(defn clojars-task! [filename]
(println (chalk/gray "Reading" filename))
(go
(let [start-time (.now js/Date)
[err content] (<! (areadFile "shadow-cljs.edn" "utf8"))
data (read-string content)
deps (->> (:dependencies data)
(filter
(fn [pair] (not (string/includes? (str (first pair)) "org.clojure")))))
skipped-deps (->> (:dependencies data)
(filter
(fn [pair] (string/includes? (str (first pair)) "org.clojure"))))]
(write (chalk/gray (string/join "" (repeat (count deps) "."))))
(write "\r")
(let [<check-results (all-once chan-check-dep deps)
results (<! <check-results)
end-time (.now js/Date)
cost (/ (- end-time start-time) 1000)]
(println (chalk/gray (<< " cost ~{cost}s to check.")))
(display-results! results skipped-deps)
(when (:replace? envs) (replace-versions! results))))))
(if-not (fs/existsSync filename)
(println (chalk/red filename "not found"))
(let [start-time (.now js/Date)
[err content] (<! (areadFile filename "utf8"))
data (case filename
"shadow-cljs.edn" (:dependencies (read-string content))
"deps.edn"
(->> (:deps (read-string content))
(map (fn [[k v]] [k (:mvn/version v)])))
(do (println "Unknown filename:" filename)))
deps (->> data
(filter
(fn [pair] (not (string/includes? (str (first pair)) "org.clojure")))))
skipped-deps (->> data
(filter
(fn [pair]
(string/includes? (str (first pair)) "org.clojure"))))]
(write (chalk/gray (string/join "" (repeat (count deps) "."))))
(write "\r")
(let [<check-results (all-once chan-check-dep deps)
results (<! <check-results)
end-time (.now js/Date)
cost (/ (- end-time start-time) 1000)]
(println (chalk/gray (<< " cost ~{cost}s to check.")))
(display-results! filename results skipped-deps)
(when (:replace? envs) (replace-versions! filename results)))))))

(defn main! [] (task!) (when (:npm-check? envs) (check-version!)))
(defn main! []
(go (<! (clojars-task! "shadow-cljs.edn")) (<! (clojars-task! "deps.edn")))
(when (:npm-check? envs) (check-version!)))

(defn reload! [] (.clear js/console) (println "Reloaded.") (task!))
(defn reload! []
(.clear js/console)
(println "Reloaded.")
(comment clojars-task! "shadow-cljs.edn"))
9 changes: 9 additions & 0 deletions src/app/util.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

(ns app.util (:require [clojure.core.async :refer [go chan >! <!]]))

(defn all-once [f xs]
(go
(loop [acc [], tasks (doall (map f xs))]
(if (empty? tasks) acc (recur (conj acc (<! (first tasks))) (rest tasks))))))

(defn pad-right [x n] (if (>= (count x) n) x (recur (str x " ") n)))

0 comments on commit bf7639a

Please sign in to comment.