Add docs and workflow for dep

Also rename dep to publishing for consistency with existing names
This commit is contained in:
Gabriel Horner
2023-04-04 18:12:10 -04:00
committed by Tienson Qin
parent 5186070248
commit fef07fe812
28 changed files with 260 additions and 45 deletions

102
.github/workflows/publishing.yml vendored Normal file
View File

@@ -0,0 +1,102 @@
name: logseq/publishing CI
on:
# Path filters ensure jobs only kick off if a change is made to publishing or
# its local dependencies
push:
branches: [master]
paths:
- 'deps/publishing/**'
# db is a local dep that could break functionality in this lib and should trigger this
- 'deps/db/**'
- '.github/workflows/publishing.yml'
- '!deps/publishing/**.md'
pull_request:
branches: [master]
paths:
- 'deps/publishing/**'
- 'deps/db/**'
- '.github/workflows/publishing.yml'
- '!deps/publishing/**.md'
defaults:
run:
working-directory: deps/publishing
env:
CLOJURE_VERSION: '1.10.1.763'
# This is the same as 1.8.
JAVA_VERSION: '11'
# This is the latest node version we can run.
NODE_VERSION: '18'
BABASHKA_VERSION: '1.0.168'
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'yarn'
cache-dependency-path: deps/publishing/yarn.lock
- name: Set up Java
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: ${{ env.JAVA_VERSION }}
- name: Set up Babashka
uses: DeLaGuardo/setup-clojure@10.1
with:
bb: ${{ env.BABASHKA_VERSION }}
- name: Fetch yarn deps
run: yarn install --frozen-lockfile
- name: Run nbb-logseq tests
run: yarn test
# In this job because it depends on an npm package
- name: Load namespaces into nbb-logseq
run: bb test:load-all-namespaces-with-nbb .
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Java
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: ${{ env.JAVA_VERSION }}
- name: Set up Clojure
uses: DeLaGuardo/setup-clojure@10.1
with:
cli: ${{ env.CLOJURE_VERSION }}
bb: ${{ env.BABASHKA_VERSION }}
- name: Run clj-kondo lint
run: clojure -M:clj-kondo --lint src test
- name: Carve lint for unused vars
run: bb lint:carve
- name: Lint for vars that are too large
run: bb lint:large-vars
- name: Lint for namespaces that aren't documented
run: bb lint:ns-docstrings
- name: Lint for public vars that are private based on usage
run: bb lint:minimize-public-vars

4
bb.edn
View File

@@ -34,9 +34,9 @@
dev:build-publishing dev:build-publishing
logseq.tasks.dev/build-publishing logseq.tasks.dev/build-publishing
dev:publish-spa dev:publishing
{:depends [dev:build-publishing] {:depends [dev:build-publishing]
:doc "Build publish spa app given graph and output dirs" :doc "Build publishing spa app given graph and output dirs"
:task (apply shell {:dir "scripts"} :task (apply shell {:dir "scripts"}
"yarn -s nbb-logseq -cp src -m logseq.tasks.dev.publishing" "yarn -s nbb-logseq -cp src -m logseq.tasks.dev.publishing"
(into ["static"] *command-line-args*))} (into ["static"] *command-line-args*))}

View File

@@ -29,7 +29,7 @@
org.clojars.mmb90/cljs-cache {:mvn/version "0.1.4"} org.clojars.mmb90/cljs-cache {:mvn/version "0.1.4"}
logseq/common {:local/root "deps/common"} logseq/common {:local/root "deps/common"}
logseq/graph-parser {:local/root "deps/graph-parser"} logseq/graph-parser {:local/root "deps/graph-parser"}
logseq/publish-spa {:local/root "deps/publish-spa"} logseq/publishing {:local/root "deps/publishing"}
metosin/malli {:mvn/version "0.10.0"} metosin/malli {:mvn/version "0.10.0"}
fipp/fipp {:mvn/version "0.6.26"}} fipp/fipp {:mvn/version "0.6.26"}}

