16
16
[cljs.env :as env]
17
17
[cljs.analyzer :as ana]
18
18
[cljs.compiler :as comp]))
19
+
20
+ ; ; =============================================================================
21
+ ; ; Main API
22
+
23
+ (defn emit
24
+ " Given an AST node generated by the analyzer emit JavaScript as a string."
25
+ [ast]
26
+ (with-out-str
27
+ (comp/emit ast)))
28
+
29
+ (defn with-core-cljs
30
+ " Ensure that core.cljs has been loaded."
31
+ ([] (comp/with-core-cljs nil ))
32
+ ([opts] (comp/with-core-cljs opts (fn [])))
33
+ ([opts body] (comp/with-core-cljs opts body)))
34
+
35
+ (defn requires-compilation?
36
+ " Return true if the src file requires compilation."
37
+ ([src dest]
38
+ (comp/requires-compilation? src dest nil ))
39
+ ([src dest opts]
40
+ (comp/requires-compilation? src dest opts)))
41
+
42
+ (defn compile-file
43
+ " Compiles src to a file of the same name, but with a .js extension,
44
+ in the src file's directory.
45
+
46
+ With dest argument, write file to provided location. If the dest
47
+ argument is a file outside the source tree, missing parent
48
+ directories will be created. The src file will only be compiled if
49
+ the dest file has an older modification time.
50
+
51
+ Both src and dest may be either a String or a File.
52
+
53
+ Returns a map containing {:ns .. :provides .. :requires .. :file ..}.
54
+ If the file was not compiled returns only {:file ...}"
55
+ ([src]
56
+ (comp/compile-file src))
57
+ ([src dest]
58
+ (comp/compile-file src dest))
59
+ ([src dest opts]
60
+ (comp/compile-file src dest opts)))
61
+
62
+ (defn cljs-files-in
63
+ " Return a sequence of all .cljs and .cljc files in the given directory."
64
+ [dir]
65
+ (comp/cljs-files-in dir))
66
+
67
+ (defn compile-root
68
+ " Looks recursively in src-dir for .cljs files and compiles them to
69
+ .js files. If target-dir is provided, output will go into this
70
+ directory mirroring the source directory structure. Returns a list
71
+ of maps containing information about each file which was compiled
72
+ in dependency order."
73
+ ([src-dir]
74
+ (comp/compile-root src-dir " out" ))
75
+ ([src-dir target-dir]
76
+ (comp/compile-root src-dir target-dir nil ))
77
+ ([src-dir target-dir opts]
78
+ (comp/compile-root src-dir target-dir opts)))
0 commit comments