Browse Source

chore(dev): just one command for ios/android development

charlie 3 years ago
parent
commit
9b57580962
4 changed files with 89 additions and 33 deletions
  1. 32 26
      capacitor.config.ts
  2. 42 5
      gulpfile.js
  3. 5 2
      package.json
  4. 10 0
      yarn.lock

+ 32 - 26
capacitor.config.ts

@@ -1,32 +1,38 @@
-import { CapacitorConfig } from '@capacitor/cli';
+import { CapacitorConfig } from '@capacitor/cli'
 
 const config: CapacitorConfig = {
-    appId: 'com.logseq.app',
-    appName: 'Logseq',
-    bundledWebRuntime: false,
-    webDir: 'public',
-    plugins: {
-        SplashScreen: {
-            launchShowDuration: 500,
-            launchAutoHide: false,
-            androidScaleType: "CENTER_CROP",
-            splashImmersive: false,
-            backgroundColor: "#002b36"
-        },
-
-        Keyboard: {
-            resize: "none"
-        }
+  appId: 'com.logseq.app',
+  appName: 'Logseq',
+  bundledWebRuntime: false,
+  webDir: 'public',
+  plugins: {
+    SplashScreen: {
+      launchShowDuration: 500,
+      launchAutoHide: false,
+      androidScaleType: 'CENTER_CROP',
+      splashImmersive: false,
+      backgroundColor: '#002b36'
     },
-    ios: {
-        scheme: "Logseq"
+
+    Keyboard: {
+      resize: 'none'
+    }
+  },
+  ios: {
+    scheme: 'Logseq'
+  }
+}
+
+if (
+  process.env.PLATFORM &&
+  process.env.LOGSEQ_APP_SERVER_URL
+) {
+  Object.assign(config, {
+    server: {
+      url: process.env.LOGSEQ_APP_SERVER_URL,
+      cleartext: true
     }
-    // do not commit this into source control
-    // source: https://capacitorjs.com/docs/guides/live-reload
-    // , server: {
-    //    url: process.env.LOGSEQ_APP_SERVER_URL,
-    //    cleartext: true
-    // }
-};
+  })
+}
 
 export = config;

+ 42 - 5
gulpfile.js

@@ -6,6 +6,7 @@ const path = require('path')
 const gulp = require('gulp')
 const cleanCSS = require('gulp-clean-css')
 const del = require('del')
+const ip = require('ip')
 
 const outputPath = path.join(__dirname, 'static')
 const resourcesPath = path.join(__dirname, 'resources')
@@ -49,13 +50,13 @@ const common = {
   syncAssetFiles (...params) {
     return gulp.series(
       () => gulp.src([
-          "./node_modules/@excalidraw/excalidraw/dist/excalidraw-assets/**",
-          "!**/*/i18n-*.js"
-        ])
+        './node_modules/@excalidraw/excalidraw/dist/excalidraw-assets/**',
+        '!**/*/i18n-*.js'
+      ])
         .pipe(gulp.dest(path.join(outputPath, 'js', 'excalidraw-assets'))),
-      () => gulp.src("node_modules/@tabler/icons/iconfont/tabler-icons.min.css")
+      () => gulp.src('node_modules/@tabler/icons/iconfont/tabler-icons.min.css')
         .pipe(gulp.dest(path.join(outputPath, 'css'))),
-      () => gulp.src("node_modules/@tabler/icons/iconfont/fonts/**")
+      () => gulp.src('node_modules/@tabler/icons/iconfont/fonts/**')
         .pipe(gulp.dest(path.join(outputPath, 'css', 'fonts'))),
     )(...params)
   },
@@ -83,6 +84,41 @@ const common = {
       path.join(outputPath, 'js/**'),
       path.join(outputPath, 'css/**')
     ], { ignoreInitial: true }, common.syncJS_CSSinRt)
