1
1
const { spawn} = require ( 'child_process' ) ;
2
2
3
+ const initQuestions = [
4
+ { search : / ^ \? .+ / , response : "\n" } ,
5
+ ] ;
6
+
7
+ const initNoExtQuestions = [
8
+ { search : / ^ \? A d d b a s i c L o g i n a n d A d m i n .+ / , response : "No\n" } ,
9
+ { search : / ^ \? .+ / , response : "\n" } ,
10
+ ] ;
11
+
3
12
const commands = [
4
13
{ cmd : 'rm' , args : [ '-r' , 'test-project' ] , ignoreErrors : true } ,
5
- { cmd : './node_modules/.bin/vue' , args : [ 'init' , '.' , 'test-project' ] , yes : true } ,
14
+ { cmd : './node_modules/.bin/vue' , args : [ 'init' , '.' , 'test-project' ] , responses : initNoExtQuestions } ,
6
15
{ cmd : 'npm' , args : [ 'install' ] , cwd : 'test-project' } ,
7
16
{ cmd : 'npm' , args : [ 'run' , 'lint' ] , cwd : 'test-project' } ,
8
17
{ cmd : 'npm' , args : [ 'run' , 'test:server' ] , cwd : 'test-project' } ,
9
18
{ cmd : 'npm' , args : [ 'run' , 'test:client' ] , cwd : 'test-project' } ,
10
19
{ cmd : 'npm' , args : [ 'run' , 'build' ] , cwd : 'test-project' } ,
20
+ { cmd : 'rm' , args : [ '-r' , 'test-project' ] , ignoreErrors : true } ,
21
+ { cmd : './node_modules/.bin/vue' , args : [ 'init' , '.' , 'test-project' ] , responses : initNoExtQuestions } ,
22
+ { cmd : 'npm' , args : [ 'install' ] , cwd : 'test-project' } ,
23
+ { cmd : 'npm' , args : [ 'run' , 'lint' ] , cwd : 'test-project' } ,
24
+ { cmd : 'npm' , args : [ 'run' , 'test:server' ] , cwd : 'test-project' } ,
25
+ { cmd : 'npm' , args : [ 'run' , 'test:client' ] , cwd : 'test-project' } ,
26
+ { cmd : 'npm' , args : [ 'run' , 'build' ] , cwd : 'test-project' } ,
11
27
] ;
12
28
13
29
function executeCommand ( command , index ) {
14
30
return new Promise ( ( resolve , reject ) => {
15
31
let cp = spawn ( command . cmd , command . args , { cwd : command . cwd } ) ;
16
32
process . on ( 'exit' , cp . kill ) ;
17
-
18
33
cp . stdout . setEncoding ( 'utf-8' ) ;
19
34
cp . stdin . setEncoding ( 'utf-8' ) ;
35
+ cp . stderr . setEncoding ( 'utf-8' ) ;
20
36
21
37
// Ignore pipe errors
22
38
cp . stdin . on ( 'error' , ( ) => { } ) ;
@@ -26,18 +42,25 @@ function executeCommand(command, index) {
26
42
cp . stderr . pipe ( process . stderr ) ;
27
43
28
44
let rejected = false ;
29
- if ( command . yes ) {
30
- cp . stdout . on ( 'data' , function ( ) {
31
- if ( ! rejected ) cp . stdin . write ( "\n" ) ;
32
- } ) ;
33
- }
45
+ if ( ! rejected && command . responses ) {
46
+ const registerResponse = q => {
47
+ cp . stdout . on ( 'data' , output => {
48
+ if ( q . search . test ( output ) ) {
49
+ // console.log('sending', q);
50
+ cp . stdin . write ( q . response ) ;
51
+ }
52
+ } ) ;
53
+ }
54
+
55
+ command . responses . forEach ( registerResponse ) ;
56
+ }
34
57
cp . once ( 'error' , code => {
35
58
if ( ! rejected ) {
36
59
reject ( code ) ;
37
60
rejected = true ;
38
61
}
39
62
} ) ;
40
-
63
+
41
64
cp . once ( 'exit' , code => {
42
65
if ( code ) {
43
66
reject ( code ) ;
0 commit comments