forked from snyk/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkspace-helper.ts
More file actions
27 lines (24 loc) · 897 Bytes
/
workspace-helper.ts
File metadata and controls
27 lines (24 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import * as path from 'path';
import { readFileSync } from 'fs';
const workspacePath = path.join(__dirname, 'workspaces');
/**
* Changes the current working directory to the specified subdirectory within the workspace path.
*
* @param {string} subdir - The subdirectory to navigate to (optional). If not provided, the workspace path itself will be used.
*
* @example
* chdirWorkspaces('project1'); // Changes the working directory to '${workspacePath}/project1'
*/
export function chdirWorkspaces(subdir = '') {
const dir = path.join(workspacePath, subdir);
process.chdir(dir);
}
export function getWorkspaceJSON(...paths: string[]): any {
const filePath = path.join(workspacePath, ...paths);
try {
const fileContents = readFileSync(filePath, 'utf8');
return JSON.parse(fileContents);
} catch (err) {
throw new Error('Could not read json file: ' + filePath);
}
}