Fork me on GitHub

(let [fname (timestamped-mainjs-fname)]
      (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


gen-html is a custom task I wrote myself


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


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


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


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

(let [fname (timestamped-mainjs-fname)]
      (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'


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


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


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.


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.


@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


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


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