@@ -60,9 +60,20 @@ module.exports = function (grunt) {
60
60
child . stdin . end ( ) ;
61
61
}
62
62
63
- function runNpmInstall ( where , callback ) {
64
- grunt . log . writeln ( "running npm install --production in " + where ) ;
65
- exec ( 'npm install --production' , { cwd : './' + where } , function ( err , stdout , stderr ) {
63
+ function runNpmInstall ( where , productionMode , callback ) {
64
+ if ( typeof productionMode === "function" ) {
65
+ callback = productionMode ;
66
+ productionMode = true ;
67
+ }
68
+
69
+ var cmd = 'npm install' ;
70
+ if ( productionMode ) {
71
+ cmd += ' --production' ;
72
+ }
73
+
74
+ grunt . log . writeln ( "running " + cmd + " in " + where ) ;
75
+
76
+ exec ( cmd , { cwd : './' + where } , function ( err , stdout , stderr ) {
66
77
if ( err ) {
67
78
grunt . log . error ( stderr ) ;
68
79
return callback ( stderr ) ;
@@ -157,50 +168,63 @@ module.exports = function (grunt) {
157
168
} ) ;
158
169
} ) ;
159
170
160
- function npmInstallExtensions ( globs ) {
161
- var doneWithTask = this . async ( ) ;
162
- var globs = [
163
- "dist/www/+(extensibility|extensions|LiveDevelopment)/**/package.json"
164
- ] ;
165
- var result ;
166
- var doneWithGlob = _ . after ( globs . length , ( ) => {
167
- doneWithTask ( result ) ;
168
- } ) ;
169
- globs . forEach ( g => {
170
- glob ( g , function ( err , files ) {
171
- if ( err ) {
172
- grunt . log . error ( err ) ;
173
- result = false ;
174
- return doneWithGlob ( ) ;
175
- }
176
- files = files . filter ( function ( path ) {
177
- return path . indexOf ( "node_modules" ) === - 1 ;
178
- } ) ;
179
- var doneWithFile = _ . after ( files . length , doneWithGlob ) ;
180
- files . forEach ( function ( file ) {
181
- runNpmInstall ( path . dirname ( file ) , function ( err ) {
182
- if ( err ) {
183
- result = false ;
184
- }
185
- return doneWithFile ( ) ;
171
+ function npmInstallExtensions ( globs , filterOutNodeModules = true , runProduction = true ) {
172
+ return new Promise ( function ( resolve ) {
173
+ var result ;
174
+ var doneWithGlob = _ . after ( globs . length , ( ) => {
175
+ resolve ( result ) ;
176
+ } ) ;
177
+ globs . forEach ( g => {
178
+ glob ( g , function ( err , files ) {
179
+ if ( err ) {
180
+ grunt . log . error ( err ) ;
181
+ result = false ;
182
+ return doneWithGlob ( ) ;
183
+ }
184
+ if ( filterOutNodeModules ) {
185
+ files = files . filter ( function ( path ) {
186
+ return path . indexOf ( "node_modules" ) === - 1 ;
187
+ } ) ;
188
+ }
189
+ var doneWithFile = _ . after ( files . length , doneWithGlob ) ;
190
+ files . forEach ( function ( file ) {
191
+ runNpmInstall ( path . dirname ( file ) , runProduction , function ( err ) {
192
+ if ( err ) {
193
+ result = false ;
194
+ }
195
+ return doneWithFile ( ) ;
196
+ } ) ;
186
197
} ) ;
187
198
} ) ;
188
199
} ) ;
189
200
} ) ;
190
201
}
191
202
192
203
grunt . registerTask ( "npm-install-extensions-src" , "Install node_modules for default extensions which have package.json defined" , function ( ) {
193
- var globs = [
204
+ var doneWithTask = this . async ( ) ;
205
+ npmInstallExtensions ( [
194
206
"src/www/+(extensibility|extensions|LiveDevelopment)/**/package.json"
195
- ] ;
196
- return npmInstallExtensions . call ( this , globs ) ;
207
+ ] ) . then ( function ( result ) {
208
+ doneWithTask ( result ) ;
209
+ } ) ;
197
210
} ) ;
198
211
199
212
grunt . registerTask ( "npm-install-extensions-dist" , "Install node_modules for default extensions which have package.json defined" , function ( ) {
200
- var globs = [
201
- "dist/www/+(extensibility|extensions|LiveDevelopment)/**/package.json"
202
- ] ;
203
- return npmInstallExtensions . call ( this , globs ) ;
213
+ var doneWithTask = this . async ( ) ;
214
+ Promise . all ( [
215
+ npmInstallExtensions ( [
216
+ "dist/www/node_modules/codemirror/package.json" // make sure codemirror builds
217
+ ] , false , false ) ,
218
+ npmInstallExtensions ( [
219
+ "dist/www/+(extensibility|extensions|LiveDevelopment)/**/package.json"
220
+ ] )
221
+ ] ) . then ( function ( results ) {
222
+ var result = ! results . some ( x => x != null ) ;
223
+ doneWithTask ( result ) ;
224
+ } ) . catch ( function ( err ) {
225
+ grunt . log . error ( 'err ' + err ) ;
226
+ doneWithTask ( false ) ;
227
+ } ) ;
204
228
} ) ;
205
229
206
230
} ;
0 commit comments