1 | let GladString = require('../namespace/string');
|
2 | let path = require('path');
|
3 | let { decamelizeToArray } = new GladString();
|
4 | let base = process.cwd();
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | function fetch (file) {
|
17 |
|
18 | if (/\//.test(file)) {
|
19 | return require(path.join(base, file));
|
20 | }
|
21 |
|
22 | let filePath = decamelizeToArray(file).reverse();
|
23 |
|
24 | if (filePath[0] === 'model') {
|
25 | filePath[0] = 'models';
|
26 | } else if (filePath[0] === 'controller') {
|
27 | filePath[0] = 'controllers'
|
28 | } else if (filePath[0] === 'route') {
|
29 | filePath[0] = 'routes'
|
30 | }
|
31 | return require(path.join(base, filePath.join('/')));
|
32 | }
|
33 |
|
34 | function retrieve (files) {
|
35 | return files.map(file => fetch(file));
|
36 | }
|
37 |
|
38 | module.exports = function importer (...args) {
|
39 | if (args.length > 1) {
|
40 | return retrieve(args);
|
41 | } else {
|
42 | return fetch(args[0]);
|
43 | }
|
44 | }
|