-
Notifications
You must be signed in to change notification settings - Fork 331
/
dynamic-imports.ts
49 lines (45 loc) · 1.46 KB
/
dynamic-imports.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
import { verifyTranslationImports } from "./services/I18NextService";
import { verifyDateFnsImports } from "@utils/app/setup-date-fns";
export class ImportReport {
error: Array<{ id: string; error: Error | string | undefined }> = [];
success: string[] = [];
}
export type ImportReportCollection = {
translation?: ImportReport;
"date-fns"?: ImportReport;
};
function collect(
verbose: boolean,
kind: keyof ImportReportCollection,
collection: ImportReportCollection,
report: ImportReport,
) {
collection[kind] = report;
if (verbose) {
for (const { id, error } of report.error) {
console.warn(`${kind} "${id}" failed: ${error}`);
}
const good = report.success.length;
const bad = report.error.length;
if (bad) {
console.error(`${bad} out of ${bad + good} ${kind} imports failed.`);
} else {
console.log(`${good} ${kind} imports verified.`);
}
}
}
// This verifies that the parameters used for parameterized imports are
// correct, that the respective chunks are reachable or bundled, and that the
// returned objects match expectations.
export async function verifyDynamicImports(
verbose: boolean,
): Promise<ImportReportCollection> {
const collection: ImportReportCollection = {};
await verifyTranslationImports().then(report =>
collect(verbose, "translation", collection, report),
);
await verifyDateFnsImports().then(report =>
collect(verbose, "date-fns", collection, report),
);
return collection;
}