-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
87 lines (74 loc) · 3.05 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
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 _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.shouldThrowErrors = shouldThrowErrors;
exports.buildFlatModule = buildFlatModule;
exports.buildModule = buildModule;
var angular = require("angular");
var flattenArray = function flattenArray(a, b) {
return a.concat(b);
};
var throwErrors = false;
function shouldThrowErrors(should) {
throwErrors = should;
}
function buildFlatModule(moduleName, childDir) {
var childModuleNames = [];
// for each file...
Object.keys(childDir).map(function (childFileName) {
return {
childFileName: childFileName,
childFileContents: (childDir[childFileName] || {}).default ? childDir[childFileName].default : childDir[childFileName]
};
})
// and extract their module names, so we can depend on them.
.forEach(function (childDirObject) {
var childFileContents = childDirObject.childFileContents;
var childFileName = childDirObject.childFileName;
if ((typeof childFileContents === "undefined" ? "undefined" : _typeof(childFileContents)) !== "object" || typeof childFileContents.name !== "string") {
var 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);
}
function buildModule(moduleName, childDirs) {
var childModuleNames = [];
// for each subdirectory...
Object.keys(childDirs).map(function (childDirName) {
return childDirs[childDirName];
})
// pull out each file inside...
.map(function (childDir) {
return Object.keys(childDir).map(function (childFileName) {
return {
childFileName: childFileName,
childFileContents: childDir[childFileName]
};
});
}).reduce(flattenArray, [])
// and extract their module names, so we can depend on them.
.forEach(function (childDirObject) {
var childFileContents = childDirObject.childFileContents;
var childFileName = childDirObject.childFileName;
if ((typeof childFileContents === "undefined" ? "undefined" : _typeof(childFileContents)) !== "object" || typeof childFileContents.name !== "string") {
var 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);
}