This repository has been archived by the owner on Jul 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
109 lines (93 loc) · 2.38 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
var through = require("through2"),
gutil = require("gulp-util"),
Graph = require("./lib/Graph"),
filters = require("./consts/angular-filters"),
PluginError = require("./lib/errors").PluginError;
module.exports = function (seeds, options, fullBuild) {
options = parseOptions(options, fullBuild);
var graph = new Graph(seeds, options);
return through.obj(function (file, enc, next) {
try {
graph.add(file);
next();
} catch (e) {
this.emit("error", e);
}
}, function (next) {
var stream = this;
try {
graph.build().forEach(function (node) {
stream.push(node.file);
});
next();
} catch (e) {
this.emit("error", e);
}
});
};
module.exports.watch = function (seeds, options, fullBuild) {
options = parseOptions(options, fullBuild);
var graph = new Graph(seeds, options);
out = {};
out.builder = function () {
return through.obj(function (file, enc, next) {
try {
graph.add(file);
next();
} catch (e) {
this.emit("error", e);
}
}, function (next) {
var stream = this;
try {
graph.build().forEach(function (node) {
stream.push(node.file.clone());
});
next();
} catch (e) {
this.emit("error", e);
}
});
};
out.update = function (file) {
switch (file.event) {
case "add":
case "change":
graph.add(file);
break;
case "unlink":
graph.remove(file);
break;
}
};
return out;
};
function parseOptions(options, fullBuild) {
if (!options.appModule) {
throw new PluginError("Missing options.appModule in configuration.");
}
options.parseExclude = parseOption(options.parseExclude);
options.requiredFiles = parseOption(options.requiredFiles);
options.requiredLibs = parseOption(options.requiredLibs);
options.filePriority = parseOption(options.filePriority);
options.optionalLibs = parseOption(options.optionalLibs);
options.optionalLibsInclude = parseOption(options.optionalLibsInclude);
options.globalDependencies = parseOption(options.globalDependencies);
options.globalModules = parseOption(options.globalModules);
options.verbose = options.verbose || false;
options.debug = options.debug || false;
filters.forEach(function (filter) {
options.globalDependencies.push("filter:" + filter);
});
options.fullBuild = !!fullBuild;
return options;
}
function parseOption(option) {
if (option instanceof Array) {
return option;
}
if (option == null) {
return [];
}
return [option];
}