|
1 | 1 | (ns wisp.wisp |
2 | 2 | "Wisp program that reads wisp code from stdin and prints |
3 | 3 | compiled javascript code into stdout" |
4 | | - (:require [fs :refer [createReadStream writeFileSync]] |
| 4 | + (:require [fs :refer [createReadStream]] |
5 | 5 | [path :refer [basename dirname join resolve]] |
6 | 6 | [module :refer [Module]] |
7 | 7 | [commander] |
8 | 8 |
|
9 | 9 | [wisp.string :refer [split join upper-case replace]] |
10 | | - [wisp.sequence :refer [first second last count reduce rest map |
| 10 | + [wisp.sequence :refer [first second last count reduce rest |
11 | 11 | conj partition assoc drop empty?]] |
12 | 12 |
|
13 | 13 | [wisp.repl :refer [start] :rename {start start-repl}] |
|
29 | 29 | compile-string |
30 | 30 | (conj {:source-uri path} options))) |
31 | 31 |
|
32 | | -(defn compile-files |
33 | | - [paths options] |
34 | | - (map #(compile-file % options) paths)) |
35 | | - |
36 | 32 | (defn compile-string |
37 | 33 | [source options] |
38 | 34 | (let [channel (or (:print options) :code) |
|
41 | 37 | (= channel :code) (:code output) |
42 | 38 | (= channel :expansion) (:expansion output) |
43 | 39 | :else (JSON.stringify (get output channel) 2 2))] |
44 | | - (if (and (:output options) (:source-uri options) content) |
45 | | - (writeFileSync (path.join (.-output options) ;; `join` relies on `path` |
46 | | - (str (basename (:source-uri options) ".wisp") ".js")) |
47 | | - content) |
48 | 40 | (.write process.stdout (or content "nil"))) |
49 | 41 | (if (:error output) (throw (.-error output))))) |
50 | 42 |
|
|
81 | 73 | (.option "-c, --compile" "Compile to JavaScript and save as .js files") |
82 | 74 | (.option "-i, --interactive" "Run an interactive wisp REPL") |
83 | 75 | (.option "--debug, --print <type>" "Print debug information. Possible values are `expansion`,`forms`, `ast` and `js-ast`") |
84 | | - ;(.option "-o, --output <dir>" "Output to specified directory") |
85 | 76 | (.option "--no-map" "Disable source map generation") |
86 | 77 | (.parse process.argv)) |
87 | 78 | (set! (aget options "no-map") (not (aget options "map"))) ;; commander auto translates to camelCase |
88 | 79 | (cond options.run (run (get options.args 0)) |
89 | 80 | (not process.stdin.isTTY) (compile-stdin options) |
90 | 81 | options.interactive (start-repl) |
91 | | - options.compile (compile-files options.args options) |
| 82 | + options.compile (compile-file options.args options) |
92 | 83 | options.args (run options.args) |
93 | 84 | :else (start-repl) |
94 | 85 | ))) |
0 commit comments