|
25 | 25 |
|
26 | 26 | (defn compile-file |
27 | 27 | [path options] |
28 | | - (map (fn [file] (with-stream-content |
29 | | - (createReadStream file) |
| 28 | + (with-stream-content (createReadStream path) |
30 | 29 | compile-string |
31 | | - (conj {:source-uri file} options))) path)) |
| 30 | + (conj {:source-uri path} options))) |
| 31 | + |
| 32 | +(defn compile-files |
| 33 | + [paths options] |
| 34 | + (map #(compile-file % options) paths)) |
32 | 35 |
|
33 | 36 | (defn compile-string |
34 | 37 | [source options] |
35 | 38 | (let [channel (or (:print options) :code) |
36 | 39 | output (compile source options) |
37 | | - content (if (= channel :code) |
38 | | - (:code output) |
39 | | - (JSON.stringify (get output channel) 2 2))] |
40 | | - (if (:ast options) (map (fn [item] |
41 | | - (.write process.stdout |
42 | | - (str (pr-str item.form) "\n"))) |
43 | | - output.ast)) |
| 40 | + content (cond |
| 41 | + (= channel :code) (:code output) |
| 42 | + (= channel :expansion) (reduce (fn [result item] |
| 43 | + (str result (pr-str (.-form item)) "\n")) |
| 44 | + "" (.-ast output)) |
| 45 | + :else (JSON.stringify (get output channel) 2 2))] |
44 | 46 | (if (and (:output options) (:source-uri options) content) |
45 | | - (writeFileSync (path.join (:output options) ;; `join` relies on `path` |
| 47 | + (writeFileSync (path.join (.-output options) ;; `join` relies on `path` |
46 | 48 | (str (basename (:source-uri options) ".wisp") ".js")) |
47 | 49 | content) |
48 | 50 | (.write process.stdout (or content "nil"))) |
49 | | - (if (:error output) (throw (:error output))))) |
| 51 | + (if (:error output) (throw (.-error output))))) |
50 | 52 |
|
51 | 53 | (defn with-stream-content |
52 | 54 | [input resume options] |
|
61 | 63 | [path] |
62 | 64 | ;; Loading module as main one, same way as nodejs does it: |
63 | 65 | ;; https://github.com/joyent/node/blob/master/lib/module.js#L489-493 |
64 | | - (Module._load (resolve (get path 0)) null true)) |
| 66 | + (Module._load (resolve path) null true)) |
65 | 67 |
|
66 | 68 | (defmacro -> |
67 | 69 | [& operations] |
|
80 | 82 | (.option "-r, --run" "Compile and execute the file") |
81 | 83 | (.option "-c, --compile" "Compile to JavaScript and save as .js files") |
82 | 84 | (.option "-i, --interactive" "Run an interactive wisp REPL") |
83 | | - (.option "--debug, --print <type>" "Print debug information. Possible values are `form`, `ast` and `js-ast`") |
| 85 | + (.option "--debug, --print <type>" "Print debug information. Possible values are `expansion`,`forms`, `ast` and `js-ast`") |
84 | 86 | (.option "-o, --output <dir>" "Output to specified directory") |
85 | 87 | (.option "--no-map" "Disable source map generation") |
86 | 88 | (.parse process.argv)) |
87 | 89 | (set! (aget options "no-map") (not (aget options "map"))) ;; commander auto translates to camelCase |
88 | | - (cond options.run (run options.args) |
| 90 | + (cond options.run (run (get options.args 0)) |
89 | 91 | (not process.stdin.isTTY) (compile-stdin options) |
90 | 92 | options.interactive (start-repl) |
91 | | - options.compile (compile-file options.args options) |
| 93 | + options.compile (compile-files options.args options) |
92 | 94 | options.args (run options.args) |
93 | 95 | :else (start-repl) |
94 | 96 | ))) |
0 commit comments