@@ -25,26 +25,68 @@ export function makeTmpDir(name: string): MakeTmpDirReturn {
2525 } ;
2626}
2727
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 ;
3330}
3431
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+ } ;
4082}
4183
4284interface SpawnOptions {
4385 cwd ?: string ;
4486 env ?: typeof process . env ;
4587}
4688
47- function spawn (
89+ function spawnOutput (
4890 command : string ,
4991 args : ReadonlyArray < string > ,
5092 options ?: SpawnOptions ,
@@ -58,6 +100,14 @@ function spawn(
58100 return result . stdout . toString ( ) . trimEnd ( ) ;
59101}
60102
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+
61111export function readdirRecursive (
62112 dirPath : string ,
63113 opts : { ignoreDir ?: RegExp } = { } ,
0 commit comments