This repository has been archived by the owner on Sep 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(build): correct detection and generation ngMaterial module defini…
…tion Correct the dynamic generation of the `ngMaterial` module definition with dependencies on angular material components only. ```js angular.module('ngMaterial', ["ng","ngAnimate","ngAria","material.core","material.core.gestures","material.layout".... ]); ```
- Loading branch information
1 parent
e4ca61f
commit d85e14a
Showing
9 changed files
with
155 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,48 @@ | ||
// Regex adapted from https://github.com/ceymard/gulp-ngcompile | ||
|
||
module.exports = function processContent(fileContent, materialOnly) { | ||
var NG_MODULE_REGEX = materialOnly ? /\.module\(('material\.[^']*'|"material\.[^"]*")\s*,(?:\s*\[([^\]]+)\])?/g : /\.module\(('[^']*'|"[^"]*")\s*,(?:\s*\[([^\]]+)\])?/g; | ||
var match = NG_MODULE_REGEX.exec(fileContent || ''); | ||
var module = match && match[1] && match[1].slice(1, -1); //remove quotes | ||
var depsMatch = match && match[2] && match[2].trim(); | ||
|
||
var dependencies = []; | ||
if (depsMatch) { | ||
dependencies = depsMatch.split(/\s*,\s*/).map(function(dep) { | ||
dep = dep.slice(1, -1); //remove quotes | ||
return dep; | ||
}); | ||
/** | ||
* The Angular 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.layout","material.core.theming.palette", | ||
* ... | ||
* ]); | ||
* | ||
*/ | ||
|
||
// Define patterns for AngularJS Module definitions | ||
|
||
var MATERIAL_ONLY = /\.module\(['|"](material\.[a-zA-Z\-\.]*)['|"]\s*,(\s*\[([^\]]*)\])/; | ||
var ANY = /\.module\(('[^']*'|"[^"]*")\s*,(?:\s*\[([^\]]+)\])?/; | ||
|
||
/** | ||
* Find module definition s that match the module definition pattern | ||
*/ | ||
function buildScanner(pattern) { | ||
|
||
return function findPatternIn(content) { | ||
var dependencies; | ||
var match = pattern.exec(content || ''); | ||
var moduleName = match ? match[1].replace(/\'/gi,'') : null; | ||
var 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; | ||
} | ||
} | ||
|
||
return { | ||
module: module || '', | ||
dependencies: dependencies | ||
}; | ||
module.exports = { | ||
material : buildScanner( MATERIAL_ONLY ), | ||
any : buildScanner( ANY ) | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.