-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathcreate-runner-files.ts
More file actions
29 lines (26 loc) · 1.06 KB
/
create-runner-files.ts
File metadata and controls
29 lines (26 loc) · 1.06 KB
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
28
29
import { writeFile } from 'node:fs/promises';
import path from 'node:path';
import type { RunnerFilesPaths } from '@code-pushup/models';
import { ensureDirectoryExists, pluginWorkDir } from './file-system.js';
import { getUniqueProcessThreadId } from './process-id.js';
/**
* Function to create timestamp nested plugin runner files for config and output.
*
* @param pluginSlug - slug of the plugin name used as folder names to group same plugin configs
* @param configJSON - config of the plugin runner as JSON.
*/
export async function createRunnerFiles(
pluginSlug: string,
configJSON: string,
): Promise<RunnerFilesPaths> {
const uniqueId = getUniqueProcessThreadId();
const runnerWorkDir = path.join(pluginWorkDir(pluginSlug), uniqueId);
const runnerConfigPath = path.join(runnerWorkDir, 'plugin-config.json');
const runnerOutputPath = path.join(runnerWorkDir, 'runner-output.json');
await ensureDirectoryExists(path.dirname(runnerOutputPath));
await writeFile(runnerConfigPath, configJSON);
return {
runnerConfigPath,
runnerOutputPath,
};
}