Skip to content

Commit 5550a6b

Browse files
authored
Merge pull request #26 from PromptECO/output-dir
Output dir
2 parents 05f5f17 + b0df8ef commit 5550a6b

File tree

5 files changed

+47
-18
lines changed

5 files changed

+47
-18
lines changed

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22

3-
## 0.5.1
3+
## 0.6.0
4+
5+
- New `output-dir` option to specify a directory for formatted files
6+
7+
## 0.5.2
48

59
- New `spread` format to accommodate line-oriented codecov tooling
610

CONTRIBUTING.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ This development environment is built on [shadow-cljs](https://github.com/thhell
44

55
## Starting a Watcher
66

7-
To start a shadow-cljs watcher, which will recompile the code whenever any files change, use the following command (you can use `-d` to run it in the background):
7+
To start a shadow-cljs watcher, which will recompile the code whenever any files change, use the following command:
88

99
```bash
10-
docker-compose run --rm shadow-cljs watch script
10+
docker-compose run -v `pwd`:/home --rm shadow-cljs watch script
1111
```
1212

13+
The `-v` option mounts the current directory. Optionally, use `-d` to run the container in the background.
14+
1315
Wait until the watch server has completed starting up, then [open the build monitor](http://localhost:9630/builds) in a web browser:
1416

1517
```bash

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,13 @@ docker run -v `pwd`:/home ghcr.io/prompteco/clariform *.clar
6262

6363
This assumes that the current directory contains Clarity contracts with a ".clar" file extension.
6464

65-
The formatted contracts will be written to output.
65+
The formatted contracts will be written to output.
66+
67+
Use the `--output-dir` option to specify a directory for formatted contracts:
68+
69+
```
70+
docker run -v `pwd`:/home ghcr.io/prompteco/clariform --output-dir "out" *.clar
71+
```
6672

6773
### Troubleshooting
6874

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "clariform",
3-
"version": "0.5.2",
3+
"version": "0.6.0",
44
"private": true,
55
"scripts": {
66
"repl": "npx shadow-cljs node-repl",

src/main/clariform/core.cljs

+30-13
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
[clariform.ast.parser :as parser]
1616
[clariform.format :as format
1717
:refer [format-code]]
18+
[cljs-node-io.core :as node-io]
19+
[cljs-node-io.file :as node-file]
1820
[clariform.io :as io]
1921
[clariform.transform :as transform
2022
:refer [transform]]))
2123

22-
(def version-string "0.5.2")
24+
(def version-string "0.6.0")
2325

2426
(defn printerr [& vals]
2527
(binding [*print-fn* *print-err-fn*]
@@ -51,19 +53,20 @@
5153
(exit 1 (pr-str err))))))
5254
(recur))))))
5355

54-
(defn format-all [{:keys [arguments options summary errors] :as opts}]
55-
(let [resources (io/resources-seq arguments)
56+
(defn format-all [{:keys [arguments options summary errors] :as opts} & {:keys [output-dir]}]
57+
(let [resources (doall (io/resources-seq arguments))
5658
multiple (some? (next resources))
5759
con-chan (io/contracts-chan resources)]
5860
(go-loop [{:keys [locator error text] :as res} (<! con-chan)]
59-
(binding [*out* (pprint/get-pretty-writer *out*)]
60-
(when (some? res)
61-
(when error
62-
(printerr (ex-message error))
63-
(recur (<! con-chan)))
64-
(when multiple
65-
(pprint/fresh-line)
66-
(println ";;" (io/file-path locator)))
61+
(when (some? res)
62+
(when (some? error)
63+
(printerr (ex-message error))
64+
(recur (<! con-chan)))
65+
(when multiple
66+
(println "") ;; pprint/fresh-line fails!
67+
(when (some? locator)
68+
(println ";; " (.toString locator))))
69+
(binding [*out* (pprint/get-pretty-writer *out*)]
6770
(let [parser-options (select-keys options [:strict])
6871
ast (format/parse-code text parser-options)]
6972
(if (insta/failure? ast)
@@ -82,7 +85,20 @@
8285
(try
8386
(let [formatted (-> (transform ast)
8487
(format-code options))]
85-
(print formatted))
88+
;_ (node-io/spit "contracts-out/file61-locator.clar" (pr-str locator))
89+
;dir (if true output-dir #_(node-io/as-file output-dir))
90+
;_ (node-io/spit "contracts-out/file62-dir.clar" (pr-str dir))
91+
;filepath (case :prod
92+
; :prod (node-io/filepath (str output-dir) #_"contracts-out" (str locator) #_"contracts/basic.clar")
93+
; :test "contracts-out/contracts/basic.clar")]
94+
;(node-io/spit "contracts-out/file70-filepath.clar" (pr-str filepath))
95+
; (apply node-io/make-parents (string/split filepath #"/"))
96+
(if-some [path (and (some? output-dir)
97+
(node-io/filepath (str output-dir) (str locator)))]
98+
(do #_(node-io/spit "contracts-out/filexx.clar" (pr-str path))
99+
(apply node-io/make-parents (string/split path #"/"))
100+
(node-io/spit path formatted))
101+
(print formatted)))
86102
(catch ExceptionInfo e
87103
(printerr (ex-message e))))))
88104
(pprint/fresh-line)
@@ -99,6 +115,7 @@
99115
:validate [#{"retain" "adjust" "indent" "auto" "align" "tight" "spread" "compact"}
100116
"Must be one of 'retain', 'adjust', 'indent', 'auto', 'align', 'tight', 'spread' or 'compact'"]]
101117
[nil "--strict" "Expect strict Clarity syntax"]
118+
["-o" "--output-dir DIR" "Output directory"]
102119
[nil "--verbose"]
103120
[nil "--debug"]])
104121

@@ -120,7 +137,7 @@
120137
(some? (:check options))
121138
(check-all params)
122139
:else
123-
(format-all params)))
140+
(format-all params :output-dir (:output-dir options))))
124141

125142
(defonce command (atom nil))
126143

0 commit comments

Comments
 (0)