Skip to content

Commit

Permalink
update clj-kondo to a version that supports windows
Browse files Browse the repository at this point in the history
Fix #2
  • Loading branch information
filipesilva committed Oct 21, 2019
1 parent 6fed13e commit bd9ae53
Show file tree
Hide file tree
Showing 10 changed files with 498 additions and 51 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
node-version: '12.x'
- name: Install
run: yarn
- name: Lint
run: yarn lint
- name: Build
run: yarn build
- name: E2E
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ See the ClojureScript [testing page](https://clojurescript.org/tools/testing) fo

### `npm run lint` or `yarn lint`, and `npm run format` or `yarn format`

`lint` checks the code for known bad code patterns using [clj-kondo](https://github.com/borkdude/clj-kondo).<br>
Note: does not work on Windows currently, see this [issue](https://github.com/filipesilva/create-cljs-app/issues/2) for a workaround.
`lint` checks the code for known bad code patterns using [clj-kondo](https://github.com/borkdude/clj-kondo).

`format` will format your code in a consistent manner using [zprint-clj](https://github.com/clj-commons/zprint-clj).

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
},
"homepage": "https://github.com/filipesilva/create-cljs-app#readme",
"devDependencies": {
"clj-kondo": "2019.10.11-alpha.1",
"shadow-cljs": "^2.8.64",
"shx": "^0.3.2",
"zprint-clj": "^0.5.0"
Expand Down
2 changes: 1 addition & 1 deletion src/create_cljs_app/lib.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
exec-options)
(init-git-msg)
; Catch and remove the .git directory to not leave it half-done.
(catch js/Object e (rm "-rf" ".git")))))
(catch js/Object _e (rm "-rf" ".git")))))
(done-msg name path abs-path commands)))))

(def exports #js {:create create})
3 changes: 1 addition & 2 deletions src/create_cljs_app/messages.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(ns create-cljs-app.messages
(:require
["chalk" :refer [blue green]]
["path" :refer [dirname]]))
["chalk" :refer [blue green]]))

(defn begin-msg
[abs-path]
Expand Down
66 changes: 34 additions & 32 deletions src/create_cljs_app/template.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(ns create-cljs-app.template
(:require
[create-cljs-app.utils :refer [get-commands]]
[clojure.string :refer [replace]]
["path" :refer [dirname join]]
["fs" :refer
Expand All @@ -14,7 +13,7 @@
"UNIX-style paths from the template dir to ignore. Mostly leftovers from template development."
#{".shadow-cljs" "node_modules" "out" "yarn.lock" "public/js"})

(defn get-template-values
(defn get-template-values-map
"List of string replacements to perform in files while copying.
Will likely need to be replaced with a proper templating library."
[name commands]
Expand All @@ -30,48 +29,51 @@ Will likely need to be replaced with a proper templating library."
{:from "__FORMAT__", :to (:format commands)}
{:from "__BUILD__", :to (:build commands)}]})

(defn- join-partial
[partial fragment]
(if (= partial "")
fragment
; Always join partials with UNIX separators to ensure matches with
; ignores.
(str partial "/" fragment)))

(defn- list-files-helper
[from ignore partial]
(mapcat
#(let [curr-partial (join-partial partial %)]
(if (.isFile (statSync (join from curr-partial)))
[curr-partial]
(list-files-helper from ignore curr-partial)))
(filter #(not (contains? ignore (join-partial partial %)))
(set (readdirSync (join from partial))))))

(defn list-files
"Recursively lists all files in a directory, ignoring some paths along the way."
[from ignore]
(defn join-partial
[partial fragment]
(if (= partial "")
fragment
; Always join partials with UNIX separators to ensure matches with
; ignores.
(str partial "/" fragment)))
(defn list-files-helper
[partial]
(mapcat
#(let [curr-partial (join-partial partial %)]
(if (.isFile (statSync (join from curr-partial)))
[curr-partial]
(list-files-helper curr-partial)))
(filter #(not (contains? ignore (join-partial partial %)))
(set (readdirSync (join from partial))))))
(list-files-helper ""))
(list-files-helper from ignore ""))

