@@ -21,8 +21,17 @@ const signals = {
21
21
SIGTERM : 15 ,
22
22
} ;
23
23
24
- export const { exec, node, yarn, mocha, bsc, rescript, execBuild, execClean } =
25
- setup ( ) ;
24
+ export const {
25
+ shell,
26
+ node,
27
+ yarn,
28
+ mocha,
29
+ bsc,
30
+ rescript,
31
+ execBin,
32
+ execBuild,
33
+ execClean,
34
+ } = setup ( ) ;
26
35
27
36
/**
28
37
* @param {string } [cwd]
@@ -71,7 +80,11 @@ export function setup(cwd = process.cwd()) {
71
80
}
72
81
73
82
if ( throwOnFail && code !== 0 ) {
74
- reject ( { status : code , stdout, stderr } ) ;
83
+ reject (
84
+ new Error (
85
+ `Command ${ command } exited with non-zero status: ${ code } ` ,
86
+ ) ,
87
+ ) ;
75
88
} else {
76
89
resolve ( { status : code , stdout, stderr } ) ;
77
90
}
@@ -80,32 +93,44 @@ export function setup(cwd = process.cwd()) {
80
93
}
81
94
82
95
return {
83
- exec,
96
+ /**
97
+ * bash shell script
98
+ *
99
+ * @param {string } script
100
+ * @param {string[] } [args]
101
+ * @param {ExecOptions } [options]
102
+ * @return {Promise<ExecResult> }
103
+ */
104
+ shell ( script , args = [ ] , options = { } ) {
105
+ return exec ( "bash" , [ script , ...args ] , options ) ;
106
+ } ,
84
107
85
108
/**
86
- * `node` CLI
109
+ * Execute JavaScript on Node.js
87
110
*
111
+ * @param {string } script
88
112
* @param {string[] } [args]
89
113
* @param {ExecOptions } [options]
90
114
* @return {Promise<ExecResult> }
91
115
*/
92
- node ( args = [ ] , options = { } ) {
93
- return exec ( "node" , args , options ) ;
116
+ node ( script , args = [ ] , options = { } ) {
117
+ return exec ( "node" , [ script , ... args ] , options ) ;
94
118
} ,
95
119
96
120
/**
97
- * `yarn` CLI
121
+ * Execute Yarn command
98
122
*
123
+ * @param {string } command
99
124
* @param {string[] } [args]
100
125
* @param {ExecOptions } [options]
101
126
* @return {Promise<ExecResult> }
102
127
*/
103
- yarn ( args = [ ] , options = { } ) {
104
- return exec ( "yarn" , args , options ) ;
128
+ yarn ( command , args = [ ] , options = { } ) {
129
+ return exec ( "yarn" , [ ... command . split ( " " ) , ... args ] , options ) ;
105
130
} ,
106
131
107
132
/**
108
- * Mocha CLI
133
+ * Execute Mocha CLI
109
134
*
110
135
* @param {string[] } [args]
111
136
* @param {ExecOptions } [options]
@@ -168,5 +193,18 @@ export function setup(cwd = process.cwd()) {
168
193
execClean ( args = [ ] , options = { } ) {
169
194
return exec ( rescript_exe , [ "clean" , ...args ] , options ) ;
170
195
} ,
196
+
197
+ /**
198
+ * Execute any binary or wrapper.
199
+ * It should support Windows as well
200
+ *
201
+ * @param {string } bin
202
+ * @param {string[] } [args]
203
+ * @param {ExecOptions } [options]
204
+ * @return {Promise<ExecResult> }
205
+ */
206
+ execBin ( bin , args = [ ] , options = { } ) {
207
+ return exec ( bin , args , options ) ;
208
+ } ,
171
209
} ;
172
210
}
0 commit comments