Skip to content

Commit f6c82ee

Browse files
committed
try updating plugins path again
1 parent 8da60f1 commit f6c82ee

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/matlab.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export async function generateScript(workspaceDir: string, command: string): Pro
3333
const temporaryDirectory = await fs.mkdtemp(path.join(os.tmpdir(), "run_matlab_command-"));
3434

3535
const scriptPath = path.join(temporaryDirectory, scriptName + ".m");
36-
await fs.writeFile(scriptPath, script.cdAndCall(command), {
36+
await fs.writeFile(scriptPath, script.prepare(command), {
3737
encoding: "utf8",
3838
});
3939

src/script.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
// Copyright 2020-2025 The MathWorks, Inc.
22

3+
import * as path from "path";
4+
35
/**
4-
* Generate MATLAB command for changing directories and calling a command in it.
6+
* Generate MATLAB command for changing directories, adding plugins to path and calling a command in it.
57
*
68
* @param dir Directory to change to.
79
* @param command Command to run in directory.
810
* @returns MATLAB command.
911
*/
10-
export function cdAndCall(command: string): string {
11-
return `cd(getenv('MW_ORIG_WORKING_FOLDER')); ${command}`;
12+
export function prepare(command: string): string {
13+
const pluginsPath = path.join(__dirname, "plugins").replaceAll("'","''");
14+
return `cd(getenv('MW_ORIG_WORKING_FOLDER')); ` +
15+
`addpath('` + pluginsPath + `'); `
16+
+ command;
1217
}
1318

1419
/**

src/script.unit.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
// Copyright 2020-2025 The MathWorks, Inc.
22

33
import * as script from "./script";
4+
import * as path from "path";
45

56
describe("call generation", () => {
67
it("ideally works", () => {
78
// I know what your thinking
89
const testCommand = "disp('hello world')";
9-
const expectedString = `cd(getenv('MW_ORIG_WORKING_FOLDER')); ${testCommand}`;
10+
const pluginsPath = path.join(__dirname, "plugins").replaceAll("'","''");
11+
const expectedString = `cd(getenv('MW_ORIG_WORKING_FOLDER')); addpath('` + pluginsPath + `'); ${testCommand}`;
1012

11-
expect(script.cdAndCall(testCommand)).toMatch(expectedString);
13+
expect(script.prepare(testCommand)).toMatch(expectedString);
1214
});
1315
});
1416

0 commit comments

Comments
 (0)