-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreprocessFiles.ts
59 lines (46 loc) · 1.9 KB
/
preprocessFiles.ts
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { Language } from "budgie";
import { ConversionStatus, IFailedConversionResult } from "../converters/converter";
import { ConvertersBag } from "../converters/convertersBag";
import { IFileSystem } from "../fileSystem";
import { ILogger } from "../logger";
import { printActionsSummary } from "../utils/printing";
import { preprocessFile } from "./preprocessFile";
export interface IPreprocessDependencies {
convertersBag: ConvertersBag;
fileSystem: IFileSystem;
filePaths: ReadonlySet<string>;
languages: ReadonlyArray<Language>;
logger: ILogger;
}
export interface IPreprocessResults {
budgieFilePaths: ReadonlySet<string>;
status: ConversionStatus;
}
const collectFilesToPreprocess = (filePaths: ReadonlySet<string>, languages: ReadonlyArray<Language>) =>
Array.from(filePaths).filter((filePath: string): boolean => {
for (const language of languages) {
if (filePath in language.projects.metadataFiles) {
return false;
}
}
return true;
});
export const preprocessFiles = async (dependencies: IPreprocessDependencies): Promise<IPreprocessResults> => {
dependencies.logger.log("Preprocessing...");
const budgieFilePaths = new Set<string>();
const failures: IFailedConversionResult[] = [];
for (const filePath of collectFilesToPreprocess(dependencies.filePaths, dependencies.languages)) {
const conversion = await preprocessFile(dependencies, filePath);
if (conversion.outputPath !== undefined) {
budgieFilePaths.add(conversion.outputPath);
}
if (conversion.status === ConversionStatus.Failed) {
failures.push(conversion);
}
}
printActionsSummary(dependencies.logger, "Preprocessing", failures);
return {
budgieFilePaths,
status: failures.length === 0 ? ConversionStatus.Succeeded : ConversionStatus.Failed,
};
};