@@ -7,8 +7,7 @@ var Buffer = require('buffer').Buffer;
77var fs = require ( 'fs' ) ;
88
99var path = require ( 'path' ) ;
10-
11- var getModuleInfo = require ( '../config/ngModuleData.js' ) ;
10+ var findModule = require ( '../config/ngModuleData.js' ) ;
1211
1312exports . humanizeCamelCase = function ( str ) {
1413 switch ( str ) {
@@ -77,7 +76,7 @@ exports.readModuleDemos = function(moduleName, fileTasks) {
7776 } else {
7877 var fileType = path . extname ( file . path ) . substring ( 1 ) ;
7978 if ( fileType == 'js' ) {
80- demo . ngModule = demo . ngModule || getModuleInfo ( file . contents . toString ( ) ) ;
79+ demo . ngModule = demo . ngModule || findModule . any ( file . contents . toString ( ) ) ;
8180 }
8281 demo [ fileType ] && demo [ fileType ] . push ( toDemoObject ( file ) ) ;
8382 }
@@ -106,8 +105,8 @@ exports.pathsForModule = function(name) {
106105 function lookupPath ( ) {
107106 gulp . src ( 'src/{services,components,core}/**/*' )
108107 . pipe ( through2 . obj ( function ( file , enc , next ) {
109- var modName = getModuleInfo ( file . contents ) . module ;
110- if ( modName == name ) {
108+ var module = findModule . any ( file . contents ) ;
109+ if ( module && module . name == name ) {
111110 var modulePath = file . path . split ( path . sep ) . slice ( 0 , - 1 ) . join ( path . sep ) ;
112111 pathsForModules [ name ] = modulePath + '/**' ;
113112 }
@@ -123,8 +122,8 @@ exports.filesForModule = function(name) {
123122 } else {
124123 return gulp . src ( 'src/{services,components,core}/**/*' )
125124 . pipe ( through2 . obj ( function ( file , enc , next ) {
126- var modName = getModuleInfo ( file . contents ) . module ;
127- if ( modName == name ) {
125+ var module = findModule . any ( file . contents ) ;
126+ if ( module && ( module . name == name ) ) {
128127 var modulePath = file . path . split ( path . sep ) . slice ( 0 , - 1 ) . join ( path . sep ) ;
129128 pathsForModules [ name ] = modulePath + '/**' ;
130129 var self = this ;
@@ -165,29 +164,33 @@ exports.appendToFile = function(filePath) {
165164} ;
166165
167166exports . buildNgMaterialDefinition = function ( ) {
168- var buffer = [ ] ;
167+ var srcBuffer = [ ] ;
169168 var modulesSeen = [ ] ;
169+ var count = 0 ;
170170 return through2 . obj ( function ( file , enc , next ) {
171- var moduleName ;
172- if ( moduleName = getModuleInfo ( file . contents , true ) . module ) {
173- modulesSeen . push ( moduleName ) ;
174- }
175- buffer . push ( file ) ;
171+ var module = findModule . material ( file . contents ) ;
172+ if ( module ) modulesSeen . push ( module . name ) ;
173+ srcBuffer . push ( file ) ;
176174 next ( ) ;
177175 } , function ( done ) {
178- var EXPLICIT_DEPS = [ 'ng' , 'ngAnimate' , 'ngAria' ] ;
179- var angularFileContents = "angular.module('ngMaterial', " + JSON . stringify ( EXPLICIT_DEPS . concat ( modulesSeen ) ) + ');' ;
176+ var self = this ;
177+ var requiredLibs = [ 'ng' , 'ngAnimate' , 'ngAria' ] ;
178+ var dependencies = JSON . stringify ( requiredLibs . concat ( modulesSeen ) ) ;
179+ var ngMaterialModule = "angular.module('ngMaterial', " + dependencies + ');' ;
180180 var angularFile = new gutil . File ( {
181181 base : process . cwd ( ) ,
182182 path : process . cwd ( ) + '/ngMaterial.js' ,
183- contents : new Buffer ( angularFileContents )
183+ contents : new Buffer ( ngMaterialModule )
184184 } ) ;
185- this . push ( angularFile ) ;
186- var self = this ;
187- buffer . forEach ( function ( file ) {
185+
186+ // Elevate ngMaterial module registration to first in queue
187+ self . push ( angularFile ) ;
188+
189+ srcBuffer . forEach ( function ( file ) {
188190 self . push ( file ) ;
189191 } ) ;
190- buffer = [ ] ;
192+
193+ srcBuffer = [ ] ;
191194 done ( ) ;
192195 } ) ;
193196} ;
@@ -197,8 +200,8 @@ function moduleNameToClosureName(name) {
197200}
198201exports . addJsWrapper = function ( enforce ) {
199202 return through2 . obj ( function ( file , enc , next ) {
200- var moduleInfo = getModuleInfo ( file . contents ) ;
201- if ( ! ! enforce || moduleInfo . module ) {
203+ var module = findModule . any ( file . contents ) ;
204+ if ( ! ! enforce || module ) {
202205 file . contents = new Buffer ( [
203206 ! ! enforce ? '(function(){' : '(function( window, angular, undefined ){' ,
204207 '"use strict";\n' ,
@@ -212,18 +215,18 @@ exports.addJsWrapper = function(enforce) {
212215} ;
213216exports . addClosurePrefixes = function ( ) {
214217 return through2 . obj ( function ( file , enc , next ) {
215- var moduleInfo = getModuleInfo ( file . contents ) ;
216- if ( moduleInfo . module ) {
217- var closureModuleName = moduleNameToClosureName ( moduleInfo . module ) ;
218- var requires = ( moduleInfo . dependencies || [ ] ) . sort ( ) . map ( function ( dep ) {
219- return dep . indexOf ( moduleInfo . module ) === 0 ? '' : 'goog.require(\'' + moduleNameToClosureName ( dep ) + '\');' ;
218+ var module = findModule . any ( file . contents ) ;
219+ if ( module ) {
220+ var closureModuleName = moduleNameToClosureName ( module . name ) ;
221+ var requires = ( module . dependencies || [ ] ) . sort ( ) . map ( function ( dep ) {
222+ return dep . indexOf ( module . name ) === 0 ? '' : 'goog.require(\'' + moduleNameToClosureName ( dep ) + '\');' ;
220223 } ) . join ( '\n' ) ;
221224
222225 file . contents = new Buffer ( [
223226 'goog.provide(\'' + closureModuleName + '\');' ,
224227 requires ,
225228 file . contents . toString ( ) ,
226- closureModuleName + ' = angular.module("' + moduleInfo . module + '");'
229+ closureModuleName + ' = angular.module("' + module . name + '");'
227230 ] . join ( '\n' ) ) ;
228231 }
229232 this . push ( file ) ;
@@ -234,10 +237,10 @@ exports.addClosurePrefixes = function() {
234237exports . buildModuleBower = function ( name , version ) {
235238 return through2 . obj ( function ( file , enc , next ) {
236239 this . push ( file ) ;
237- var moduleInfo = getModuleInfo ( file . contents ) ;
238- if ( moduleInfo . module ) {
240+ var module = findModule . any ( file . contents ) ;
241+ if ( module ) {
239242 var bowerDeps = { } ;
240- ( moduleInfo . dependencies || [ ] ) . forEach ( function ( dep ) {
243+ ( module . dependencies || [ ] ) . forEach ( function ( dep ) {
241244 var convertedName = 'angular-material-' + dep . split ( '.' ) . pop ( ) ;
242245 bowerDeps [ convertedName ] = version ;
243246 } ) ;
0 commit comments