This repository has been archived by the owner on Feb 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (55 loc) · 1.75 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
var fs = require('fs');
var path = require('path');
function routesResolver(filePath) {
var file;
var ngModule;
var ngRoutes = [];
try {
file = require(filePath);
ngModule = file && file.default || {};
ngRoutes = ngModule.routes ||
file.routes ||
ngModule.ROUTER_CONFIG ||
file.ROUTER_CONFIG ||
ngModule.ROUTE_CONFIG ||
file.ROUTE_CONFIG ||
[];
} catch (e) {
console.warn('ResolveNgRoutes', filePath)
}
return ngRoutes;
}
function resolveNgRoute(srcPath, config, defaultFile, resolver) {
config = config || {};
resolver = resolver || routesResolver;
defaultFile = defaultFile || 'index.ts';
fs.readdirSync(srcPath)
.filter(function(file) {
var filePath = path.join(srcPath, file);
return fs.statSync(filePath).isDirectory() || file === defaultFile;
})
.map(function(file) {
var filePath = path.join(srcPath, file);
if (fs.statSync(filePath).isDirectory()) {
return resolveNgRoute(filePath, config, defaultFile, resolver);
}
resolver(filePath)
.filter(function(route) {
var filePath = route.component || route.loadChildren;
return typeof filePath === 'string';
})
.map(function(route) {
var filePath = route.component || route.loadChildren;
return filePath.split('#')[0]
})
.map(function(componentPath) {
// create context map
config[componentPath] = path.join(srcPath, componentPath);
});
// return filePath;
});
return config;
}
resolveNgRoute.default = resolveNgRoute
resolveNgRoute.resolveNgRoute = resolveNgRoute;
module.exports = resolveNgRoute;