@@ -19,7 +19,6 @@ var packageJson = 'package.json';
19
19
var installTask ;
20
20
var installQueue = [ ] ;
21
21
22
- // downloads a file
23
22
function downloadFile ( inputUri , callback ) {
24
23
25
24
var uri = url . parse ( inputUri ) ;
@@ -44,7 +43,6 @@ function downloadFile (inputUri, callback) {
44
43
return deferred . resolve ( { 'statusCode' : res . statusCode , 'statusMessage' : res . statusMessage , 'contentType' : res . headers [ 'content-type' ] , 'data' : buffer } ) ;
45
44
}
46
45
47
- // If status is Moved Permanently or Found, redirect to new URL
48
46
if ( [ 301 , 302 ] . indexOf ( res . statusCode ) > - 1 ) {
49
47
return downloadFile ( res . headers . location )
50
48
. then ( function ( result ) { deferred . resolve ( result ) ; } )
@@ -62,7 +60,6 @@ function downloadFile (inputUri, callback) {
62
60
return deferred . promise . nodeify ( callback ) ;
63
61
}
64
62
65
- // returns package information (package.json) given a package name
66
63
function getPackageInformation ( packageName , parentPackagePath ) {
67
64
68
65
try {
@@ -94,7 +91,6 @@ function getPackageInformation (packageName, parentPackagePath) {
94
91
throw new Error ( 'Error retrieving information for module: \'' + ( packageName || 'main' ) + '\'.' ) ;
95
92
}
96
93
97
- // returns package information (package.json) given a file or directory
98
94
function getModuleInformation ( dir ) {
99
95
100
96
try {
@@ -124,7 +120,6 @@ function getModuleInformation (dir) {
124
120
throw new Error ( 'Error retrieving information for module: \'' + ( dir || 'main' ) + '\'.' ) ;
125
121
}
126
122
127
- // get package information from the npm registry
128
123
function getNpmPackageInfo ( packageName , callback ) {
129
124
var deferred = Q . defer ( ) ;
130
125
http . get ( 'http://registry.npmjs.org/' + packageName + '/latest' , function ( res ) {
@@ -155,7 +150,6 @@ function getNpmPackageInfo (packageName, callback) {
155
150
return deferred . promise . nodeify ( callback ) ;
156
151
}
157
152
158
- // get package information from a GitHub repository
159
153
function getGitHubPackageInformation ( repositoryUrl , callback ) {
160
154
161
155
var src = url . parse ( repositoryUrl ) ;
@@ -187,15 +181,13 @@ function getGitHubPackageInformation (repositoryUrl, callback) {
187
181
} ) ;
188
182
}
189
183
190
- // get the latest version for an npm package
191
184
function getNpmPackageLatestVersion ( packageName , callback ) {
192
185
return getNpmPackageInfo ( packageName ) . then ( function ( packageJson ) {
193
186
return packageJson . version ;
194
187
} )
195
188
. nodeify ( callback ) ;
196
189
}
197
190
198
- // checks for updates to the application
199
191
function checkForUpdate ( callback ) {
200
192
201
193
var mainModule = getPackageInformation ( ) ;
@@ -206,12 +198,10 @@ function checkForUpdate (callback) {
206
198
. nodeify ( callback ) ;
207
199
}
208
200
209
- // installs an npm package
210
201
function installPackage ( packageName , source , callback ) {
211
202
212
203
log . info ( 'Installing new module: ' + packageName ) ;
213
204
214
- // npm command in Windows is a batch file and needs to include extension to be resolved by spawn call
215
205
var npm = ( process . platform === 'win32' ? 'npm.cmd' : 'npm' ) ;
216
206
var appRoot = path . dirname ( utils . getRootPackagePath ( ) ) ;
217
207
return exec ( npm , [ 'install' , source ] , { cwd : appRoot , statusMessage : 'Installing package ' } ) . then ( function ( ) {
@@ -240,7 +230,6 @@ function queuePackageInstallation (packageName, source, callback) {
240
230
return installTask . promise . nodeify ( callback ) ;
241
231
}
242
232
243
- // Triggers the installation of all queued npm packages.
244
233
function installQueuedPackages ( ) {
245
234
246
235
if ( installQueue . length === 0 ) {
@@ -251,25 +240,20 @@ function installQueuedPackages () {
251
240
252
241
log . info ( 'Installing the following module(s): \'' + moduleList + '\'...' ) ;
253
242
254
- // npm command in Windows is a batch file and needs to include extension to be resolved by spawn call
255
243
var npm = ( process . platform === 'win32' ? 'npm.cmd' : 'npm' ) ;
256
244
var appRoot = path . dirname ( utils . getRootPackagePath ( ) ) ;
257
245
258
- // build package list
259
246
var sources = installQueue . map ( function ( item ) {
260
247
return item . source ;
261
248
} ) ;
262
249
263
- // launch npm
264
250
return exec ( npm , [ 'install' ] . concat ( sources ) , { cwd : appRoot , statusMessage : 'Installing packages ' } ) . then ( function ( ) {
265
- // signal completion
266
251
installTask . resolve ( installQueue ) ;
267
252
} )
268
253
. catch ( function ( err ) {
269
254
return installTask . reject ( new CustomError ( 'Failed to install the following module(s): \'' + moduleList + '\'.' , err ) ) ;
270
255
} )
271
256
. finally ( function ( ) {
272
- // clear queue
273
257
installTask = undefined ;
274
258
installQueue = [ ] ;
275
259
} ) ;
0 commit comments