Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix init project exception on windows #17

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Some differences have been documented, see [Differences with Clojure](doc/differ

# Quick starts

> The minimum JDK version is 11

- [Plain Dart](doc/quick-start.md) (recommended first step)
- [With Flutter](doc/flutter-quick-start.md)

Expand Down
34 changes: 22 additions & 12 deletions clj/src/cljd/build.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

(def ^:dynamic *ansi* false)
(def ^:dynamic *config* {})
(def ^:dynamic *may-dart* ["dart"])
(def ^:dynamic *flutter* "flutter")
(def ^:dynamic *path* "PATH")

(defn compile-core []
(compiler/compile 'cljd.core))
Expand Down Expand Up @@ -116,19 +119,22 @@
pb (doto (ProcessBuilder. [])
(-> .environment (.putAll env))
(cond->
in (.redirectInput in)
err (.redirectError err)
out (.redirectOutput out)))
path (-> pb .environment (get "PATH"))
in (.redirectInput in)
err (.redirectError err)
out (.redirectOutput out)))
path (-> pb .environment (get *path*))
full-bin
(or
(some (fn [dirname]
(let [file (java.io.File. dirname bin)]
(when (and (.isFile file) (.canExecute file))
(.getAbsolutePath file))))
(.split path java.io.File/pathSeparator))
(let [have-file? #(let [file (java.io.File. dirname %)]
(when (and (.isFile file) (.canExecute file))
(.getAbsolutePath file)))]
(if (vector? bin)
(some have-file? bin)
(have-file? bin))))
(.split path java.io.File/pathSeparator))
(throw (ex-info (str "Can't find " bin " on PATH.")
{:bin bin :path path})))
{:bin bin :path path})))
process (.start (doto pb (.command (into [full-bin] args))))]
(if-not async
(let [exit-code (.waitFor process)]
Expand Down Expand Up @@ -216,7 +222,7 @@
(when flutter
(println (title (str/join " " (into ["Lauching flutter run"] flutter)))))
(let [p (some->> flutter
(apply exec {:async true :in nil :env {"TERM" ""}} "flutter" "run"))]
(apply exec {:async true :in nil :env {"TERM" ""}} *flutter* "run"))]
(try
(let [flutter-stdin (some-> p .getOutputStream (java.io.OutputStreamWriter. "UTF-8"))]
(when flutter-stdin
Expand Down Expand Up @@ -246,9 +252,9 @@
(or
(case bin
"flutter"
(apply exec bin "create" (concat bin-opts [(System/getProperty "user.dir")]))
(apply exec *flutter* "create" (concat bin-opts [(System/getProperty "user.dir")]))
"dart"
(apply exec bin "create" "--force" (concat bin-opts [(System/getProperty "user.dir")])))
(apply exec *may-dart* "create" "--force" (concat bin-opts [(System/getProperty "user.dir")])))
(spit (java.io.File. (System/getProperty "user.dir") "cljd.edn") (pr-str {:main main-ns :bin bin}))
(spit entry-point (str "export " (with-out-str (compiler/write-string-literal lib)) " show main;\n"))
(println "👍" (green "All setup!") "Let's write some cljd in" main-ns))))
Expand Down Expand Up @@ -337,11 +343,15 @@

(defn -main [& args]
(let [f (java.io.File. (System/getProperty "user.dir") "cljd.edn")
is-windows? (str/includes? (str/lower-case (or (System/getProperty "os.name") "")) "windows")
config (if (.exists f)
(with-open [rdr (-> f io/reader java.io.PushbackReader.)]
(edn/read rdr))
{})]
(binding [*ansi* (and (System/console) (get (System/getenv) "TERM"))
*may-dart* (if is-windows? ["dart.exe" "dart.bat"] *may-dart*)
*flutter* (if is-windows? "flutter.bat" *flutter*)
*path* (if is-windows? "Path" *path*)
*config* config
compiler/*lib-path*
(str (.getPath (java.io.File. (System/getProperty "user.dir") "lib")) "/")]
Expand Down