소스 검색

Split desktop and mobile dev to separate ns's (#5864)

Also replace shell script which required external deps with a bb fn
Gabriel Horner 3 년 전
부모
커밋
54c886597c
6개의 변경된 파일117개의 추가작업 그리고 102개의 파일을 삭제
  1. 13 13
      bb.edn
  2. 0 20
      scripts/set-system-env.sh
  3. 3 68
      scripts/src/logseq/tasks/dev.clj
  4. 21 0
      scripts/src/logseq/tasks/dev/desktop.clj
  5. 73 0
      scripts/src/logseq/tasks/dev/mobile.clj
  6. 7 1
      scripts/src/logseq/tasks/util.clj

+ 13 - 13
bb.edn

@@ -13,14 +13,14 @@
  {clj-kondo/clj-kondo {:version "2022.02.09"}
   org.babashka/fswatcher {:version "0.0.3"}}
  :tasks
- {dev:watch
-  logseq.tasks.dev/watch
+ {dev:desktop-watch
+  logseq.tasks.dev.desktop/watch
 
   dev:open-dev-electron-app
-  logseq.tasks.dev/open-dev-electron-app
+  logseq.tasks.dev.desktop/open-dev-electron-app
 
   -dev:electron-start
-  {:depends [dev:watch dev:open-dev-electron-app]}
+  {:depends [dev:desktop-watch dev:open-dev-electron-app]}
 
   dev:electron-start
   {:doc "Start electron dev by watching assets and opening dev app"
@@ -28,34 +28,34 @@
    :task (run '-dev:electron-start {:parallel true})}
 
   dev:app-watch
-  logseq.tasks.dev/app-watch
+  logseq.tasks.dev.mobile/app-watch
 
   dev:npx-cap-run-ios
-  logseq.tasks.dev/npx-cap-run-ios
+  logseq.tasks.dev.mobile/npx-cap-run-ios
 
   -dev:ios-app
   {:depends [dev:app-watch dev:npx-cap-run-ios]}
-  
+
   dev:ios-app
   {:doc "iOS development environment"
    :task (run '-dev:ios-app {:parallel true})}
 
   release:ios-app
-  logseq.tasks.dev/run-ios-release
+  logseq.tasks.dev.mobile/run-ios-release
 
   dev:npx-cap-run-android
-  logseq.tasks.dev/npx-cap-run-android
+  logseq.tasks.dev.mobile/npx-cap-run-android
 
   -dev:android-app
   {:depends [dev:app-watch dev:npx-cap-run-android]}
-  
+
   dev:android-app
   {:doc "Android development environment"
    :task (run '-dev:android-app {:parallel true})}
-  
+
   release:android-app
-  logseq.tasks.dev/run-android-release
-  
+  logseq.tasks.dev.mobile/run-android-release
+
   dev:validate-local-storage
   logseq.tasks.spec/validate-local-storage
 

+ 0 - 20
scripts/set-system-env.sh

@@ -1,20 +0,0 @@
-#!/bin/bash
-
-if uname -s | grep -q Darwin; then
-  SED=gsed
-else
-  SED=sed
-fi
-
-PROTOCOL="http"
-IP=$(ipconfig getifaddr en0)
-PORT="3001"
-LOGSEQ_APP_SERVER_URL="${PROTOCOL}://${IP}:${PORT}"
-echo -e "Server URL: ${LOGSEQ_APP_SERVER_URL}"
-
-git checkout capacitor.config.ts
-$SED -i 's#// , server:# , server:#g' capacitor.config.ts
-$SED -i 's#//    url:#    url:#g' capacitor.config.ts
-$SED -i 's#process.env.LOGSEQ_APP_SERVER_URL#"'${LOGSEQ_APP_SERVER_URL}'"#g' capacitor.config.ts
-$SED -i 's#//    cleartext:#    cleartext:#g' capacitor.config.ts
-$SED -i 's#// }# }#g' capacitor.config.ts

+ 3 - 68
scripts/src/logseq/tasks/dev.clj

@@ -1,72 +1,7 @@
 (ns logseq.tasks.dev
-  "Tasks for development"
-  (:require [babashka.fs :as fs]
-            [babashka.tasks :refer [shell]]))
-
-(defn watch
-  "Watches environment to reload cljs, css and other assets"
-  []
-  (shell "yarn electron-watch"))
-
-(defn- file-modified-later-than?
-  [file comparison-instant]
-  (pos? (.compareTo (fs/file-time->instant (fs/last-modified-time file))
-                    comparison-instant)))
-
-;; Works whether yarn clean has been run before or not
-(defn open-dev-app
-  "Opens dev app when watch process has built main.js"
-  [cmd]
-  (let [start-time (java.time.Instant/now)]
-    (loop [n 1000]
-      (if (and (fs/exists? "static/js/main.js")
-               (file-modified-later-than? "static/js/main.js" start-time))
-        (shell cmd)
-        (println "Waiting for app to build..."))
-      (Thread/sleep 1000)
-      (when-not (or (and (fs/exists? "ios/App/App/public/static/js/main.js")
-                      (file-modified-later-than? "ios/App/App/public/static/js/main.js" start-time))
-                    (and (fs/exists? "android/App/src/main/assets/public/static/js/main.js")
-                      (file-modified-later-than? "android/App/src/main/assets/public/static/js/main.js" start-time)))
-        (recur (dec n))))))
-
-(defn open-dev-electron-app
-  "Opens dev-electron-app when watch process has built main.js"
-  []
-  (open-dev-app "yarn dev-electron-app"))
-
-(defn app-watch
-  "Watches environment to reload cljs, css and other assets for mobile"
-  []
-  (doseq [cmd ["bash scripts/set-system-env.sh"
-               "yarn clean"
-               "yarn app-watch"]]
-    (println cmd)
-    (shell cmd)))
-
-(defn npx-cap-run-ios
-  "Copy assets files to iOS build directory, and run app in Xcode"
-  []
-  (open-dev-app "npx cap sync ios")
-  (shell "npx cap open ios"))
-
-(defn npx-cap-run-android
-  "Copy assets files to Android build directory, and run app in Android Studio"
-  []
-  (open-dev-app "npx cap sync android")
-  (shell "npx cap open android"))
-
-(defn run-ios-release
-  "Build iOS app release"
-  []
-  (shell "git checkout capacitor.config.ts")
-  (shell "yarn run-ios-release"))
-
-(defn run-android-release
-  "Build Android app release"
-  []
-  (shell "git checkout capacitor.config.ts")
-  (shell "yarn run-android-release"))
+  "Tasks for general development. For desktop or mobile development see their
+  namespaces"
+  (:require [babashka.tasks :refer [shell]]))
 
 (defn lint
   "Run all lint tasks

+ 21 - 0
scripts/src/logseq/tasks/dev/desktop.clj

@@ -0,0 +1,21 @@
+(ns logseq.tasks.dev.desktop
+  "Tasks for desktop (electron) development"
+  (:require [babashka.tasks :refer [shell]]
+            [babashka.fs :as fs]
+            [logseq.tasks.util :as task-util]))
+
+(defn watch
+  "Watches environment to reload cljs, css and other assets"
+  []
+  (shell "yarn electron-watch"))
+
+(defn open-dev-electron-app
+  "Opens dev-electron-app when watch process has built main.js"
+  []
+  (let [start-time (java.time.Instant/now)]
+    (dotimes [_n 1000]
+             (if (and (fs/exists? "static/js/main.js")
+                      (task-util/file-modified-later-than? "static/js/main.js" start-time))
+               (shell "yarn dev-electron-app")
+               (println "Waiting for app to build..."))
+             (Thread/sleep 1000))))

+ 73 - 0
scripts/src/logseq/tasks/dev/mobile.clj

@@ -0,0 +1,73 @@
+(ns logseq.tasks.dev.mobile
+  "Tasks for mobile development"
+  (:require [babashka.tasks :refer [shell]]
+            [babashka.fs :as fs]
+            [clojure.string :as string]
+            [logseq.tasks.util :as task-util]))
+
+(defn- open-dev-app
+  "Opens mobile app when watch process has built main.js"
+  [cmd]
+  (let [start-time (java.time.Instant/now)]
+    (loop [n 1000]
+      (if (and (fs/exists? "static/js/main.js")
+               (task-util/file-modified-later-than? "static/js/main.js" start-time))
+        (shell cmd)
+        (println "Waiting for app to build..."))
+      (Thread/sleep 1000)
+      (when-not (or (and (fs/exists? "ios/App/App/public/static/js/main.js")
+                      (task-util/file-modified-later-than? "ios/App/App/public/static/js/main.js" start-time))
+                    (and (fs/exists? "android/App/src/main/assets/public/static/js/main.js")
+                      (task-util/file-modified-later-than? "android/App/src/main/assets/public/static/js/main.js" start-time)))
+        (recur (dec n))))))
+
+(defn- set-system-env
+  "Updates capacitor.config.ts serve url with IP from ifconfig"
+  []
+  (let [ip (string/trim (:out (shell {:out :string} "ipconfig getifaddr en0")))
+        logseq-app-server-url (format "%s://%s:%s" "http" ip "3001")]
+    (println "Server URL:" logseq-app-server-url)
+    (shell "git checkout capacitor.config.ts")
+    (let [new-body (-> (slurp "capacitor.config.ts")
+                       (string/replace "// , server:" " , server:")
+                       (string/replace "//    url:" "    url:")
+                       (string/replace "process.env.LOGSEQ_APP_SERVER_URL"
+                                       (pr-str logseq-app-server-url))
+                       (string/replace "//    cleartext:" "    cleartext:")
+                       (string/replace "// }" " }"))]
+      (spit "capacitor.config.ts" new-body))))
+
+
+(defn app-watch
+  "Watches environment to reload cljs, css and other assets for mobile"
+  []
+  (println "set-system-env")
+  (set-system-env)
+  (doseq [cmd ["yarn clean"
+               "yarn app-watch"]]
+    (println cmd)
+    (shell cmd)))
+
+(defn npx-cap-run-ios
+  "Copy assets files to iOS build directory, and run app in Xcode"
+  []
+  (open-dev-app "npx cap sync ios")
+  (shell "npx cap open ios"))
+
+(defn npx-cap-run-android
+  "Copy assets files to Android build directory, and run app in Android Studio"
+  []
+  (open-dev-app "npx cap sync android")
+  (shell "npx cap open android"))
+
+(defn run-ios-release
+  "Build iOS app release"
+  []
+  (shell "git checkout capacitor.config.ts")
+  (shell "yarn run-ios-release"))
+
+(defn run-android-release
+  "Build Android app release"
+  []
+  (shell "git checkout capacitor.config.ts")
+  (shell "yarn run-android-release"))

+ 7 - 1
scripts/src/logseq/tasks/util.clj

@@ -1,6 +1,12 @@
 (ns logseq.tasks.util
   "Utils for tasks"
-  (:require [clojure.pprint :as pprint]))
+  (:require [clojure.pprint :as pprint]
+            [babashka.fs :as fs]))
+
+(defn file-modified-later-than?
+  [file comparison-instant]
+  (pos? (.compareTo (fs/file-time->instant (fs/last-modified-time file))
+                    comparison-instant)))
 
 (defn print-usage [arg-str]
   (println (format