Fork me on GitHub
#boot
<
2017-10-27
>
qqq20:10:01

(let [fname (timestamped-mainjs-fname)]
     (comp 
      (gen-html :hiccup-var 'client.static.html/gen-index
                :js-fname (timestamped-mainjs-fname))
      (sift :move {#"main.js" fname})))
this piece of code here does not do what I think it does because timestamped-mainjs-fname is only called once

qqq20:10:07

gen-html is a custom task I wrote myself

qqq20:10:35

I need to call timestamped-mainjs-fname inside of ten-html (which I can easily do) I also need to "move sift inside gen-html|" -- that I don't know how to do

seancorfield20:10:29

@qqq Isn't the problem that you're calling timestamped-mainjs-fname twice in that code?

seancorfield20:10:56

So what you pass into gen-html is going to be different to what you pass into sift?

qqq21:10:52

@seancorfield: 1. that indeed is a bug, I was in the middle of refactoring. 2. I meant to write:

(let [fname (timestamped-mainjs-fname)]
     (comp 
      (gen-html :hiccup-var 'client.static.html/gen-index
                :js-fname fname)
      (sift :move {#"main.js" fname})))
the problem with the current code is that (mainjs-fname) is only called once across all recompiles ; something due to boot tasks being functions that returns functions causes these steps to be 'executed once, returhning functions, which are then chained together'

qqq21:10:14

in particular, across different compiles, sift is moving "main.js" to "main_timestamp.js" ... but the timestamp is fixed, at the moment when the entire 'boot chain' is created

qqq21:10:50

to fix this, I'm moving the (timestamped-mainjs-fname) call into gen-html ... but then, I somehow also need to 'move in the sift' -- which is non-trivial, as I can't just replace it with an io/copy since I'm dealing with filesets, and not the filesystem directly

seancorfield21:10:47

Ah, right. So what you probably want is a task that creates the timestamp'd file name and stores it so that all downstream tasks can access it.

seancorfield21:10:05

We use set-env! to add such things to the task environment:

(with-pass-thru [fs]
  (set-env! :my-project/js-filename (timestamped-mainjs-fname)))
as a separate task that you comp into any pipeline that needs it and then retrieve it from the environment in other tasks.

qqq22:10:23

@seancorfield: due to the simplicity of my case (spitting out index.html + remaing main.js), I found I could just use the boot.core/mv task is the gist of your solution: there's some builtin env (global map of kw -> value? ) gen-html sets a field in the map move task, later on, reads from the env

seancorfield22:10:14

Yup, Boot has an "environment" which is a mutable hash map that is accessible to all tasks.

seancorfield22:10:40

It's a good way for tasks to "communicate" environmental stuff -- which a timestamped output file name is a good example.