Last active
May 25, 2016 03:32
-
-
Save billpull/3bbac1e7bfec2ab7ec6a30a1a7cafbfa to your computer and use it in GitHub Desktop.
In Repo Addon Move & Remove Routes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*jshint node:true*/ | |
var stew = require('broccoli-stew'); | |
var Funnel = require('broccoli-funnel'); | |
var BroccoliMergeTrees = require('broccoli-merge-trees'); | |
var OPTIONAL_ROUTES = [ | |
'optional-1', | |
'optional-2' | |
]; | |
module.exports = { | |
name: 'process-optional-routes', | |
isDevelopingAddon: function() { | |
return true; | |
}, | |
included: function included(app) { | |
this._super.included.apply(this, arguments); | |
if (typeof app.import !== 'function' && app.app) { | |
app = app.app; | |
} | |
this.app = app; | |
}, | |
_removeRoute: function(tree, routeName) { | |
var routePattern = '*/routes/' + routeName + '.js'; | |
tree = stew.rm(tree, routePattern); | |
return tree; | |
}, | |
preprocessTree: function (type, tree) { | |
if (type === 'js') { | |
var routeFiles = OPTIONAL_ROUTES.map((route) => (`${route}.js`)); | |
var routesTree = new Funnel('app/routes', { | |
files: routeFiles, | |
destDir: 'dist/assets/optional', | |
allowEmtpy: true | |
}); | |
// var debugTree = stew.debug(routesTree, { name: 'routeFunnel' }); | |
return new BroccoliMergeTrees([tree, routesTree]); | |
} | |
return tree; | |
}, | |
postprocessTree: function (type, tree) { | |
if (this.app.env === 'test' || type !== 'js') { | |
return tree; | |
} | |
return OPTIONAL_ROUTES.reduce(this._removeRoute, tree); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment