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

Task for generating edn files #141

Closed
burn2delete opened this issue Nov 28, 2016 · 8 comments
Closed

Task for generating edn files #141

burn2delete opened this issue Nov 28, 2016 · 8 comments

Comments

@burn2delete
Copy link
Contributor

burn2delete commented Nov 28, 2016

I would be nice if there was such a task within the cljs package itself, here is my attempt:

(boot/deftask cljs-edn
  "Generate a .cljs.edn file."
  [e edn      VAL str   "EDN file name."
   i init-fn  VAL sym   "EDN init function."
   r require  VAL [sym] "Vector of namespaces to require."
   f init-fns VAL [sym] "Vector of fuctions to wrap in do block."
   t target   VAL kw    "Target platform."
   d closure-defines  VAL {} "A map of closure defines options."
   o compiler-options VAL {} "A map of compiler options."]
   (assert (:edn *opts*) "Must provide an edn file name.")
   (assert (:init-fn *opts*) "Must provide an init-fn.")
   (let [edn    (:edn *opts*)
         init   (:init-fn *opts*)
         main   (symbol (namespace init))
         ednstr {:require (:require *opts* [main])
                 :init-fns (:init-fns *opts* [init])
                 :compiler-options (:compiler-options *opts*
                                     {:target (:target *opts*)
                                      :closure-defines (:closure-defines *opts*)})}
         tmp    (boot/tmp-dir!)
         fname  (str edn ".cljs.edn")
         fedn   (io/file tmp fname)]
     (boot/with-pre-wrap fileset
       (util/info (str "Generating EDN file: " fname "\n"))
       (doto fedn (spit ednstr))
       (-> fileset (boot/add-resource tmp) boot/commit!))))
@martinklepsch
Copy link
Member

martinklepsch commented Nov 28, 2016 via email

@burn2delete
Copy link
Contributor Author

@martinklepsch init-fn is an easy option which will extract the ns and populate require for you, init-fns overrides that portion of the edn file. Essentially one version is automatic and the other is manual.

@martinklepsch
Copy link
Member

martinklepsch commented Nov 28, 2016 via email

@Deraen
Copy link
Contributor

Deraen commented Nov 28, 2016

Boot-cljs already adds require to any namespace in :init-fns so duplicating that logic here is unnecessary: https://github.com/adzerk-oss/boot-cljs/blob/master/src/adzerk/boot_cljs/middleware.clj#L68

@burn2delete
Copy link
Contributor Author

@Deraen @martinklepsch created PR #142

@mobileink
Copy link

what problem does this solve? why is parameterizing a task like this better than just writing the edn file?

@burn2delete
Copy link
Contributor Author

@mobileink there are lots of cases where I would like to generate an entry-point as part of a build. Usually for frameworks like express/feathers.js when generating server files or for cases where I am using boot for things other than building projects, like project management tasks which generate project files, etc.

@Deraen
Copy link
Contributor

Deraen commented Aug 4, 2017

This is no longer a goal. All the options can now be provided as task options with the latest release. Using Boot-cljs without .cljs.edn can still be problematic (and slow) as in this case all the .cljs files in fileset will be compiled, but I have some ideas on how to fix that eventually: #169

@Deraen Deraen closed this as completed Aug 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants