forked from angular/material
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathngModuleData.js
47 lines (40 loc) · 1.35 KB
/
ngModuleData.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
/**
* The AngularJS Material module `ngMaterial` is generated by scanning all Material components
* for valid module definitions. @see gulp-utils.js ::buildNgMaterialDefinition()
*
* angular.module('ngMaterial', [
* "ng","ngAnimate","ngAria",
* "material.core","material.core.gestures","material.core.layout","material.core.theming.palette",
* ...
* ]);
*
*/
// Define patterns for AngularJS Module definitions
const MATERIAL_ONLY = /\.module\(['|"](material\.[a-zA-Z\-.]*)['|"]\s*,(\s*\[([^\]]*)])/;
const ANY = /\.module\(('[^']*'|"[^"]*")\s*,(?:\s*\[([^\]]+)])?/;
/**
* Find module definition s that match the module definition pattern
*/
function buildScanner(pattern) {
return function findPatternIn(content) {
let dependencies;
const match = pattern.exec(content || '');
const moduleName = match ? match[1].replace(/'/gi,'') : null;
const depsMatch = match && match[2] && match[2].trim();
if (depsMatch) {
dependencies = depsMatch.split(/\s*,\s*/).map(function(dep) {
dep = dep.trim().slice(1, -1); // remove quotes
return dep;
});
}
return match ? {
name : moduleName || '',
module : moduleName || '',
dependencies : dependencies || []
} : null;
};
}
module.exports = {
material : buildScanner(MATERIAL_ONLY),
any : buildScanner(ANY)
};