6

I have a ember-cli project that builds to the dist/ directory. I've configured the app to handle assets in the dist/ directory and set the history to use a hash instead of pushState. This allows me to sym-link the index.html to the root. The reasoning is that pushing the project to gh-pages on GitHub requires a root index.html and ember apps require routing to be absolute not relative (AFAIK). GitHub however will not follow sym-links and require a copy of the output index.html. This works and now I have 2 build steps (ember build and cp dist/index.html ./index.html).

How do I tell my Brocfile.js to copy the outputted index.html file after it is done building?

A bit of back-history: I am developing an ember-cli addon. I'm hosting it on GitHub. I need to provide a demo site. gh-pages is the correct place to host the demo site. So I create an ember-cli app in the gh-pages branch. I could not set the output folder to ./ because the ember build will rm -rf the output directory destroying the source. So it has to be dist/. I couldn't use a <meta http-equiv="Refresh"... because Ember borked up the paths and crashes on start. So the solution I had was to sym-link/copy the index.html to a higher level and change ember's config to prepend the dist/ directory to assets and set the routing to hash instead of pushState.

I currently have a deply.sh script that does this but I wanted to know if there was a way using Broccoli for this?

Sukima
  • 9,965
  • 3
  • 46
  • 60

1 Answers1

12

We this for over at Ghost. Use ember-cli to generate an in-repo-addon for yourself, and then use your favorite library for copying the file (I already had fs-extra and am using it)

Create your addon with ember g in-repo-addon <addon-name>

in /lib/<addon-name>/index.js:

module.exports = {
    name: '<addon-name>',
    postBuild: function (results) {
        var fs = this.project.require('fs-extra');
        fs.copySync(results.directory + '/index.html', '../server/views/default.hbs');
    }
};

Example from Ghost

Ember-cli docs: developing addons and scaffolding in-repo addons

Novaugust
  • 318
  • 2
  • 8
  • Do you host your addon in a private npm repository or via guthub? Or is there a way to have an addon be included in an ember-cli app codebase? – Sukima Mar 14 '15 at 00:17
  • Looked at the code linked. You include it in the app repo. I'm going to edit the answer for others who might need more explanation like I did. Thank you BTW I would have never known you can write your own add-ons inside a project! My co-workers are going to hallelujah with this news. – Sukima Mar 14 '15 at 00:24
  • Hey Sukima, sorry for the late response - I don't frequent this site too often ;) You're right that `ember generate addon` is for making external addons; the command to build an in-reop addon is `ember g in-repo-addon` So for instance, to build my addon, I ran `ember g in-repo-addon asset-delivery` then edited the created index.js. No other work is necessary. – Novaugust Mar 19 '15 at 03:16
  • Oh wow, the `in-repo-addon` seemed like an undocumented feature as far as I could tell. It was buried deep in the docs. Great to know it's there! Thanks. – Sukima Mar 19 '15 at 14:01
  • I ran into the same issue, so I wrote an addon to copy files out after build: https://www.npmjs.com/package/ember-cli-post-build-copy – Tim Overly Jan 21 '16 at 02:13