Permalink
Browse files

Add nodels, a nodejs demo that uses fs and path. Refs #52

  • Loading branch information...
1 parent 8fa1501 commit ad38da9e107653e52a1493c4c2cb45c42c9e7202 @Chouser Chouser committed Jul 18, 2011
Showing with 24 additions and 1 deletion.
  1. +17 −0 samples/nodels.cljs
  2. +3 −0 src/cljs/cljs/nodejs.cljs
  3. +4 −1 src/cljs/cljs/nodejscli.cljs
View
@@ -0,0 +1,17 @@
+; This one doesn't yet work with :optimizations :advanced
+(ns nodels
+ (:require [cljs.nodejs :as nodejs]))
+
+(def fs (nodejs/require "fs"))
+(def path (nodejs/require "path"))
+
+(defn file-seq [dir]
+ (tree-seq
+ (fn [f] (.isDirectory (.statSync fs f) ()))
+ (fn [d] (map #(.join path d %) (.readdirSync fs d)))
+ dir))
+
+(defn -main [& paths]
+ (dorun (map println (mapcat file-seq paths))))
+
+(set! *main-cli-fn* -main)
@@ -1,3 +1,6 @@
+; Projects compiled with :target :nodejs can 'require' this namespace
+; to get the nodejs globals loaded into cljs.nodejs and get
+; ClojureScript's 'print' set up correctly.
(ns cljs.nodejs)
; Define namespaced references to Node's externed globals:
@@ -1,6 +1,9 @@
+; Projects compiled with :target :nodejs have this file appended. Its
+; job is to make sure cljs.nodejs is loaded and that the *main-cli-fn*
+; is called with the script's command-line arguments.
(ns cljs.nodejscli
(:require [cljs.nodejs :as nodejs]))
; Call the user's main function
-(apply cljs.core/*main-cli-fn* (.argv nodejs/process))
+(apply cljs.core/*main-cli-fn* (drop 2 (.argv nodejs/process)))

0 comments on commit ad38da9

Please sign in to comment.