This repository has been archived on 2018-10-12. You can view files and clone it, but cannot push or open issues or pull requests.
2016-01-25 09:19:28 -05:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const glob = require('glob');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Map Routes to route files
|
|
|
|
*
|
2016-02-18 21:50:45 -05:00
|
|
|
* @param {string} path - folder with Routes
|
2016-01-25 09:19:28 -05:00
|
|
|
* @return {Object} - Object mapping routes to their files
|
|
|
|
*/
|
|
|
|
module.exports = function routeLoader(path) {
|
|
|
|
|
2016-02-18 21:50:45 -05:00
|
|
|
const basePath = path.replace(/\\/g, '/');
|
2016-01-25 09:19:28 -05:00
|
|
|
|
|
|
|
let paths = glob.sync(`${path}/**/*.js`);
|
|
|
|
paths = paths.sort();
|
2016-02-18 21:50:45 -05:00
|
|
|
paths = paths.map((path) => path.replace('\\', '/'));
|
2016-01-25 09:19:28 -05:00
|
|
|
|
|
|
|
let routes = {};
|
|
|
|
|
|
|
|
paths.forEach((path) => {
|
|
|
|
let routePath = path.replace(basePath, '')
|
|
|
|
.replace('.js', '')
|
|
|
|
.replace('index', '');
|
|
|
|
|
|
|
|
routes[routePath] = path;
|
|
|
|
});
|
|
|
|
|
|
|
|
return routes;
|
|
|
|
};
|