This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-18
Channels
- # beginners (84)
- # boot (21)
- # cider (12)
- # cljs-dev (13)
- # cljsrn (3)
- # clojure (169)
- # clojure-dusseldorf (2)
- # clojure-gamedev (6)
- # clojure-germany (1)
- # clojure-russia (15)
- # clojure-serbia (4)
- # clojure-spec (16)
- # clojure-uk (4)
- # clojurescript (51)
- # core-async (1)
- # datomic (23)
- # emacs (16)
- # figwheel (1)
- # fulcro (60)
- # hoplon (8)
- # lein-figwheel (3)
- # leiningen (1)
- # luminus (4)
- # lumo (43)
- # off-topic (4)
- # re-frame (17)
- # rum (37)
- # shadow-cljs (21)
- # test-check (13)
- # vim (14)
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@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
Yes you need http://lumo.io/respurce before your slurp it for the relative path to work
yes it is
it’s been there since 1.2
but I have never spoken about these, since they are internal helpers for now
use at your own risk
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.
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)
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.
@dotemacs
doesn’t really behave like Clojure’s
it looks for something in the classpath
but doesn’t add a resources
folder to the classpath automatically
@anmonteiro isn't that exactly how clojure's behaves?
well then
it doesn’t behave exactly like Lein
@anmonteiro the root folder is always on classpath? So useing io/resource with full path relative to the root folder should work?
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.
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
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
But ok as scriot goot question, dont know what the variable process.cwd() returns from foreign dirs
Does (.pwd js/process) return the same value wherever you call this script? Dont know myself
Does (.cwd js/process) return the same value wherever you call this script? Dont know myself