@@ -1450,7 +1450,8 @@ should contain the source for the given namespace name."
1450
1450
(defn watch
1451
1451
" Given a source directory, produce runnable JavaScript. Watch the source
1452
1452
directory for changes rebuliding when necessary. Takes the same arguments as
1453
- cljs.closure/build."
1453
+ cljs.closure/build in addition to :watch-fn, a function of no arguments to
1454
+ run after a successful build."
1454
1455
([source opts]
1455
1456
(watch source opts
1456
1457
(if-not (nil? env/*compiler*)
@@ -1461,11 +1462,16 @@ should contain the source for the given namespace name."
1461
1462
fs (.getFileSystem path)
1462
1463
service (.newWatchService fs)]
1463
1464
(letfn [(buildf []
1464
- (let [start (System/nanoTime )]
1465
- (build source opts compiler-env)
1466
- (println " ... done. Elapsed"
1467
- (/ (unchecked-subtract (System/nanoTime ) start) 1e9 ) " seconds" )
1468
- (flush )))
1465
+ (try
1466
+ (let [start (System/nanoTime )]
1467
+ (build source opts compiler-env)
1468
+ (println " ... done. Elapsed"
1469
+ (/ (unchecked-subtract (System/nanoTime ) start) 1e9 ) " seconds" )
1470
+ (flush ))
1471
+ (when-let [f (:watch-fn opts)]
1472
+ (f ))
1473
+ (catch Throwable e
1474
+ (.printStackTrace e))))
1469
1475
(watch-all [^Path root]
1470
1476
(Files/walkFileTree root
1471
1477
(reify
@@ -1501,10 +1507,7 @@ should contain the source for the given namespace name."
1501
1507
(seq (.pollEvents key)))
1502
1508
(println " Change detected, recompiling..." )
1503
1509
(flush )
1504
- (try
1505
- (buildf )
1506
- (catch Exception e
1507
- (.printStackTrace e))))
1510
+ (buildf ))
1508
1511
(recur key))))))))
1509
1512
1510
1513
(comment
@@ -1514,7 +1517,10 @@ should contain the source for the given namespace name."
1514
1517
:output-dir " samples/hello/out"
1515
1518
:cache-analysis true
1516
1519
:source-map true
1517
- :verbose true })
1520
+ :verbose true
1521
+ :watch-fn
1522
+ (fn []
1523
+ (println " Success!" ))})
1518
1524
)
1519
1525
1520
1526
; ; =============================================================================
0 commit comments