Skip to content

Commit

Permalink
feat: support windows for sdk generating
Browse files Browse the repository at this point in the history
  • Loading branch information
octoshikari committed Jun 23, 2023
1 parent cc438fb commit d34cc06
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
11 changes: 8 additions & 3 deletions build/build.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
(ns build
(:require [clojure.tools.build.api :as b]))

(def class-dir "target/classes")
(def class-dir (.getPath (clojure.java.io/file "target" (java.io.File/separator) "classes")))
(def basis (b/create-basis {:project "deps.edn"}))
(def uber-file "target/zen.jar")
(def uber-file (.getPath (clojure.java.io/file "target" (java.io.File/separator) "zen.jar")))

(defn clean [_]
(b/delete {:path "target"}))
Expand All @@ -18,4 +18,9 @@
(b/uber {:class-dir class-dir
:uber-file uber-file
:basis basis
:main 'generator.cli}))
:main 'generator.cli}))


(comment

(uber {}))
18 changes: 12 additions & 6 deletions src/generator/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
(when (empty? (filter #(= (.getPath %) (.getPath f)) @processed))
(when (and (.isFile f) (not= out-fname (.getPath ^File f)))
(let [entry-name (relativise-path (.getPath input-name) (-> f .getPath))
#_(println entry-name (str input-name))
entry (.createArchiveEntry a f entry-name)]
(.putArchiveEntry a entry)
(when (.isFile f)
Expand Down Expand Up @@ -313,16 +312,20 @@


(defn sdk [path]
(let [ztx (zen.core/new-context {:package-paths [path]})]
(let [ztx (zen.core/new-context {:package-paths [path]})
win? (str/includes? (str/lower-case (System/getProperty "os.name")) "windows")]
(io/make-parents (io/file path "package" "types" "index.ts"))
(when (gen-types ztx path "package/types")
(copy-from-resources (io/resource "index.ts") (io/file path "package" "index.ts"))
(copy-from-resources (io/resource "tsconfig.json") (io/file path "package" "tsconfig.json"))
(copy-from-resources (io/resource "package.json") (io/file path "package" "package.json"))
(println "[sdk] Run prettier for source files")
(shell/sh "npx" "prettier" "--write" "." :dir (io/file path "package"))
(shell/sh "npm" "install" :dir (io/file path "package"))
(shell/sh "npm" "run" "build" :dir (io/file path "package"))
(shell/with-sh-dir (io/file path "package")
(apply shell/sh (if win? ["powershell" "npx" "prettier" "--write ."] ["npx" "prettier" "--write ."])))
(shell/with-sh-dir (io/file path "package")
(apply shell/sh (if win? ["powershell" "npm" "install"] ["npm" "install"])))
(shell/with-sh-dir (io/file path "package")
(apply shell/sh (if win? ["powershell" "npm" "run" "build"] ["npm" "run" "build"])))
(copy-from-resources (io/resource "package.json") (io/file path "package" "lib" "package.json"))
(println "[sdk] Archive generation")
(create-archive "aidbox-javascript-sdk-v1.0.0" (file-seq (io/file path "package" "lib")) (io/file path "..") "gz")
Expand All @@ -333,8 +336,11 @@


(comment
(def win? (str/includes? (str/lower-case (System/getProperty "os.name")) "windows"))
(require ['zen.cli])
(-> (zen.cli/get-pwd {:pwd "/Users/alexanderstreltsov/work/hs/aidbox-sdk-js/zen-project"})


(-> (zen.cli/get-pwd {:pwd "C:\\Users\\mc_do\\aidbox-sdk-js\\zen-project"})
sdk))


0 comments on commit d34cc06

Please sign in to comment.