-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.es6
87 lines (75 loc) · 2.68 KB
/
index.es6
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
"use strict";
var angular = require("angular");
const flattenArray = (a, b) => a.concat(b);
var throwErrors = false;
export function shouldThrowErrors(should) {
throwErrors = should;
}
export function buildFlatModule(moduleName, childDir) {
const childModuleNames = [];
// for each file...
Object.keys(childDir)
.map(childFileName => (
{
childFileName,
childFileContents: (
(childDir[childFileName] || {}).default ?
childDir[childFileName].default :
childDir[childFileName]
)
}
))
// and extract their module names, so we can depend on them.
.forEach(childDirObject => {
const { childFileContents, childFileName } = childDirObject;
if (
typeof childFileContents !== "object" ||
typeof childFileContents.name !== "string"
) {
const message = `Cannot find angular module name in ${ childFileName }`;
if (shouldThrowErrors) {
throw new TypeError(message)
} else {
console.warn(message);
}
} else {
childModuleNames.push(childFileContents.name);
}
});
return angular.module(moduleName, childModuleNames);
}
export function buildModule(moduleName, childDirs) {
const childModuleNames = [];
// for each subdirectory...
Object.keys(childDirs)
.map(childDirName => childDirs[childDirName])
// pull out each file inside...
.map(childDir =>
Object.keys(childDir)
.map(childFileName => (
{
childFileName,
childFileContents: childDir[childFileName]
}
))
)
.reduce(flattenArray, [])
// and extract their module names, so we can depend on them.
.forEach(childDirObject => {
const { childFileContents, childFileName } = childDirObject;
if (
typeof childFileContents !== "object" ||
typeof childFileContents.name !== "string"
) {
const message = `Cannot find angular module name in ${ childFileName }`;
if (shouldThrowErrors) {
throw new TypeError(message)
} else {
console.warn(message);
}
} else {
childModuleNames.push(childFileContents.name);
}
});
return angular.module(moduleName, childModuleNames);
}