Search code examples
ember.jsember-clibroccolijs

move output file after ember build is complete


I'm using ember-cli 0.0.28 which depends BroccoliJS to build the distributable source for my front-end application. The problem I'm having is that whenever I (re)build I need the index.html file to be copied (or rather moved) to my back-end's template directory from which I serve the application.

I can't figure out how to configure the Brocfile.js in the ember-cli project directory to do this after the build is complete.

I've used a symlink for the time being, which works but would be a dead link until the front-end application is built with ember build. I think it's possible to use grunt-broccoli to run the build as a grunt task?! I don't know if this is the way forward though.

Using broccoli-file-mover is easy enough but it works with current trees, not future trees!

All help is appreciated.


Solution

  • ember-cli has progressed quite a bit but this question is still, fundamentally, valid and there are myriad of ways to address it.

    If the front-end build is to be bundled with the back-end assets, a symlink from the build/dist directory to the back-end's assets directory is adequate for most development phases.

    Now, ember-cli also allows proxying to the back-end via the ember server command which is useful if building an API backed app, sort of thing.

    ember-cli-deploy also appears as an excellent way to deploy front-end apps which can help with deploying to a development or production environment. It has many packs but I've reverted to using the redis pack as it provides an easy way to checkout font-end revision with a small back-end tweak, like this:

    defmodule PageController do
      def index(conn, %{"index_id" => sha}) do
        case _fetch_page_string(sha) do
          {:ok, output_string} -> html(conn, output_string)
          {:error, reason} -> conn |> send_resp(404, reason)
        end
      end
    
      defp _fetch_page_string(sha) do
        # some code to fetch page string (content)
        ... 
      end
    end
    

    In the above index page handler, attempt to catch an index_id queryParam, if present, we look for the corresponding page string that can be checked into e.g., a key/value store.