-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathutils.ts
More file actions
39 lines (34 loc) · 1.19 KB
/
Copy pathutils.ts
File metadata and controls
39 lines (34 loc) · 1.19 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
30
31
32
33
34
35
36
37
38
39
import type { ESLint } from 'eslint';
import { glob } from 'glob';
import type { PluginArtifactOptions } from '@code-pushup/models';
import { executeProcess, readJsonFile } from '@code-pushup/utils';
import type { LinterOutput } from './types.js';
export async function loadArtifacts(
artifacts: PluginArtifactOptions,
): Promise<LinterOutput[]> {
if (artifacts.generateArtifactsCommand) {
const { command, args = [] } =
typeof artifacts.generateArtifactsCommand === 'string'
? { command: artifacts.generateArtifactsCommand }
: artifacts.generateArtifactsCommand;
await executeProcess({
command,
args,
ignoreExitCode: true,
});
}
const initialArtifactPaths = Array.isArray(artifacts.artifactsPaths)
? artifacts.artifactsPaths
: [artifacts.artifactsPaths];
const artifactPaths = await glob(initialArtifactPaths);
return await Promise.all(
artifactPaths.map(async artifactPath => {
// ESLint CLI outputs raw ESLint.LintResult[], but we need LinterOutput format
const results = await readJsonFile<ESLint.LintResult[]>(artifactPath);
return {
results,
ruleOptionsPerFile: {}, // TODO
};
}),
);
}