Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I execute a post build hook in an ember-cli Brocfile.js?

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?

like image 612
Sukima Avatar asked Mar 03 '15 15:03

Sukima


1 Answers

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

like image 180
Novaugust Avatar answered Oct 24 '22 11:10

Novaugust