lumo

:lumo: Standalone ClojureScript environment. Currently at version 1.9.0
dotemacs 2017-11-18T20:16:18.000132Z

Hi, with <http://clojure.java.io|clojure.java.io> you can read files under resources like:

(-&gt; "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 <http://lumo.io/slurp|lumo.io/slurp>, 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

2017-11-18T20:25:13.000086Z

@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

2017-11-18T20:26:47.000116Z

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

👌 1
borkdude 2017-11-18T20:31:36.000002Z

<http://lumo.io/slurp|lumo.io/slurp>, is that new? it’s not available in my version of lumo (1.8.0-beta)

anmonteiro 2017-11-18T20:31:56.000066Z

yes it is

anmonteiro 2017-11-18T20:32:00.000018Z

it’s been there since 1.2

anmonteiro 2017-11-18T20:32:26.000104Z

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

anmonteiro 2017-11-18T20:32:36.000019Z

use at your own risk

borkdude 2017-11-18T20:32:45.000106Z

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

2017-11-18T21:03:45.000060Z

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.

dotemacs 2017-11-18T21:05:49.000074Z

Thanks for the pointers

dotemacs 2017-11-18T21:05:53.000059Z

:)

dotemacs 2017-11-18T22:44:51.000018Z

See this:

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

dotemacs 2017-11-18T22:45:11.000042Z

Am I misunderstanding how resource should be used or … ?

2017-11-18T22:49:09.000053Z

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.

anmonteiro 2017-11-18T22:50:31.000095Z

@dotemacs <http://lumo.io/resource|lumo.io/resource> doesn’t really behave like Clojure’s

anmonteiro 2017-11-18T22:50:40.000055Z

it looks for something in the classpath

anmonteiro 2017-11-18T22:50:51.000046Z

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

dominicm 2017-11-18T22:50:57.000063Z

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

dominicm 2017-11-18T22:51:04.000049Z

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

anmonteiro 2017-11-18T22:51:10.000019Z

well then

anmonteiro 2017-11-18T22:51:15.000083Z

it doesn’t behave exactly like Lein

anmonteiro 2017-11-18T22:51:18.000028Z

🙂

dotemacs 2017-11-18T22:54:11.000028Z

@hlolli on 1.7.0

2017-11-18T22:57:58.000050Z

@dotemacs try 1.8.0-alpha

2017-11-18T22:59:58.000001Z

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

anmonteiro 2017-11-18T23:00:08.000038Z

yes

👍 1
dotemacs 2017-11-18T23:01:36.000006Z

thanks for that

dotemacs 2017-11-18T23:06:26.000082Z

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.

dotemacs 2017-11-18T23:07:05.000025Z

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

2017-11-18T23:09:42.000068Z

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

2017-11-18T23:11:32.000059Z

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

2017-11-18T23:14:13.000018Z

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

2017-11-18T23:15:05.000041Z

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

2017-11-18T23:15:34.000084Z

Wtf edit on mobile phone causes replied :)

dotemacs 2017-11-18T23:15:40.000009Z

I’m trying something out

dotemacs 2017-11-18T23:15:45.000017Z

don’t worry

dotemacs 2017-11-18T23:16:04.000096Z

this is one of many joys of being always connected

dotemacs 2017-11-18T23:44:28.000029Z

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

dotemacs 2017-11-18T23:45:14.000018Z

but I desperately wanted this:

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

dotemacs 2017-11-18T23:45:26.000064Z

no luck

dotemacs 2017-11-18T23:48:58.000025Z

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