Browse Source

fix: fix code-editor and other extensions not working when publishing

Also, removed unused files for publishing
Tienson Qin 4 years ago
parent
commit
5ce319415c

+ 1 - 1
gulpfile.js

@@ -90,7 +90,7 @@ exports.electron = () => {
 }
 
 exports.electronMaker = async () => {
-  cp.execSync('yarn cljs:electron-release', {
+  cp.execSync('yarn cljs:release', {
     stdio: 'inherit'
   })
 

+ 27 - 15
src/electron/electron/core.cljs

@@ -56,26 +56,38 @@
   #(.unregisterProtocol protocol "assets"))
 
 (defn- handle-export-publish-assets [_event html]
-  (let
-   [app-path (. app getAppPath)
-    paths (js->clj (. dialog showOpenDialogSync (clj->js {:properties ["openDirectory" "createDirectory" "promptToCreate", "multiSelections"]})))]
-    (when (vector? paths)
-      (let [root-dir (first (js->clj paths))
+  (let [app-path (. app getAppPath)
+        paths (js->clj (. dialog showOpenDialogSync (clj->js {:properties ["openDirectory" "createDirectory" "promptToCreate", "multiSelections"]})))]
+    (when (seq paths)
+      (let [root-dir (first paths)
             static-dir (path/join root-dir "static")
             path (path/join root-dir "index.html")]
-        (p/let [_ (. fs ensureDir static-dir)]
-          (let  [_ (p/all  (concat
-                            [(. fs writeFile
-                                path
-                                html)]
-                            [(. fs copy (path/join app-path "404.html") (path/join root-dir "404.html"))]
-
-                            (map
+        (p/let [_ (. fs ensureDir static-dir)
+                _ (p/all  (concat
+                           [(. fs writeFile path html)
+                            (. fs copy (path/join app-path "404.html") (path/join root-dir "404.html"))]
+
+                           (map
                              (fn [part]
                                (. fs copy (path/join app-path part) (path/join static-dir part)))
-                             ["css" "fonts" "icons" "img" "js" "dev.html"])))]
+                             ["css" "fonts" "icons" "img" "js"])))
+                js-files ["main.js" "code-editor.js" "excalidraw.js"]
+                _ (p/all (map (fn [file]
+                                (. fs removeSync (path/join static-dir "js" file)))
+                           js-files))
+                _ (p/all (map (fn [file]
+                                (. fs moveSync
+                                   (path/join static-dir "js" "publishing" file)
+                                   (path/join static-dir "js" file)))
+                           js-files))
+                _ (. fs removeSync (path/join static-dir "js" "publishing"))
+                ;; remove source map files
+                ;; TODO: ugly, replace with ls-files and filter with ".map"
+                _ (p/all (map (fn [file]
+                                (. fs removeSync (path/join static-dir "js" (str file ".map"))))
+                           ["main.js" "code-editor.js" "excalidraw.js" "age-encryption.js"]))]
+          (. dialog showMessageBox (clj->js {:message (str "Export publish assets to " root-dir " successfully")})))))))
 
-            (. dialog showMessageBox (clj->js {:message (str "Export publish assets to " root-dir " successfully")}))))))))
 (defn setup-app-manager!
   [^js win]
   (let [toggle-win-channel "toggle-max-or-min-active-win"

+ 8 - 1
src/main/frontend/config.cljs

@@ -28,10 +28,17 @@
 (def asset-domain (util/format "https://asset.%s.com"
                                app-name))
 
+;; TODO: Remove this, switch to lazy loader
 (defn asset-uri
   [path]
-  (if (util/file-protocol?)
+  (cond
+    publishing?
+    path
+
+    (util/file-protocol?)
     (string/replace path "/static/" "./")
+
+    :else
     (if dev? path
         (str asset-domain path))))
 

+ 1 - 1
src/main/frontend/dicts.cljs

@@ -229,7 +229,7 @@ title: How to take dummy notes?
         :page/open-in-finder "Open in directory"
         :page/open-with-default-app "Open with default app"
         :page/action-publish "Publish"
-        :page/make-public "Publish it for export"
+        :page/make-public "Make it public for publishing"
         :page/make-private "Make it private"
         :page/delete "Delete page"
         :page/publish "Publish this page on Logseq"

+ 1 - 1
src/main/frontend/publishing/html.cljs

@@ -84,4 +84,4 @@
             ;; TODO: should make this configurable
            [:script {:src "/static/js/highlight.min.js"}]
            [:script {:src "/static/js/interact.min.js"}]
-           [:script {:src "/static/js/publishing/main.js"}]]))))
+           [:script {:src "/static/js/main.js"}]]))))