@@ -7,8 +7,7 @@ var Buffer = require('buffer').Buffer;
7
7
var fs = require ( 'fs' ) ;
8
8
9
9
var path = require ( 'path' ) ;
10
-
11
- var getModuleInfo = require ( '../config/ngModuleData.js' ) ;
10
+ var findModule = require ( '../config/ngModuleData.js' ) ;
12
11
13
12
exports . humanizeCamelCase = function ( str ) {
14
13
switch ( str ) {
@@ -77,7 +76,7 @@ exports.readModuleDemos = function(moduleName, fileTasks) {
77
76
} else {
78
77
var fileType = path . extname ( file . path ) . substring ( 1 ) ;
79
78
if ( fileType == 'js' ) {
80
- demo . ngModule = demo . ngModule || getModuleInfo ( file . contents . toString ( ) ) ;
79
+ demo . ngModule = demo . ngModule || findModule . any ( file . contents . toString ( ) ) ;
81
80
}
82
81
demo [ fileType ] && demo [ fileType ] . push ( toDemoObject ( file ) ) ;
83
82
}
@@ -106,8 +105,8 @@ exports.pathsForModule = function(name) {
106
105
function lookupPath ( ) {
107
106
gulp . src ( 'src/{services,components,core}/**/*' )
108
107
. 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 ) {
111
110
var modulePath = file . path . split ( path . sep ) . slice ( 0 , - 1 ) . join ( path . sep ) ;
112
111
pathsForModules [ name ] = modulePath + '/**' ;
113
112
}
@@ -123,8 +122,8 @@ exports.filesForModule = function(name) {
123
122
} else {
124
123
return gulp . src ( 'src/{services,components,core}/**/*' )
125
124
. 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 ) ) {
128
127
var modulePath = file . path . split ( path . sep ) . slice ( 0 , - 1 ) . join ( path . sep ) ;
129
128
pathsForModules [ name ] = modulePath + '/**' ;
130
129
var self = this ;
@@ -165,29 +164,33 @@ exports.appendToFile = function(filePath) {
165
164
} ;
166
165
167
166
exports . buildNgMaterialDefinition = function ( ) {
168
- var buffer = [ ] ;
167
+ var srcBuffer = [ ] ;
169
168
var modulesSeen = [ ] ;
169
+ var count = 0 ;
170
170
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 ) ;
176
174
next ( ) ;
177
175
} , 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 + ');' ;
180
180
var angularFile = new gutil . File ( {
181
181
base : process . cwd ( ) ,
182
182
path : process . cwd ( ) + '/ngMaterial.js' ,
183
- contents : new Buffer ( angularFileContents )
183
+ contents : new Buffer ( ngMaterialModule )
184
184
} ) ;
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 ) {
188
190
self . push ( file ) ;
189
191
} ) ;
190
- buffer = [ ] ;
192
+
193
+ srcBuffer = [ ] ;
191
194
done ( ) ;
192
195
} ) ;
193
196
} ;
@@ -197,8 +200,8 @@ function moduleNameToClosureName(name) {
197
200
}
198
201
exports . addJsWrapper = function ( enforce ) {
199
202
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 ) {
202
205
file . contents = new Buffer ( [
203
206
! ! enforce ? '(function(){' : '(function( window, angular, undefined ){' ,
204
207
'"use strict";\n' ,
@@ -212,18 +215,18 @@ exports.addJsWrapper = function(enforce) {
212
215
} ;
213
216
exports . addClosurePrefixes = function ( ) {
214
217
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 ) + '\');' ;
220
223
} ) . join ( '\n' ) ;
221
224
222
225
file . contents = new Buffer ( [
223
226
'goog.provide(\'' + closureModuleName + '\');' ,
224
227
requires ,
225
228
file . contents . toString ( ) ,
226
- closureModuleName + ' = angular.module("' + moduleInfo . module + '");'
229
+ closureModuleName + ' = angular.module("' + module . name + '");'
227
230
] . join ( '\n' ) ) ;
228
231
}
229
232
this . push ( file ) ;
@@ -234,10 +237,10 @@ exports.addClosurePrefixes = function() {
234
237
exports . buildModuleBower = function ( name , version ) {
235
238
return through2 . obj ( function ( file , enc , next ) {
236
239
this . push ( file ) ;
237
- var moduleInfo = getModuleInfo ( file . contents ) ;
238
- if ( moduleInfo . module ) {
240
+ var module = findModule . any ( file . contents ) ;
241
+ if ( module ) {
239
242
var bowerDeps = { } ;
240
- ( moduleInfo . dependencies || [ ] ) . forEach ( function ( dep ) {
243
+ ( module . dependencies || [ ] ) . forEach ( function ( dep ) {
241
244
var convertedName = 'angular-material-' + dep . split ( '.' ) . pop ( ) ;
242
245
bowerDeps [ convertedName ] = version ;
243
246
} ) ;
0 commit comments