Skip to content

Commit 60afc25

Browse files
authored
Merge pull request #3 from mathworks-continuous-integration/jpereira/docstrings
Add docstrings
2 parents f447535 + ddb5006 commit 60afc25

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import * as matlab from "./matlab";
66

77
export { matlab };
88

9+
/**
10+
* Gather action inputs and then run action.
11+
*/
912
async function run() {
1013
const platform = process.platform;
1114
const workspaceDir = process.cwd();

src/matlab.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,27 @@ import * as path from "path";
66
import { v4 as uuid } from "uuid";
77
import * as script from "./script";
88

9+
/**
10+
* Helper interface to represent a MATLAB script.
11+
*/
912
export 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+
*/
1421
export 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+
*/
1630
export 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+
*/
2952
export 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+
*/
4169
export function getRmcPath(platform: string): string {
4270
const ext = platform === "win32" ? "bat" : "sh";
4371
const rmcPath = path.join(__dirname, "bin", `run_matlab_command.${ext}`);

src/script.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
11
// Copyright 2020 The MathWorks, Inc.
22

3+
/**
4+
* Generate MATLAB command for changing directories and calling a command in it.
5+
*
6+
* @param dir Directory to change to.
7+
* @param command Command to run in directory.
8+
* @returns MATLAB command.
9+
*/
310
export function cdAndCall(dir: string, command: string): string {
411
return `cd('${pathToCharVec(dir)}'); ${command}`;
512
}
613

14+
/**
15+
* Convert a path-like string to MATLAB character vector literal.
16+
*
17+
* @param s Input string.
18+
* @returns Input string in MATLAB character vector literal.
19+
*/
720
export function pathToCharVec(s: string): string {
821
return s.replace(/'/g, "''");
922
}
1023

24+
/**
25+
* Convert an identifier (i.e., a script name) to one that is callable by MATLAB.
26+
*
27+
* @param s Input identifier.
28+
*/
1129
export function safeName(s: string): string {
1230
return s.replace(/-/g, "_");
1331
}

0 commit comments

Comments
 (0)