Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reload garden-fn on file change #53

Closed
jacobobryant opened this issue Apr 4, 2021 · 4 comments
Closed

Reload garden-fn on file change #53

jacobobryant opened this issue Apr 4, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@jacobobryant
Copy link
Contributor

I've made the following quick hack to girouette.processor so that I don't have to restart the process when I change the definition of class-name->garden (which will probably be pretty often now given #35 (comment)). Would you be interested in a PR for this or something similar?

...

(defn- garden-fn-file? [^File file garden-fn-sym]
  (str/ends-with?
    (str/replace (.getPath file) #"\.clj(c|s)?" "")
    (str/replace (namespace garden-fn-sym) "." "/")))

...

  (let [garden-fn-sym garden-fn
        garden-fn (cond-> garden-fn

...

      (hawk/watch! [{:paths source-paths
                     :handler (fn [ctx {:keys [^File file kind]}]
                                (when (garden-fn-file? file garden-fn-sym)
                                  (require (symbol (namespace garden-fn-sym)) :reload)
                                  (swap! config assoc :garden-fn (requiring-resolve garden-fn-sym)))

...

I tried :reload-all instead of :reload, but it was giving me a weird error (java.lang.UnsupportedOperationException: Can't create empty: garden.selectors.CSSSelector), perhaps something to do with reloading girouette namespaces? :reload is fine for my purposes, but it could be a gotcha since it wouldn't load changes from any required namespaces; just garden-fn's namespace. tools.namespace's refresh might work.

@green-coder
Copy link
Owner

I've made the following quick hack to girouette.processor so that I don't have to restart the process when I change the definition of class-name->garden (which will probably be pretty often now given #35 (comment)). Would you be interested in a PR for this or something similar?

Yes, that type of PR would be awesome !

@green-coder green-coder added the enhancement New feature or request label Apr 4, 2021
@jacobobryant
Copy link
Contributor Author

Hey! I've ended up going a different direction with this actually: I replaced tailwind with girouette in biff, and I run girouette in the same jvm as the app. So I just eval things normally. (See https://github.com/jacobobryant/biff/blob/master/libs/tasks/resources/biff/template/dev/%7B%7Bparent-path%7D%7D/dev.clj#L28 and https://github.com/jacobobryant/biff/blob/master/libs/dev/src/biff/dev/girouette.clj if you're curious).

@green-coder
Copy link
Owner

@jacobobryant Should we close that issue?

@jacobobryant
Copy link
Contributor Author

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants