@@ -12,7 +12,6 @@ var semver = require('semver');
1212var Errors = require ( '../errors' ) ;
1313var Constants = require ( '../Constants' ) ;
1414var JsonLoader = require ( '../JsonLoader' ) ;
15- var JsonWriter = require ( '../JsonWriter' ) ;
1615var PackageMeta = require ( '../PackageMeta' ) ;
1716var Plugin = require ( '../Plugin' ) ;
1817var Project = require ( '../Project' ) ;
@@ -46,7 +45,7 @@ module.exports = function (dependencies) {
4645 apiinstall : function ( pluginName , cwd ) {
4746 isInteractive = false ;
4847
49- if ( cwd ) process . chdir ( cwd ) ;
48+ Constants . setCwd ( cwd ) ;
5049
5150 project = new Project ( Constants . DefaultProjectManifestPath , Constants . DefaultProjectFrameworkPath ) ;
5251
@@ -57,7 +56,7 @@ module.exports = function (dependencies) {
5756 itinerary = { } ;
5857 plugins = [ ] ;
5958
60- return init ( [ pluginName ] )
59+ return init ( pluginName ? [ pluginName ] : [ ] )
6160 . then ( createPlugins )
6261 . then ( getInitialInfo )
6362 . then ( findCompatibleVersions )
@@ -273,33 +272,28 @@ module.exports = function (dependencies) {
273272 var compatibleWithUnmetConstraint = present . filter ( isCompatibleWithUnmetConstraint ) ;
274273
275274 if ( ! isInteractive ) {
276- var errors = [ ] ;
277275
278- if ( incompatibleWithOldConstraint . length > 0 ) {
279- errors . push ( { error :Errors . ERROR_INCOMPATIBLE_VALID_REQUEST , context :incompatibleWithOldConstraint . map ( getPackageName ) } ) ;
280- }
281- if ( incompatibleWithLatestConstraint . length > 0 ) {
282- errors . push ( { error :Errors . ERROR_INCOMPATIBLE_VALID_REQUEST , context :incompatibleWithLatestConstraint . map ( getPackageName ) } ) ;
283- }
284- if ( incompatibleWithBadConstraint . length > 0 ) {
285- errors . push ( { error :Errors . ERROR_INCOMPATIBLE_BAD_REQUEST , context :incompatibleWithBadConstraint . map ( getPackageName ) } ) ;
286- }
287- if ( incompatibleWithNoConstraint . length > 0 ) {
288- errors . push ( { error :Errors . ERROR_INCOMPATIBLE , context :incompatibleWithNoConstraint . map ( getPackageName ) } ) ;
289- }
290- if ( compatibleWithOldIncompatibleConstraint . length > 0 ) {
291- errors . push ( { error :Errors . ERROR_COMPATIBLE_INC_REQUEST , context :compatibleWithOldIncompatibleConstraint . map ( getPackageName ) } ) ;
292- }
293- if ( compatibleWithBadConstraint . length > 0 ) {
294- errors . push ( { error :Errors . ERROR_COMPATIBLE_BAD_REQUEST , context :compatibleWithBadConstraint . map ( getPackageName ) } ) ;
295- }
296- if ( compatibleWithUnmetConstraint . length > 0 ) {
297- errors . push ( { error :Errors . ERROR_COMPATIBLE_INC_REQUEST , context :compatibleWithUnmetConstraint . map ( getPackageName ) } ) ;
298- }
299-
300- if ( errors . length > 0 ) {
301- return Q . reject ( errors ) ;
302- }
276+ incompatibleWithOldConstraint . forEach ( function ( p ) {
277+ p . _error = Errors . ERROR_INCOMPATIBLE_VALID_REQUEST ;
278+ } ) ;
279+ incompatibleWithLatestConstraint . forEach ( function ( p ) {
280+ p . _error = Errors . ERROR_INCOMPATIBLE_VALID_REQUEST ;
281+ } ) ;
282+ incompatibleWithBadConstraint . forEach ( function ( p ) {
283+ p . _error = Errors . ERROR_INCOMPATIBLE_BAD_REQUEST ;
284+ } ) ;
285+ incompatibleWithNoConstraint . forEach ( function ( p ) {
286+ p . _error = Errors . ERROR_INCOMPATIBLE ;
287+ } ) ;
288+ compatibleWithOldIncompatibleConstraint . forEach ( function ( p ) {
289+ p . _error = Errors . ERROR_COMPATIBLE_INC_REQUEST ;
290+ } ) ;
291+ compatibleWithBadConstraint . forEach ( function ( p ) {
292+ p . _error = Errors . ERROR_COMPATIBLE_BAD_REQUEST ;
293+ } ) ;
294+ compatibleWithUnmetConstraint . forEach ( function ( p ) {
295+ p . _error = Errors . ERROR_COMPATIBLE_INC_REQUEST ;
296+ } ) ;
303297
304298 compatibleWithOldCompatibleConstraint . forEach ( function ( p ) {
305299 p . markRequestedForInstallation ( ) ;
@@ -556,25 +550,63 @@ module.exports = function (dependencies) {
556550 var successMsg ;
557551
558552 if ( ! isInteractive ) {
559- var report = {
560- success :{ } ,
561- errored :{ } ,
562- missing :[ ]
553+ var report = [ ] ;
554+
555+ if ( plugins . length == 1 ) {
556+ var p = plugins [ 0 ] ;
557+
558+ if ( installSucceeded . length == 1 ) {
559+ var bowerPath = path . join ( Constants . cwd , 'src' , p . _belongsTo , p . packageName , 'bower.json' ) ;
560+ return Q . resolve ( JsonLoader . readJSONSync ( bowerPath ) ) ;
561+ }
562+ if ( installSkipped . length == 1 ) {
563+ return Q . reject ( p . _error ) ;
564+ }
565+ if ( installErrored . length == 1 ) {
566+ var error = _ . clone ( Errors . ERROR_INSTALL_ERROR ) ;
567+
568+ if ( p . _installError ) error . msg = p . _installError ;
569+
570+ return Q . reject ( error ) ;
571+ }
572+ return Q . reject ( Errors . ERROR_NOT_FOUND ) ;
563573 }
564574
565575 installSucceeded . forEach ( function ( p ) {
566- var bowerPath = path . join ( 'src' , p . _belongsTo , p . packageName , 'bower.json' ) ;
567- report . success [ p . packageName ] = JsonLoader . readJSONSync ( bowerPath ) ;
576+ var bowerPath = path . join ( Constants . cwd , 'src' , p . _belongsTo , p . packageName , 'bower.json' ) ;
577+ report . push ( {
578+ name :p . packageName ,
579+ status :'fulfilled' ,
580+ pluginData :JsonLoader . readJSONSync ( bowerPath )
581+ } ) ;
582+ } ) ;
583+
584+ installSkipped . forEach ( function ( p ) {
585+ report . push ( {
586+ name :p . packageName ,
587+ status :'rejected' ,
588+ reason :p . _error
589+ } ) ;
568590 } ) ;
569591
570592 installErrored . forEach ( function ( p ) {
571- report . errored [ p . packageName ] = {
572- errorMessage : p . _installError ? p . _installError : 'unknown error'
573- } ;
593+ var error = _ . clone ( Errors . ERROR_INSTALL_ERROR ) ;
594+
595+ if ( p . _installError ) error . msg = p . _installError ;
596+
597+ report . push ( {
598+ name :p . packageName ,
599+ status :'rejected' ,
600+ reason :error
601+ } ) ;
574602 } ) ;
575603
576604 missing . forEach ( function ( p ) {
577- report . missing . push ( p . packageName ) ;
605+ report . push ( {
606+ name :p . packageName ,
607+ status :'rejected' ,
608+ reason :Errors . ERROR_NOT_FOUND
609+ } ) ;
578610 } ) ;
579611
580612 return Q . resolve ( report ) ;
@@ -809,7 +841,7 @@ module.exports = function (dependencies) {
809841 plugin . _belongsTo = pluginType . belongsTo ;
810842
811843 return install ( plugin , {
812- directory : path . join ( 'src' , pluginType . belongsTo ) ,
844+ directory : path . join ( Constants . cwd , 'src' , pluginType . belongsTo ) ,
813845 registry : Constants . getRegistry ( )
814846 } ) ;
815847 }
0 commit comments