3
3
4
4
var Promise = require ( 'ember-cli/lib/ext/promise' ) ;
5
5
var Task = require ( 'ember-cli/lib/models/task' ) ;
6
- var npm = require ( 'ember-cli/lib/ utilities/npm ') ;
6
+ var shellPromise = require ( '../ utilities/shell-promise ') ;
7
7
var existsSync = require ( 'exists-sync' ) ;
8
8
var chalk = require ( 'chalk' ) ;
9
9
var path = require ( 'path' ) ;
@@ -18,36 +18,30 @@ module.exports = Task.extend({
18
18
completionOKMessage : '' ,
19
19
completionErrorMessage : 'Error installing packages. Did you misspelt it?' ,
20
20
21
- init : function ( ) {
22
- this . npm = this . npm || require ( 'npm' ) ;
23
- } ,
24
21
run : function ( options ) {
25
22
this . packages = options . packages || [ ] ;
26
23
this . skipInjection = options . skipInjection || false ;
27
24
this . autoInjection = options . autoInjection || false ;
28
25
this . disableLogger ( ) ;
29
26
30
- this . ui . startProgress ( chalk . green ( 'Installing 3rd party package:' ,
27
+ this . ui . startProgress ( chalk . green ( 'Installing 3rd party package:' ,
31
28
this . packages . join ( ', ' ) ) , chalk . green ( '.' ) ) ;
32
29
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
+
44
38
if ( this . skipInjection ) {
45
39
return this . announceOKCompletion ( ) ;
46
40
}
47
41
48
42
if ( this . autoInjection ) {
49
43
var pkg = this . packages [ 0 ] ;
50
-
44
+
51
45
if ( existsSync ( path . resolve ( process . cwd ( ) , 'src' , 'app.ts' ) ) ) {
52
46
var entryPoint = path . resolve ( process . cwd ( ) , 'src' , 'app.ts' ) ;
53
47
var packageData = this . parseFile ( pkg ) ;
@@ -57,10 +51,10 @@ module.exports = Task.extend({
57
51
return this . announceOKCompletion ( ) ;
58
52
}
59
53
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 ( ) ;
64
58
} . bind ( this ) ) ;
65
59
} ,
66
60
@@ -83,12 +77,14 @@ module.exports = Task.extend({
83
77
'as authentic: ' + allPackages . toUninstall . join ( ', ' ) ;
84
78
this . ui . writeLine ( chalk . yellow ( msg ) ) ;
85
79
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 )
87
83
. then ( function ( ) {
88
84
return this . processPackages ( allPackages . toProcess )
89
- . then ( function ( resp ) {
90
- return resolve ( resp ) ;
91
- } ) ;
85
+ . then ( function ( resp ) {
86
+ return resolve ( resp ) ;
87
+ } ) ;
92
88
} . bind ( this ) ) ;
93
89
}
94
90
else {
@@ -133,7 +129,7 @@ module.exports = Task.extend({
133
129
return new Promise ( function ( resolve , reject ) {
134
130
var packageData ;
135
131
136
- var msg = 'Customize the injection of ' +
132
+ var msg = 'Customize the injection of ' +
137
133
chalk . yellow ( path . basename ( packageName ) ) + '? (Y/n)' ;
138
134
139
135
return this . ui . prompt ( {
@@ -226,7 +222,7 @@ module.exports = Task.extend({
226
222
type : 'input' ,
227
223
name : 'sel' ,
228
224
message : msg ,
229
- filter : function ( val ) { return val . trim ( ) ; } ,
225
+ filter : function ( val ) { return val . trim ( ) ; } ,
230
226
validate : function ( value ) {
231
227
return value > 0 && value <= packageData [ componentKey ] . length ? true : 'Enter a valid value' ;
232
228
}
@@ -260,8 +256,8 @@ module.exports = Task.extend({
260
256
packageName ,
261
257
packageData [ componentKey ] [ componentIndex ] ) ;
262
258
263
- this . injectItem ( componentKey . toLowerCase ( ) ,
264
- packageData [ componentKey ] [ componentIndex ] ,
259
+ this . injectItem ( componentKey . toLowerCase ( ) ,
260
+ packageData [ componentKey ] [ componentIndex ] ,
265
261
possibleFiles [ fileIndex ] ) ;
266
262
267
263
this . ui . writeLine ( chalk . green ( 'Successfully injected.' ) ) ;
@@ -336,8 +332,8 @@ module.exports = Task.extend({
336
332
337
333
if ( removeNextLine ) {
338
334
arr . splice ( index , 1 ) ;
339
- if ( / ; / . test ( line ) ) {
340
- removeNextLine = false ;
335
+ if ( / ; / . test ( line ) ) {
336
+ removeNextLine = false ;
341
337
}
342
338
}
343
339
} ) ;
@@ -348,12 +344,12 @@ module.exports = Task.extend({
348
344
function generateFlatImportLine ( arr , fromIndex ) {
349
345
var lineArr = [ ] ;
350
346
var lastIndex ;
351
-
347
+
352
348
arr . forEach ( function ( line , index ) {
353
349
if ( index >= fromIndex && ! lastIndex ) {
354
350
lineArr . push ( line ) ;
355
- if ( / ; / . test ( line ) ) {
356
- lastIndex = true ;
351
+ if ( / ; / . test ( line ) ) {
352
+ lastIndex = true ;
357
353
}
358
354
}
359
355
} ) ;
@@ -443,7 +439,7 @@ module.exports = Task.extend({
443
439
444
440
if ( / \) / . test ( line ) ) {
445
441
replace = line . match ( / \( ( .* ?) \) / ) [ 0 ] ;
446
- }
442
+ }
447
443
else {
448
444
replace = contentsArr . splice ( index , contentsArr . length - 1 ) . join ( '\n' ) . replace ( / \n / g, '' ) ;
449
445
replace = replace . match ( / \( ( .* ?) \) / ) [ 0 ] ;
@@ -495,7 +491,7 @@ module.exports = Task.extend({
495
491
match = match . replace ( / [ \[ \] ] / g, '' ) ;
496
492
match = match . split ( ',' ) ;
497
493
match . push ( name ) ;
498
- match = match . filter ( function ( n ) { return n !== '' ; } ) ;
494
+ match = match . filter ( function ( n ) { return n !== '' ; } ) ;
499
495
contentsArr [ index ] = contentsArr [ index ] . replace ( replace , '[' + match . join ( ',' ) + ']' ) ;
500
496
}
501
497
} . bind ( this ) ) ;
@@ -505,14 +501,14 @@ module.exports = Task.extend({
505
501
506
502
parseFile : function ( packageName ) {
507
503
var packagePath = path . join ( process . cwd ( ) , 'node_modules' , packageName , packageName + '.ts' ) ;
508
-
504
+
509
505
if ( ! existsSync ( packagePath ) ) {
510
506
return false ;
511
507
}
512
508
513
509
var contents = fs . readFileSync ( packagePath , 'utf8' ) ;
514
510
var data = { } ;
515
-
511
+
516
512
data . Component = [ ] ;
517
513
data . Directive = [ ] ;
518
514
data . Pipe = [ ] ;
0 commit comments