@@ -25,26 +25,68 @@ export function makeTmpDir(name: string): MakeTmpDirReturn {
25
25
} ;
26
26
}
27
27
28
- export function npm (
29
- args : ReadonlyArray < string > ,
30
- options ?: SpawnOptions ,
31
- ) : string {
32
- return spawn ( 'npm' , args , options ) ;
28
+ interface NPMOptions extends SpawnOptions {
29
+ quiet ?: boolean ;
33
30
}
34
31
35
- export function git (
36
- args : ReadonlyArray < string > ,
37
- options ?: SpawnOptions ,
38
- ) : string {
39
- return spawn ( 'git' , args , options ) ;
32
+ export function npm ( options ?: NPMOptions ) {
33
+ const globalOptions = options ?. quiet === true ? [ '--quiet' ] : [ ] ;
34
+ return {
35
+ run ( ...args : ReadonlyArray < string > ) : void {
36
+ spawn ( 'npm' , [ ...globalOptions , 'run' , ...args ] , options ) ;
37
+ } ,
38
+ install ( ...args : ReadonlyArray < string > ) : void {
39
+ spawn ( 'npm' , [ ...globalOptions , 'install' , ...args ] , options ) ;
40
+ } ,
41
+ ci ( ...args : ReadonlyArray < string > ) : void {
42
+ spawn ( 'npm' , [ ...globalOptions , 'ci' , ...args ] , options ) ;
43
+ } ,
44
+ exec ( ...args : ReadonlyArray < string > ) : void {
45
+ spawn ( 'npm' , [ ...globalOptions , 'exec' , ...args ] , options ) ;
46
+ } ,
47
+ pack ( ...args : ReadonlyArray < string > ) : string {
48
+ return spawnOutput ( 'npm' , [ ...globalOptions , 'pack' , ...args ] , options ) ;
49
+ } ,
50
+ diff ( ...args : ReadonlyArray < string > ) : string {
51
+ return spawnOutput ( 'npm' , [ ...globalOptions , 'diff' , ...args ] , options ) ;
52
+ } ,
53
+ } ;
54
+ }
55
+
56
+ interface GITOptions extends SpawnOptions {
57
+ quiet ?: boolean ;
58
+ }
59
+
60
+ export function git ( options ?: GITOptions ) {
61
+ const cmdOptions = options ?. quiet === true ? [ '--quiet' ] : [ ] ;
62
+ return {
63
+ clone ( ...args : ReadonlyArray < string > ) : void {
64
+ spawn ( 'git' , [ 'clone' , ...cmdOptions , ...args ] , options ) ;
65
+ } ,
66
+ checkout ( ...args : ReadonlyArray < string > ) : void {
67
+ spawn ( 'git' , [ 'checkout' , ...cmdOptions , ...args ] , options ) ;
68
+ } ,
69
+ revParse ( ...args : ReadonlyArray < string > ) : string {
70
+ return spawnOutput ( 'git' , [ 'rev-parse' , ...cmdOptions , ...args ] , options ) ;
71
+ } ,
72
+ revList ( ...args : ReadonlyArray < string > ) : string {
73
+ return spawnOutput ( 'git' , [ 'rev-list' , ...cmdOptions , ...args ] , options ) ;
74
+ } ,
75
+ catFile ( ...args : ReadonlyArray < string > ) : string {
76
+ return spawnOutput ( 'git' , [ 'cat-file' , ...cmdOptions , ...args ] , options ) ;
77
+ } ,
78
+ log ( ...args : ReadonlyArray < string > ) : string {
79
+ return spawnOutput ( 'git' , [ 'log' , ...cmdOptions , ...args ] , options ) ;
80
+ } ,
81
+ } ;
40
82
}
41
83
42
84
interface SpawnOptions {
43
85
cwd ?: string ;
44
86
env ?: typeof process . env ;
45
87
}
46
88
47
- function spawn (
89
+ function spawnOutput (
48
90
command : string ,
49
91
args : ReadonlyArray < string > ,
50
92
options ?: SpawnOptions ,
@@ -58,6 +100,14 @@ function spawn(
58
100
return result . stdout . toString ( ) . trimEnd ( ) ;
59
101
}
60
102
103
+ function spawn (
104
+ command : string ,
105
+ args : ReadonlyArray < string > ,
106
+ options ?: SpawnOptions ,
107
+ ) : void {
108
+ childProcess . spawnSync ( command , args , { stdio : 'inherit' , ...options } ) ;
109
+ }
110
+
61
111
export function readdirRecursive (
62
112
dirPath : string ,
63
113
opts : { ignoreDir ?: RegExp } = { } ,
0 commit comments