2
deps/db/README.md vendored
View File

@@ -13,7 +13,7 @@ two main namespaces, `logseq.db` and `logseq.db.rules`.
## Usage ## Usage
See usage in `deps/graph-parser` and in the Logseq app. See the frontend for example usage.
## Dev ## Dev

View File

@@ -18,7 +18,9 @@ CLIs.
## Usage ## Usage
See `logseq.graph-parser.cli-test` for now. A real world example is coming soon. See `logseq.graph-parser.cli-test` and [nbb-logseq example
scripts](https://github.com/logseq/nbb-logseq/tree/main/examples) for example
usage.
## Dev ## Dev
@@ -34,11 +36,11 @@ To run linters and tests, you'll want to install yarn dependencies once:
yarn install yarn install
``` ```
This step is not needed if you're just running the application. This step is not needed if you're just running the frontend application.
### Testing ### Testing
Since this file is compatible with cljs and nbb-logseq, tests are run against both languages. Since this library is compatible with cljs and nbb-logseq, tests are run against both languages.
ClojureScript tests use https://github.com/Olical/cljs-test-runner. To run tests: ClojureScript tests use https://github.com/Olical/cljs-test-runner. To run tests:
``` ```

View File

@@ -1,3 +0,0 @@
{:paths ["src"]
:deps
{logseq/db {:local/root "../db"}}}

4
deps/publishing/.carve/config.edn vendored Normal file
View File

@@ -0,0 +1,4 @@
{:paths ["src"]
:api-namespaces [;; for nbb-logseq CLIs
logseq.publishing]
:report {:format :ignore}}

View File

@@ -7,7 +7,7 @@
{:aliases {clojure.string string}}} {:aliases {clojure.string string}}}
:lint-as :lint-as
{logseq.publish-spa.test.helper/deftest-async clojure.test/deftest {logseq.publishing.test.helper/deftest-async clojure.test/deftest
promesa.core/let clojure.core/let} promesa.core/let clojure.core/let}
:skip-comments true :skip-comments true
:output {:progress true}} :output {:progress true}}

52
deps/publishing/README.md vendored Normal file
View File

