@@ -6,13 +6,27 @@ import * as path from "path";
66import { v4 as uuid } from "uuid" ;
77import * as script from "./script" ;
88
9+ /**
10+ * Helper interface to represent a MATLAB script.
11+ */
912export interface HelperScript {
1013 dir : string ;
1114 command : string ;
1215}
1316
17+ /**
18+ * Type of a function that executes a command on a runner and returns the error
19+ * code.
20+ */
1421export type ExecFn = ( command : string , args ?: string [ ] ) => Promise < number > ;
1522
23+ /**
24+ * Generate a MATLAB script in the temporary directory that runs a command in
25+ * the workspace.
26+ *
27+ * @param workspaceDir CI job workspace directory
28+ * @param command MATLAB command to run
29+ */
1630export async function generateScript ( workspaceDir : string , command : string ) : Promise < HelperScript > {
1731 const scriptName = script . safeName ( `command_${ uuid ( ) } ` ) ;
1832
@@ -26,6 +40,15 @@ export async function generateScript(workspaceDir: string, command: string): Pro
2640 return { dir : temporaryDirectory , command : scriptName } ;
2741}
2842
43+ /**
44+ * Run a HelperScript in MATLAB.
45+ *
46+ * Create the HelperScript using `generateScript`.
47+ *
48+ * @param hs HelperScript pointing to the script containing the command
49+ * @param platform Operating system of the runner (e.g., "win32" or "linux")
50+ * @param fn ExecFn that will execute a command on the runner
51+ */
2952export async function runCommand ( hs : HelperScript , platform : string , fn : ExecFn ) : Promise < void > {
3053 const rmcPath = getRmcPath ( platform ) ;
3154 await fs . chmod ( rmcPath , 0o777 ) ;
@@ -38,6 +61,11 @@ export async function runCommand(hs: HelperScript, platform: string, fn: ExecFn)
3861 }
3962}
4063
64+ /**
65+ * Get the path of the script containing RunMATLABCommand for the host OS.
66+ *
67+ * @param platform Operating system of the runner (e.g., "win32" or "linux")
68+ */
4169export function getRmcPath ( platform : string ) : string {
4270 const ext = platform === "win32" ? "bat" : "sh" ;
4371 const rmcPath = path . join ( __dirname , "bin" , `run_matlab_command.${ ext } ` ) ;
0 commit comments