(defn copy-template
"Copy a file while using it as a template with replacements."
[from-abs to-abs values]
[from-abs to-abs template-values]
(writeFileSync
to-abs
(reduce #(replace %1 (:from %2) (:to %2))
(readFileSync from-abs "utf-8")
values)))
template-values)))

(defn- copy-file
[from to path template-values]
(let [from-abs (join from path)
to-abs (join to path)]
(mkdirSync (dirname to-abs) #js {:recursive true})
(if template-values
(copy-template from-abs to-abs template-values)
(copyFileSync from-abs to-abs))))

(defn copy-files
"Copy files from one directory to another, preserving folder structure."
[files from to template-values]
(defn copy-file
[path]
(let [from-abs (join from path)
to-abs (join to path)]
(mkdirSync (dirname to-abs) #js {:recursive true})
(if (contains? template-values path)
(copy-template from-abs to-abs (get template-values path))
(copyFileSync from-abs to-abs))))
(doall (map #(copy-file %) files)))
[files from to get-template-values-map]
(doall (map #(copy-file from to % (get get-template-values-map path)) files)))

(defn use-template
"Create an app from a template into."
Expand All @@ -80,4 +82,4 @@ Will likely need to be replaced with a proper templating library."
(list-files template-dir template-ignores)
template-dir
app-path
(get-template-values name commands)))
(get-template-values-map name commands)))
9 changes: 3 additions & 6 deletions src/e2e/core.cljs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
(ns e2e.core
(:require
[clojure.string :refer [includes?]]
[cljs.test :refer-macros [deftest are is use-fixtures testing]]
[cljs.test :refer-macros [deftest is use-fixtures testing]]
["fs" :refer [existsSync readFileSync]]
["os" :refer [platform]]
["shelljs" :refer [exec rm]]))

(defn silent-exec
[cmd]
"Run a command silently. Flip silent to false to see output."
[cmd]
(exec cmd #js {:silent true}))

; Clean existing test app, if any.
Expand Down Expand Up @@ -57,7 +56,5 @@
(is (existsSync "./public/js/main.js"))
"Should output public/js/main.js")
(is (= (.-code (silent-exec "yarn e2e")) 0) "Should e2e")
(when (not (= (platform) "win32"))
; Linting doesn't work on Windows yet.
(is (= (.-code (silent-exec "yarn lint")) 0) "Should lint"))
(is (= (.-code (silent-exec "yarn lint")) 0) "Should lint")
(is (= (.-code (silent-exec "yarn format")) 0) "Should format"))))
3 changes: 1 addition & 2 deletions template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ See the ClojureScript [testing page](https://clojurescript.org/tools/testing) fo

### `__LINT__` and `__FORMAT__`

`__LINT__` checks the code for known bad code patterns using [clj-kondo](https://github.com/borkdude/clj-kondo).<br>
Note: does not work on Windows currently, see this [issue](https://github.com/filipesilva/create-cljs-app/issues/2) for a workaround.
`__LINT__` checks the code for known bad code patterns using [clj-kondo](https://github.com/borkdude/clj-kondo).

`__FORMAT__` will format your code in a consistent manner using [zprint-clj](https://github.com/clj-commons/zprint-clj).

Expand Down
4 changes: 1 addition & 3 deletions template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"clean": "rimraf public/js"
},
"devDependencies": {
"clj-kondo": "2019.10.11-alpha.1",
"rimraf": "~3.0.0",
"serve-handler": "~6.1.2",
"shadow-cljs": "~2.8.64",
Expand All @@ -23,8 +24,5 @@
"create-react-class": "~15.6.3",
"react": "~16.10.2",
"react-dom": "~16.10.2"
},
"optionalDependencies": {
"clj-kondo": "^2019.10.11-alpha"
}
}
Loading

0 comments on commit bd9ae53

Please sign in to comment.