@@ -0,0 +1,52 @@
## Description
This library handles exporting the `frontend.publishing` single page
application. This library is compatible with ClojureScript and with
node/[nbb-logseq](https://github.com/logseq/nbb-logseq) to respectively provide
frontend and Electron/commandline functionality.
## API
This library is under the parent namespace `logseq.publishing`. This library
provides two namespaces for node/CLI contexts, `logseq.publishing` and
`logseq.publishing.export` and two namespaces for the frontend,
`logseq.publishing.html` and `logseq.publishing.db`.
## Usage
See `logseq.tasks.dev.publishing` for a CLI example. See the frontend for cljs usage.
## Dev
This follows the practices that [the Logseq frontend
follows](/docs/dev-practices.md). Most of the same linters are used, with
configurations that are specific to this library. See [this library's CI
file](/.github/workflows/publishing.yml) for linting examples.
### Setup
To run linters and tests, you'll want to install yarn dependencies once:
```
yarn install
```
This step is not needed if you're just running the frontend application.
### Testing
Testing is done with nbb-logseq and
[nbb-test-runner](https://github.com/nextjournal/nbb-test-runner). Some basic
usage:
```
# Run all tests
$ yarn test
# List available options
$ yarn test -H
# Run tests with :focus metadata flag
$ yarn test -i focus
```
### Managing dependencies
See [standard nbb/cljs library advice in graph-parser](/deps/graph-parser/README.md#managing-dependencies).

30
deps/publishing/bb.edn vendored Normal file
View File

@@ -0,0 +1,30 @@
{:min-bb-version "1.0.168"
:deps
{logseq/bb-tasks
#_{:local/root "../../../bb-tasks"}
{:git/url "https://github.com/logseq/bb-tasks"
:git/sha "0d49051909bfa0c6b414e86606d82b4ea54f382c"}}
:pods
{clj-kondo/clj-kondo {:version "2023.03.17"}}
:tasks
{test:load-all-namespaces-with-nbb
logseq.bb-tasks.nbb.test/load-all-namespaces
lint:large-vars
logseq.bb-tasks.lint.large-vars/-main
lint:carve
logseq.bb-tasks.lint.carve/-main
lint:ns-docstrings
logseq.bb-tasks.lint.ns-docstrings/-main
lint:minimize-public-vars
logseq.bb-tasks.lint.minimize-public-vars/-main}
:tasks/config
{:large-vars
;; For vars with long running html
{:metadata-exceptions #{:large-vars/html}}}}

7
deps/publishing/deps.edn vendored Normal file
View File

@@ -0,0 +1,7 @@
{:paths ["src"]
:deps
{logseq/db {:local/root "../db"}}
:aliases
{:clj-kondo {:replace-deps {clj-kondo/clj-kondo {:mvn/version "2023.03.17"}}
:main-opts ["-m" "clj-kondo.main"]}}}

View File

@@ -1,5 +1,5 @@
{ {
"name": "@logseq/publish-spa", "name": "@logseq/publishing",
"version": "1.0.0", "version": "1.0.0",
"private": true, "private": true,
"devDependencies": { "devDependencies": {

View File

@@ -1,7 +1,7 @@
(ns logseq.publish-spa (ns logseq.publishing
"This node only ns provides api fns for exporting a publishing app" "This node only ns provides api fns for exporting a publishing app"
(:require [logseq.publish-spa.html :as publish-html] (:require [logseq.publishing.html :as publish-html]
[logseq.publish-spa.export :as publish-export])) [logseq.publishing.export :as publish-export]))
(defn export (defn export
"Exports the given graph-dir and db to the specific output-dir. Most of the graph "Exports the given graph-dir and db to the specific output-dir. Most of the graph

View File

@@ -1,9 +1,10 @@
(ns logseq.publish-spa.db (ns logseq.publishing.db
"Provides db fns and associated util fns for publishing"
(:require [datascript.core :as d] (:require [datascript.core :as d]
[logseq.db.schema :as db-schema] [logseq.db.schema :as db-schema]
[clojure.string :as string])) [clojure.string :as string]))
(defn get-area-block-asset-url (defn ^:api get-area-block-asset-url
"Returns asset url for an area block used by pdf assets. This lives in this ns "Returns asset url for an area block used by pdf assets. This lives in this ns
because it is used by this dep and needs to be indepent from the frontend app" because it is used by this dep and needs to be indepent from the frontend app"
[block page] [block page]

View File

@@ -1,4 +1,4 @@
(ns logseq.publish-spa.export (ns logseq.publishing.export
"This electron only ns (for the main process) exports files from multiple "This electron only ns (for the main process) exports files from multiple
locations to provide a complete publishing app" locations to provide a complete publishing app"
(:require ["fs-extra" :as fse] (:require ["fs-extra" :as fse]
@@ -6,11 +6,11 @@
["fs" :as fs] ["fs" :as fs]
[promesa.core :as p])) [promesa.core :as p]))
(def js-files (def ^:api js-files
"js files from publishing release build" "js files from publishing release build"
["main.js" "code-editor.js" "excalidraw.js" "tldraw.js"]) ["main.js" "code-editor.js" "excalidraw.js" "tldraw.js"])
(def static-dirs (def ^:api static-dirs
"dirs under static dir to copy over" "dirs under static dir to copy over"
["css" "fonts" "icons" "img" "js"]) ["css" "fonts" "icons" "img" "js"])

View File

@@ -1,11 +1,11 @@
(ns logseq.publish-spa.html (ns logseq.publishing.html
"This frontend only ns builds the publishing html including doing all the "This frontend only ns builds the publishing html including doing all the
necessary db filtering" necessary db filtering"
(:require [clojure.string :as string] (:require [clojure.string :as string]
[goog.string :as gstring] [goog.string :as gstring]
[goog.string.format] [goog.string.format]
[datascript.transit :as dt] [datascript.transit :as dt]
[logseq.publish-spa.db :as db])) [logseq.publishing.db :as db]))
;; Copied from hiccup but tweaked for publish usage ;; Copied from hiccup but tweaked for publish usage
;; Any changes here should also be made in frontend.publishing/unescape-html ;; Any changes here should also be made in frontend.publishing/unescape-html
@@ -20,7 +20,7 @@ necessary db filtering"
(string/replace "'" "logseq____'"))) (string/replace "'" "logseq____'")))
;; Copied from https://github.com/babashka/babashka/blob/8c1077af00c818ade9e646dfe1297bbe24b17f4d/examples/notes.clj#L21 ;; Copied from https://github.com/babashka/babashka/blob/8c1077af00c818ade9e646dfe1297bbe24b17f4d/examples/notes.clj#L21
(defn html [v] (defn- html [v]
(cond (vector? v) (cond (vector? v)
(let [tag (first v) (let [tag (first v)
attrs (second v) attrs (second v)
@@ -39,7 +39,7 @@ necessary db filtering"
(string/join " " (map html v)) (string/join " " (map html v))
:else (str v))) :else (str v)))
(defn publishing-html (defn- ^:large-vars/html publishing-html
[transit-db app-state options] [transit-db app-state options]
(let [{:keys [icon name alias title description url]} options (let [{:keys [icon name alias title description url]} options
icon (or icon "static/img/logo.png") icon (or icon "static/img/logo.png")

View File

@@ -1,7 +1,7 @@
(ns logseq.publish-spa.db-test (ns logseq.publishing.db-test
(:require [cljs.test :refer [deftest is]] (:require [cljs.test :refer [deftest is]]
[clojure.set :as set] [clojure.set :as set]
[logseq.publish-spa.db :as publish-db] [logseq.publishing.db :as publish-db]
[logseq.graph-parser :as graph-parser] [logseq.graph-parser :as graph-parser]
[datascript.core :as d] [datascript.core :as d]
[logseq.db :as ldb])) [logseq.db :as ldb]))

View File

@@ -1,7 +1,7 @@
(ns logseq.publish-spa.export-test (ns logseq.publishing.export-test
(:require [cljs.test :as t :refer [is use-fixtures async]] (:require [cljs.test :as t :refer [is use-fixtures async]]
[logseq.publish-spa.test.helper :as test-helper :include-macros true :refer [deftest-async]] [logseq.publishing.test.helper :as test-helper :include-macros true :refer [deftest-async]]
[logseq.publish-spa.export :as publish-export] [logseq.publishing.export :as publish-export]
[promesa.core :as p] [promesa.core :as p]
[clojure.set :as set] [clojure.set :as set]
["fs" :as fs] ["fs" :as fs]

View File

@@ -1,4 +1,4 @@
(ns logseq.publish-spa.test.helper) (ns logseq.publishing.test.helper)
;; Copied from https://github.com/babashka/nbb/blob/e5d84b0fac59774f5d7a4a9e807240cce04bf252/test/nbb/test_macros.clj ;; Copied from https://github.com/babashka/nbb/blob/e5d84b0fac59774f5d7a4a9e807240cce04bf252/test/nbb/test_macros.clj
(defmacro deftest-async (defmacro deftest-async

View File

@@ -257,10 +257,29 @@ We strive to use explicit names that are self explanatory so that our codebase i
### Babashka tasks ### Babashka tasks
There are a number of bb tasks under `dev:` for developers. There are also some There are a number of bb tasks under `dev:` for developers. Some useful ones to
tasks under `nbb:` which are useful for inspecting database changes in realtime. point out:
See [these docs](https://github.com/logseq/bb-tasks#logseqbb-tasksnbbwatch) for
more info. * `dev:validate-repo-config-edn` - Validate a repo config.edn
```sh
bb dev:validate-repo-config-edn templates/config.edn
```
* `dev:publishing` - Build a publishing app for a given graph dir. If the
publishing frontend is out of date, it builds that first which takes time.
Subsequent runs are quick.
```sh
# Build the export
$ bb dev:publishing /path/to/graph-dir tmp/publish
# View the app in a browser
$ open tmp/publish/index.html
```
There are also some tasks under `nbb:` which are useful for inspecting database
changes in realtime. See [these
docs](https://github.com/logseq/bb-tasks#logseqbb-tasksnbbwatch) for more info.
### Dev Commands ### Dev Commands

View File

@@ -3,5 +3,5 @@
{logseq/graph-parser {logseq/graph-parser
;; Nbb bug. Should just be "../graph-parser" ;; Nbb bug. Should just be "../graph-parser"
{:local/root "../../../../deps/graph-parser"} {:local/root "../../../../deps/graph-parser"}
logseq/publish-spa logseq/publishing
{:local/root "../../../../deps/publish-spa"}}} {:local/root "../../../../deps/publishing"}}}

View File

@@ -1,6 +1,7 @@
(ns logseq.tasks.dev.publishing (ns logseq.tasks.dev.publishing
"Basic script for publishing from CLI"
(:require [logseq.graph-parser.cli :as gp-cli] (:require [logseq.graph-parser.cli :as gp-cli]
[logseq.publish-spa :as publish-spa] [logseq.publishing :as publishing]
["fs" :as fs] ["fs" :as fs]
["path" :as node-path] ["path" :as node-path]
[clojure.edn :as edn])) [clojure.edn :as edn]))
@@ -18,8 +19,8 @@
;; Offset relative paths since they are run in a different directory than user is in ;; Offset relative paths since they are run in a different directory than user is in
(map #(if (node-path/isAbsolute %) % (node-path/resolve ".." %)) args) (map #(if (node-path/isAbsolute %) % (node-path/resolve ".." %)) args)
repo-config (-> (node-path/join graph-dir "logseq" "config.edn") fs/readFileSync str edn/read-string)] repo-config (-> (node-path/join graph-dir "logseq" "config.edn") fs/readFileSync str edn/read-string)]
(publish-spa/export (get-db graph-dir) (publishing/export (get-db graph-dir)
static-dir static-dir
graph-dir graph-dir
output-path output-path
{:repo-config repo-config}))) {:repo-config repo-config})))

View File

@@ -22,7 +22,7 @@
[electron.window :as win] [electron.window :as win]
[electron.exceptions :as exceptions] [electron.exceptions :as exceptions]
["/electron/utils" :as js-utils] ["/electron/utils" :as js-utils]
[logseq.publish-spa.export :as publish-export])) [logseq.publishing.export :as publish-export]))
;; Keep same as main/frontend.util.url ;; Keep same as main/frontend.util.url
(defonce LSP_SCHEME "logseq") (defonce LSP_SCHEME "logseq")

View File

@@ -4,7 +4,7 @@
[frontend.util :as util] [frontend.util :as util]
["/frontend/extensions/pdf/utils" :as js-utils] ["/frontend/extensions/pdf/utils" :as js-utils]
[datascript.core :as d] [datascript.core :as d]
[logseq.publish-spa.db :as publish-db] [logseq.publishing.db :as publish-db]
[clojure.string :as string])) [clojure.string :as string]))
(defonce MAX-SCALE 5.0) (defonce MAX-SCALE 5.0)

View File

@@ -15,7 +15,7 @@
[frontend.mobile.util :as mobile-util] [frontend.mobile.util :as mobile-util]
[frontend.modules.file.core :as outliner-file] [frontend.modules.file.core :as outliner-file]
[frontend.modules.outliner.tree :as outliner-tree] [frontend.modules.outliner.tree :as outliner-tree]
[logseq.publish-spa.html :as publish-html] [logseq.publishing.html :as publish-html]
[frontend.state :as state] [frontend.state :as state]
[frontend.util :as util] [frontend.util :as util]
[frontend.util.property :as property] [frontend.util.property :as property]