Clojurians
#lumo
<
2017-11-18
>

This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

dotemacs20:11:18

Hi, with you can read files under resources like:

(-> "config.edn"
      io/resource
      do-something-with-the-file)
What would be the equivalent to io/resource approach in Lumo, something that looks under project’s resources directory? I get that you can do , but for it to work you have to specify the full path to it. I’m looking for a way to read a file, relative to the project it’s being run from. Is there something like that? Thanks

hlolli20:11:13

@dotemacs http://lumo.io/slurp should not need full path. Im not at the computer but http://lumo.io/resource and http://lumo.io/slurp is what you want to use more than any fs require or macchiato/fs

hlolli20:11:47

Yes you need http://lumo.io/respurce before your slurp it for the relative path to work

borkdude20:11:36

, is that new? it’s not available in my version of lumo (1.8.0-beta)

anmonteiro20:11:00

it’s been there since 1.2

anmonteiro20:11:26

but I have never spoken about these, since they are internal helpers for now

anmonteiro20:11:36

use at your own risk

borkdude20:11:45

ok, I forgot a require, since it’s not loaded at startup obviously - sorry :slightly_smiling_face:

hlolli21:11:45

good thing about http://lumo.io/resources is that it takes bundles data into account. So if lumo ever supports bundled data, you wont need to change your code.

dotemacs21:11:49

Thanks for the pointers

dotemacs22:11:51

See this:

cljs.user=> (require '[ :refer [resource slurp]])
nil
cljs.user=> (slurp "resources/bar")
"this is bar"
cljs.user=> (slurp (resource "bar"))
should never happen!
	 (new)
	 Function.cljs.core.ex_info.cljs$core$IFn$_invoke$arity$3 (NO_SOURCE_FILE <embedded>:1923:72)
	 Function.cljs.core.ex_info.cljs$core$IFn$_invoke$arity$2 (NO_SOURCE_FILE <embedded>:1922:449)
	 lumo$io$slurp (evalmachine.<anonymous>:49:25)
	 (evalmachine.<anonymous>:1:15)
	 ContextifyScript.Script.runInThisContext (vm.cljs:44:33)
	 Object.runInThisContext (vm.cljs:116:38)
	 ()
	 (Object.lumo.repl.caching_node_eval)
	 (NO_SOURCE_FILE <embedded>:5720:273)

dotemacs22:11:11

Am I misunderstanding how resource should be used or … ?

hlolli22:11:09

What version are you running, I used resource just few days ago in this project http://://github.com/hlolli/lumo-quiz-game/blob/master/src/lumo_quiz_game/main.cljs questions-db symbol.

anmonteiro22:11:31

@dotemacs doesn’t really behave like Clojure’s

anmonteiro22:11:40

it looks for something in the classpath

anmonteiro22:11:51

but doesn’t add a resources folder to the classpath automatically

dominicm22:11:57

@anmonteiro isn't that exactly how clojure's behaves?

dominicm22:11:04

It's lein that adds resources folder to the classpath.

anmonteiro22:11:15

it doesn’t behave exactly like Lein

anmonteiro22:11:18

:slightly_smiling_face:

dotemacs22:11:11

@hlolli on 1.7.0

hlolli22:11:58

@dotemacs try 1.8.0-alpha

hlolli22:11:58

@anmonteiro the root folder is always on classpath? So useing io/resource with full path relative to the root folder should work?

dotemacs23:11:36

thanks for that

dotemacs23:11:26

The main reason I even started to ask about this is because I have a script that is invoked via: npm run foo, where foo is a task in package.json. So using io/resource would look for a relative path from where the npm run foo was invoked.

dotemacs23:11:05

But I figure that by adding resources dir to the class path explicitly, I’ll be able to pick up the script that I’m after

hlolli23:11:42

You wouldnt run lein repl from different folder than the root foler, then why would you run npm run from other dir than project root. Nodejs also wont find childrents node_modules directorires, only parents

hlolli23:11:32

But ok as scriot goot question, dont know what the variable process.cwd() returns from foreign dirs

hlolli23:11:13

Does (.pwd js/process) return the same value wherever you call this script? Dont know myself

hlolli23:11:05

Does (.cwd js/process) return the same value wherever you call this script? Dont know myself

hlolli23:11:34

Wtf edit on mobile phone causes replied :)

dotemacs23:11:40

I’m trying something out

dotemacs23:11:45

don’t worry

dotemacs23:11:04

this is one of many joys of being always connected

dotemacs23:11:28

(.cwd js/process) does return the correct pwd…

dotemacs23:11:14

but I desperately wanted this:

(-> "foo.edn"
    resource
    (js->clj :keywordize-keys true)
    :src
…
to work

dotemacs23:11:58

wait, the above will work, if you add the project’s resources to the class path