+  },
+
+  async env (cb) {
+    const mode = process.env.PLATFORM || 'ios'
+
+    const IP = ip.address()
+    const LOGSEQ_APP_SERVER_URL = `http://${IP}:3001`
+
+    if (typeof global.fetch != null) {
+      try {
+        await fetch(LOGSEQ_APP_SERVER_URL)
+      } catch (e) {
+        return cb(new Error(`/* ❌ Please check if the service is ON. (${LOGSEQ_APP_SERVER_URL}) ❌ */`))
+      }
+    }
+
+    console.log(`------ Cap ${mode.toUpperCase()} -----`)
+    console.log(`Dev serve at: ${LOGSEQ_APP_SERVER_URL}`)
+    console.log(`--------------------------------------`)
+
+    cp.execSync(`npx cap sync ${mode}`, {
+      stdio: 'inherit',
+      env: Object.assign(process.env, {
+        LOGSEQ_APP_SERVER_URL
+      })
+    })
+
+    cp.execSync(`npx cap run ${mode} --external`, {
+      stdio: 'inherit',
+      env: Object.assign(process.env, {
+        LOGSEQ_APP_SERVER_URL
+      })
+    })
+
+    cb()
   }
 }
 
@@ -130,6 +166,7 @@ exports.electronMaker = async () => {
   })
 }
 
+exports.env = common.env
 exports.clean = common.clean
 exports.watch = gulp.series(common.syncResourceFile, common.syncAssetFiles, common.syncAllStatic,
   gulp.parallel(common.keepSyncResourceFile, css.watchCSS))

+ 5 - 2
package.json

@@ -26,7 +26,8 @@
         "stylelint": "^13.8.0",
         "stylelint-config-standard": "^20.0.0",
         "tailwindcss": "2.2.16",
-        "typescript": "^4.4.3"
+        "typescript": "^4.4.3",
+        "ip": "1.1.8"
     },
     "scripts": {
         "watch": "run-p gulp:watch cljs:watch",
@@ -63,7 +64,9 @@
         "cljs:debug": "clojure -M:cljs release app --debug",
         "cljs:report": "clojure -M:cljs run shadow.cljs.build-report app report.html",
         "cljs:build-electron": "clojure -A:cljs compile app electron",
-        "cljs:lint": "clojure -M:clj-kondo --parallel --lint src --cache false"
+        "cljs:lint": "clojure -M:clj-kondo --parallel --lint src --cache false",
+        "ios:dev": "cross-env PLATFORM=ios gulp env",
+        "android:dev": "cross-env PLATFORM=android gulp env"
     },
     "dependencies": {
         "@capacitor/android": "3.2.2",

+ 10 - 0
yarn.lock

@@ -3706,6 +3706,16 @@ invert-kv@^2.0.0:
   resolved "https://registry.yarnpkg.com/invert-kv/-/invert-kv-2.0.0.tgz#7393f5afa59ec9ff5f67a27620d11c226e3eec02"
   integrity sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA==
 
[email protected]:
+  version "1.1.8"
+  resolved "https://registry.yarnpkg.com/ip/-/ip-1.1.8.tgz#ae05948f6b075435ed3307acce04629da8cdbf48"
+  integrity sha512-PuExPYUiu6qMBQb4l06ecm6T6ujzhmh+MeJcW9wa89PoAz5pvd4zPgN5WJV104mb6S2T1AwNIAaB70JNrLQWhg==
+
+is-absolute-url@^2.0.0:
+  version "2.1.0"
+  resolved "https://registry.yarnpkg.com/is-absolute-url/-/is-absolute-url-2.1.0.tgz#50530dfb84fcc9aa7dbe7852e83a37b93b9f2aa6"
+  integrity sha1-UFMN+4T8yap9vnhS6Do3uTufKqY=
+
 is-absolute@^1.0.0:
   version "1.0.0"
   resolved "https://registry.yarnpkg.com/is-absolute/-/is-absolute-1.0.0.tgz#395e1ae84b11f26ad1795e73c17378e48a301576"