Fork me on GitHub
#shadow-cljs
<
2021-06-15
>
thheller06:06:12

@huxley and what was it?

ribelo06:06:26

I was working in a new file that was not yet required anywhere 😜

ribelo06:06:26

and date-fns-tz has not been used anywhere else

ribelo06:06:14

the main cause of problems usually sits in front of the monitor

thheller06:06:29

hmm well normally that shouldn't be a problem but I guess there is an issue with electron and eval then

thheller06:06:05

(assuming you just load-file or require the file it should be fine)

ribelo07:06:20

as I did a require in another ns which is used in the application and is compiled, then suddenly everything started to work everywhere and in every ns

thheller08:06:07

do you have any custom :js-options or so in your build config? anything electron related?

thheller08:06:33

normally this should just work (and did in your and my tests)

West13:06:09

Is it possible to call a node script from cljs? If so, how do I configure my shadow-cljs.edn so that I can call it?

thheller13:06:46

what do you mean by "call a node script from cljs"?

West13:06:45

Nevermind, I finally figured out the classpath business.

(ns app.data
  (:require [clojure.edn :as edn]
            [shadow.resource]
            ["/org_processor" :as org]
            ))

West13:06:20

deps.edn:

{:paths ["src" "scripts/js"]
...}

West13:06:56

But now I get a weird error.

[:app] Compiling ...
[:app] Build failure:
Closure compilation failed with 1 errors
--- org_processor.js:3
Parse error. '}' expected

thheller13:06:57

ah you mean using a JS file in your build. by "call a node script" I assuming you mean run node some-script.js or so 😛

thheller13:06:41

whats weird about that error? seems to be invalid js?

West13:06:47

yeah, I want to use a node script as it interacts with my local filesystem, and shadow.resource just doesn’t suit my needs.

West13:06:05

The error is weird because it’s output from a compiled cljs file.

West13:06:17

It should be valid

thheller13:06:19

you are not making much sense to me here

thheller13:06:49

its output from a compiled cljs file? what does that mean?

thheller13:06:14

please describe what you are trying to do, if possible with actual example

West13:06:38

I’m trying to use a library that turns org-mode documents into html.

West13:06:03

Here’s my script.

(ns scripts.org-processor
  (:require ["unified" :as unified]
            ["rehype-stringify" :as html]
            ["uniorg-parse" :as uniorg]
            ["uniorg-rehype" :as rehype]
            ["uniorg-extract-keywords" :refer (extractKeywords)]
            [cljs-node-io.core :as io :refer [slurp spit file-seq]]
            ))

(def processor
  (->
   (unified)
   (.use uniorg)
   (.use extractKeywords)
   (.use rehype)
   (.use html)))

#_(def org-string "
#+title: Lorem Ipsum
#+subtitle: stuff test
#+date: 2021-04-15
#+tags: test
#+author: Christian Westrom
#+id: test-1

* Here's some stuff
  * Here's more stuff
  - more stuff")

(defn process-org
  [org]
  (.processSync processor org))

(defn org->html
  [org-string]
  (.-contents (process-org org-string)))

(defn org->data
  [org-string]
  (js->clj (.-data (process-org org-string))
  :keywordize-keys true))

(defn blog-post
  [org-string]
  {:content (org->html org-string)
   :data (org->data org-string)})

(defn ^:export all-posts
  [path]
  (js/console.log (map #(blog-post (slurp %)) (rest (file-seq path)))))

West13:06:41

Now the function all-posts just outputs to the console for now, but I want to call it from my reagent site.

thheller13:06:27

ok then requiring the file is that what you want here

thheller13:06:44

I'd recommend to have that script output files to a certain location

thheller13:06:54

and either loading those files dynamically via ajax at runtime

thheller13:06:01

or including then via shadow.resource

thheller13:06:26

I do NOT recommend trying to run that script as part of the compilation. that'll just end up with unnecessary avoidable problems all over the place

West13:06:43

Looks like I need ajax then lol Because there’s no equivalent to file-seq in shadow-resource.

thheller13:06:08

well with a macro you could trivially write that yourself

thheller13:06:20

I wouldn't recommend doing that though so you'll have to figure that out yourself 😉

thheller13:06:39

I mean you have the script to generate the stuff right there

thheller13:06:59

so you could have that generate a single EDN or JSON file and just shadow.resource that

thheller13:06:32

but I would really recommend loading them dynamically

thheller13:06:46

unless you enjoy recompiling your entire code every time you make a change in the org mode files

West13:06:06

Ok cool, any good libraries for doing ajax in clojurescript?

thheller13:06:29

if you don't care about really old browser then just use js/fetch

West13:06:57

Thanks a bunch!