33
44var Promise = require ( 'ember-cli/lib/ext/promise' ) ;
55var Task = require ( 'ember-cli/lib/models/task' ) ;
6- var npm = require ( 'ember-cli/lib/ utilities/npm ') ;
6+ var shellPromise = require ( '../ utilities/shell-promise ') ;
77var existsSync = require ( 'exists-sync' ) ;
88var chalk = require ( 'chalk' ) ;
99var path = require ( 'path' ) ;
@@ -18,36 +18,30 @@ module.exports = Task.extend({
1818 completionOKMessage : '' ,
1919 completionErrorMessage : 'Error installing packages. Did you misspelt it?' ,
2020
21- init : function ( ) {
22- this . npm = this . npm || require ( 'npm' ) ;
23- } ,
2421 run : function ( options ) {
2522 this . packages = options . packages || [ ] ;
2623 this . skipInjection = options . skipInjection || false ;
2724 this . autoInjection = options . autoInjection || false ;
2825 this . disableLogger ( ) ;
2926
30- this . ui . startProgress ( chalk . green ( 'Installing 3rd party package:' ,
27+ this . ui . startProgress ( chalk . green ( 'Installing 3rd party package:' ,
3128 this . packages . join ( ', ' ) ) , chalk . green ( '.' ) ) ;
3229
33- this . npmOptions = {
34- logLevel : 'error' ,
35- logstream : this . ui . outputStream ,
36- color : 'always' ,
37- optional : true ,
38- 'save-dev' : true ,
39- 'save-exact' : ! ! options [ 'save-exact' ]
40- } ;
41-
42- return npm ( 'install' , this . packages , this . npmOptions , this . npm )
43- . then ( function ( npmresp ) {
30+ this . npmOptions = ' --loglevel error --color always --optional --save-dev ' +
31+ '--save-exact ' + ! ! options [ 'save-exact' ] ;
32+
33+ var npmCommand = 'npm install ' + this . packages . join ( ' ' ) + this . npmOptions ;
34+
35+ return shellPromise ( npmCommand )
36+ . then ( function ( npmresp ) {
37+
4438 if ( this . skipInjection ) {
4539 return this . announceOKCompletion ( ) ;
4640 }
4741
4842 if ( this . autoInjection ) {
4943 var pkg = this . packages [ 0 ] ;
50-
44+
5145 if ( existsSync ( path . resolve ( process . cwd ( ) , 'src' , 'app.ts' ) ) ) {
5246 var entryPoint = path . resolve ( process . cwd ( ) , 'src' , 'app.ts' ) ;
5347 var packageData = this . parseFile ( pkg ) ;
@@ -57,10 +51,10 @@ module.exports = Task.extend({
5751 return this . announceOKCompletion ( ) ;
5852 }
5953
60- return this . installProcedure ( )
61- . then ( function ( resp ) {
62- return this . announceOKCompletion ( ) ;
63- } . bind ( this ) ) ;
54+ return this . installProcedure ( ) ;
55+ } . bind ( this ) )
56+ . then ( function ( resp ) {
57+ return this . announceOKCompletion ( ) ;
6458 } . bind ( this ) ) ;
6559 } ,
6660
@@ -83,12 +77,14 @@ module.exports = Task.extend({
8377 'as authentic: ' + allPackages . toUninstall . join ( ', ' ) ;
8478 this . ui . writeLine ( chalk . yellow ( msg ) ) ;
8579
86- return npm ( 'uninstall' , allPackages . toUninstall , this . npmOptions , this . npm )
80+ var npmCommand = 'npm uninstall ' + allPackages . toUninstall . join ( ' ' ) + this . npmOptions ;
81+
82+ return shellPromise ( npmCommand )
8783 . then ( function ( ) {
8884 return this . processPackages ( allPackages . toProcess )
89- . then ( function ( resp ) {
90- return resolve ( resp ) ;
91- } ) ;
85+ . then ( function ( resp ) {
86+ return resolve ( resp ) ;
87+ } ) ;
9288 } . bind ( this ) ) ;
9389 }
9490 else {
@@ -133,7 +129,7 @@ module.exports = Task.extend({
133129 return new Promise ( function ( resolve , reject ) {
134130 var packageData ;
135131
136- var msg = 'Customize the injection of ' +
132+ var msg = 'Customize the injection of ' +
137133 chalk . yellow ( path . basename ( packageName ) ) + '? (Y/n)' ;
138134
139135 return this . ui . prompt ( {
@@ -226,7 +222,7 @@ module.exports = Task.extend({
226222 type : 'input' ,
227223 name : 'sel' ,
228224 message : msg ,
229- filter : function ( val ) { return val . trim ( ) ; } ,
225+ filter : function ( val ) { return val . trim ( ) ; } ,
230226 validate : function ( value ) {
231227 return value > 0 && value <= packageData [ componentKey ] . length ? true : 'Enter a valid value' ;
232228 }
@@ -260,8 +256,8 @@ module.exports = Task.extend({
260256 packageName ,
261257 packageData [ componentKey ] [ componentIndex ] ) ;
262258
263- this . injectItem ( componentKey . toLowerCase ( ) ,
264- packageData [ componentKey ] [ componentIndex ] ,
259+ this . injectItem ( componentKey . toLowerCase ( ) ,
260+ packageData [ componentKey ] [ componentIndex ] ,
265261 possibleFiles [ fileIndex ] ) ;
266262
267263 this . ui . writeLine ( chalk . green ( 'Successfully injected.' ) ) ;
@@ -336,8 +332,8 @@ module.exports = Task.extend({
336332
337333 if ( removeNextLine ) {
338334 arr . splice ( index , 1 ) ;
339- if ( / ; / . test ( line ) ) {
340- removeNextLine = false ;
335+ if ( / ; / . test ( line ) ) {
336+ removeNextLine = false ;
341337 }
342338 }
343339 } ) ;
@@ -348,12 +344,12 @@ module.exports = Task.extend({
348344 function generateFlatImportLine ( arr , fromIndex ) {
349345 var lineArr = [ ] ;
350346 var lastIndex ;
351-
347+
352348 arr . forEach ( function ( line , index ) {
353349 if ( index >= fromIndex && ! lastIndex ) {
354350 lineArr . push ( line ) ;
355- if ( / ; / . test ( line ) ) {
356- lastIndex = true ;
351+ if ( / ; / . test ( line ) ) {
352+ lastIndex = true ;
357353 }
358354 }
359355 } ) ;
@@ -443,7 +439,7 @@ module.exports = Task.extend({
443439
444440 if ( / \) / . test ( line ) ) {
445441 replace = line . match ( / \( ( .* ?) \) / ) [ 0 ] ;
446- }
442+ }
447443 else {
448444 replace = contentsArr . splice ( index , contentsArr . length - 1 ) . join ( '\n' ) . replace ( / \n / g, '' ) ;
449445 replace = replace . match ( / \( ( .* ?) \) / ) [ 0 ] ;
@@ -495,7 +491,7 @@ module.exports = Task.extend({
495491 match = match . replace ( / [ \[ \] ] / g, '' ) ;
496492 match = match . split ( ',' ) ;
497493 match . push ( name ) ;
498- match = match . filter ( function ( n ) { return n !== '' ; } ) ;
494+ match = match . filter ( function ( n ) { return n !== '' ; } ) ;
499495 contentsArr [ index ] = contentsArr [ index ] . replace ( replace , '[' + match . join ( ',' ) + ']' ) ;
500496 }
501497 } . bind ( this ) ) ;
@@ -505,14 +501,14 @@ module.exports = Task.extend({
505501
506502 parseFile : function ( packageName ) {
507503 var packagePath = path . join ( process . cwd ( ) , 'node_modules' , packageName , packageName + '.ts' ) ;
508-
504+
509505 if ( ! existsSync ( packagePath ) ) {
510506 return false ;
511507 }
512508
513509 var contents = fs . readFileSync ( packagePath , 'utf8' ) ;
514510 var data = { } ;
515-
511+
516512 data . Component = [ ] ;
517513 data . Directive = [ ] ;
518514 data . Pipe = [ ] ;
0 commit comments