Skip to content

Commit

Permalink
allow figwheel system to take the result of (config/fetch-config)
Browse files Browse the repository at this point in the history
fixes #440
also allowed the figwheel-server to take a figwheel-internal-config as
well
updated the sidecar/README to reflect these changes
  • Loading branch information
Bruce Hauman committed Jul 8, 2016
1 parent 37547a4 commit 4a34663
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 35 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Then include `lein-figwheel` in the `:plugins`
section of your project.clj.

```clojure
[lein-figwheel "0.5.4-3"]
[lein-figwheel "0.5.4-5"]
```

#### Configure your builds
Expand Down Expand Up @@ -536,7 +536,7 @@ Figwheel has a Clojure
that makes it easy to start, stop and control Figwheel from Clojure.

In order for the following examples to work, you will need to have
`[figwheel-sidecar "0.5.4-3"]` in your dependencies.
`[figwheel-sidecar "0.5.4-5"]` in your dependencies.

To start Figwheel from a script, you will need to require the
`figwheel-sidecar.repl-api` and provide your build configuration to
Expand Down
58 changes: 29 additions & 29 deletions sidecar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,20 @@ file in the root directory of our project.
}
```

(You can also just add your configuration via the project.clj as usual)


We'll use leiningen for dependency and classpath management and our
`project.clj` should look like this:

```clojure
(defproject example "0.1.0-SNAPSHOT"
:description "Sidecar example"
:dependencies [[org.clojure/clojure "1.7.0"]
[org.clojure/clojurescript "1.7.145"]]
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/clojurescript "1.8.51"]]
:profiles {
:dev {
:dependencies [[figwheel-sidecar "0.5.0-SNAPSHOT"]]
:dependencies [[figwheel-sidecar "0.5.4-6"]]
}
}
)
Expand All @@ -56,22 +59,24 @@ nil
=> (require '[clojure.pprint :refer [pprint]])
nil
=> (pprint (sys/fetch-config))
{:figwheel-options
{:http-server-root "public",
:server-port 3449,
:open-file-command "emacsclient"},
:all-builds
[{:id "example",
:source-paths ["src"],
:figwheel {:build-id "example"},
:build-options
{:main example.core,
:asset-path "js/out",
:output-to "resources/public/js/example.js",
:output-dir "resources/public/js/out",
:source-map-timestamp true,
:optimizations :none}}],
:build-ids ["example"]}
{:data
{:figwheel-options
{:http-server-root "public",
:server-port 3449,
:open-file-command "emacsclient"},
:all-builds
[{:id "example",
:source-paths ["src"],
:figwheel {:build-id "example"},
:build-options
{:main example.core,
:asset-path "js/out",
:output-to "resources/public/js/example.js",
:output-dir "resources/public/js/out",
:source-map-timestamp true,
:optimizations :none}}],
:build-ids ["example"]},
:file "figwheel.edn"}
```

`fetch-config` fetches the config from the `figwheel.edn` file and
Expand All @@ -80,12 +85,7 @@ prepares it for consumption by figwheel components.
The call to `fetch-config` will attempt to get config first from
`figwheel.edn` and if there is no `figwheel.edn` available, it will
look for and read the `project.clj` file and attempt to get the
configuration info from the `:figwheel` and `:cljsbuild` entries. When
reading the `project.clj` directly **no leiningen profile merging will
occur**.

If you wish to load your configuration from a merged `project.clj` you
can load `leiningen.core` and read the configuration.
configuration info from the `:figwheel` and `:cljsbuild` entries.

One can store and load the configuration however one wants to.
`fetch-config` is merely a convenience.
Expand Down Expand Up @@ -165,7 +165,7 @@ java.util.concurrent.RejectedExecutionException:
## Adding the CSS Watcher component

The figwheel-system doesn't include css watching but we can add the
CSS watching as a seperate component.
CSS watching as a separate component.

and now let's define a system with a CSS Watcher:

Expand Down Expand Up @@ -228,7 +228,7 @@ repl doesn't offer us much.

## Creating a component that communicates with the Figwheel client

Let's make a simple component that preiodically sends the current
Let's make a simple component that periodically sends the current
server side time to the client. This has no practical value but will
just server as an example.

Expand Down Expand Up @@ -281,7 +281,7 @@ with the build id ("example" is build id from the config above).

Now let's listen for this message on the client. You will need to add
the following to your ClojureScript project source. You will probably
want to create a developement build that includes the source directory
want to create a development build that includes the source directory
that contains a source file as follows.

```clojure
Expand All @@ -292,7 +292,7 @@ that contains a source file as follows.
:time-pusher
(fn [{:keys [msg-name] :as msg}]
(when (= msg-name :time-push)
(println "Recieved time message:" (prn-str (:time msg))))))
(println "Received time message:" (prn-str (:time msg))))))
```

This will add a listener and whenever you receive a `:time-push`
Expand Down
8 changes: 6 additions & 2 deletions sidecar/src/figwheel_sidecar/components/figwheel_server.clj
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,12 @@
(when-let [default-handler (resolve 'figwheel-sidecar.components.cljs-autobuild/figwheel-build)]
@default-handler)))

(defn figwheel-server [{:keys [figwheel-options all-builds] :as options}]
(let [all-builds (map butils/add-compiler-env (config/prep-builds* all-builds))
(defn figwheel-server [config-data]
(let [{:keys [figwheel-options all-builds] :as options}
(if (config/figwheel-internal-config-data? config-data)
(:data config-data)
config-data)
all-builds (map butils/add-compiler-env (config/prep-builds* all-builds))
all-builds (ensure-array-map all-builds)

initial-state (create-initial-state figwheel-options)
Expand Down
8 changes: 6 additions & 2 deletions sidecar/src/figwheel_sidecar/system.clj
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,12 @@
(server/-connection-data (:figwheel-server @system)))
(-actual [this] (:figwheel-server @system)))

(defn figwheel-system [{:keys [build-ids] :as options}]
(let [system
(defn figwheel-system [config-data]
(let [{:keys [build-ids] :as options}
(if (config/figwheel-internal-config-data? config-data)
(:data config-data)
config-data)
system
(atom
(-> (component/system-map
:figwheel-server (server/figwheel-server options))
Expand Down

0 comments on commit 4a34663

Please sign in to comment.