|
1 | 1 | import * as child_process from "node:child_process"; |
2 | 2 | import * as fs from "node:fs/promises"; |
3 | 3 | import * as path from "node:path"; |
4 | | -import { bsc_exe, rescript_legacy_exe } from "#cli/bins"; |
| 4 | +import { bsc_exe, rescript_exe, rescript_legacy_exe } from "#cli/bins"; |
5 | 5 |
|
6 | 6 | /** |
7 | 7 | * @typedef {{ |
@@ -29,10 +29,13 @@ export const { |
29 | 29 | yarn, |
30 | 30 | mocha, |
31 | 31 | bsc, |
32 | | - rescript, |
33 | 32 | execBin, |
| 33 | + rescript, |
34 | 34 | execBuild, |
35 | 35 | execClean, |
| 36 | + rescriptLegacy, |
| 37 | + execBuildLegacy, |
| 38 | + execCleanLegacy, |
36 | 39 | } = setup(); |
37 | 40 |
|
38 | 41 | /** |
@@ -156,58 +159,98 @@ export function setup(cwd = process.cwd()) { |
156 | 159 | return exec("npx", ["mocha", ...args], options); |
157 | 160 | }, |
158 | 161 |
|
| 162 | + /** |
| 163 | + * `bsc` CLI |
| 164 | + * |
| 165 | + * @param {string[]} [args] |
| 166 | + * @param {ExecOptions} [options] |
| 167 | + * @return {Promise<ExecResult>} |
| 168 | + */ |
| 169 | + bsc(args = [], options = {}) { |
| 170 | + return exec(bsc_exe, args, options); |
| 171 | + }, |
| 172 | + |
159 | 173 | /** |
160 | 174 | * `rescript` CLI |
161 | 175 | * |
162 | 176 | * @param {( |
163 | 177 | * | "build" |
164 | 178 | * | "clean" |
165 | 179 | * | "format" |
166 | | - * | "dump" |
167 | 180 | * | (string & {}) |
168 | 181 | * )} command |
169 | 182 | * @param {string[]} [args] |
170 | 183 | * @param {ExecOptions} [options] |
171 | 184 | * @return {Promise<ExecResult>} |
172 | 185 | */ |
173 | 186 | rescript(command, args = [], options = {}) { |
174 | | - const cliPath = path.join( |
175 | | - import.meta.dirname, |
176 | | - "../cli/rescript-legacy.js", |
177 | | - ); |
| 187 | + const cliPath = path.join(import.meta.dirname, "../cli/rescript.js"); |
178 | 188 | return exec("node", [cliPath, command, ...args].filter(Boolean), options); |
179 | 189 | }, |
180 | 190 |
|
181 | 191 | /** |
182 | | - * `bsc` CLI |
| 192 | + * Execute ReScript `build` command directly |
183 | 193 | * |
184 | 194 | * @param {string[]} [args] |
185 | 195 | * @param {ExecOptions} [options] |
186 | 196 | * @return {Promise<ExecResult>} |
187 | 197 | */ |
188 | | - bsc(args = [], options = {}) { |
189 | | - return exec(bsc_exe, args, options); |
| 198 | + execBuild(args = [], options = {}) { |
| 199 | + return exec(rescript_exe, ["build", ...args], options); |
190 | 200 | }, |
191 | 201 |
|
192 | 202 | /** |
193 | | - * Execute ReScript `build` command directly |
| 203 | + * Execute ReScript `clean` command directly |
194 | 204 | * |
195 | 205 | * @param {string[]} [args] |
196 | 206 | * @param {ExecOptions} [options] |
197 | 207 | * @return {Promise<ExecResult>} |
198 | 208 | */ |
199 | | - execBuild(args = [], options = {}) { |
| 209 | + execClean(args = [], options = {}) { |
| 210 | + return exec(rescript_exe, ["clean", ...args], options); |
| 211 | + }, |
| 212 | + |
| 213 | + /** |
| 214 | + * `rescript` legacy CLI |
| 215 | + * |
| 216 | + * @param {( |
| 217 | + * | "build" |
| 218 | + * | "clean" |
| 219 | + * | "format" |
| 220 | + * | "dump" |
| 221 | + * | (string & {}) |
| 222 | + * )} command |
| 223 | + * @param {string[]} [args] |
| 224 | + * @param {ExecOptions} [options] |
| 225 | + * @return {Promise<ExecResult>} |
| 226 | + */ |
| 227 | + rescriptLegacy(command, args = [], options = {}) { |
| 228 | + const cliPath = path.join( |
| 229 | + import.meta.dirname, |
| 230 | + "../cli/rescript-legacy.js", |
| 231 | + ); |
| 232 | + return exec("node", [cliPath, command, ...args].filter(Boolean), options); |
| 233 | + }, |
| 234 | + |
| 235 | + /** |
| 236 | + * Execute ReScript legacy `build` command directly |
| 237 | + * |
| 238 | + * @param {string[]} [args] |
| 239 | + * @param {ExecOptions} [options] |
| 240 | + * @return {Promise<ExecResult>} |
| 241 | + */ |
| 242 | + execBuildLegacy(args = [], options = {}) { |
200 | 243 | return exec(rescript_legacy_exe, ["build", ...args], options); |
201 | 244 | }, |
202 | 245 |
|
203 | 246 | /** |
204 | | - * Execute ReScript `clean` command directly |
| 247 | + * Execute ReScript legacy `clean` command directly |
205 | 248 | * |
206 | 249 | * @param {string[]} [args] |
207 | 250 | * @param {ExecOptions} [options] |
208 | 251 | * @return {Promise<ExecResult>} |
209 | 252 | */ |
210 | | - execClean(args = [], options = {}) { |
| 253 | + execCleanLegacy(args = [], options = {}) { |
211 | 254 | return exec(rescript_legacy_exe, ["clean", ...args], options); |
212 | 255 | }, |
213 | 256 |
|
|
0 commit comments