2023-06-19 00:09:21 +02:00
|
|
|
import { crawl } from "../../tools/crawl";
|
|
|
|
import { removeDuplicates } from "evt/tools/reducers/removeDuplicates";
|
|
|
|
import { join as pathJoin } from "path";
|
|
|
|
import * as fs from "fs";
|
2023-09-03 07:14:57 +02:00
|
|
|
import type { ThemeType } from "../../constants";
|
2023-06-19 00:09:21 +02:00
|
|
|
|
2023-06-21 18:06:12 +02:00
|
|
|
/** Assumes the theme type exists */
|
|
|
|
export function readFieldNameUsage(params: { keycloakifySrcDirPath: string; themeSrcDirPath: string; themeType: ThemeType }): string[] {
|
2023-06-19 00:09:21 +02:00
|
|
|
const { keycloakifySrcDirPath, themeSrcDirPath, themeType } = params;
|
|
|
|
|
|
|
|
const fieldNames: string[] = [];
|
|
|
|
|
2023-08-23 08:13:09 +02:00
|
|
|
for (const srcDirPath of [pathJoin(keycloakifySrcDirPath, themeType), pathJoin(themeSrcDirPath, themeType)]) {
|
2023-06-21 03:54:43 +02:00
|
|
|
const filePaths = crawl({ "dirPath": srcDirPath, "returnedPathsType": "absolute" }).filter(filePath => /\.(ts|tsx|js|jsx)$/.test(filePath));
|
2023-06-19 00:09:21 +02:00
|
|
|
|
|
|
|
for (const filePath of filePaths) {
|
|
|
|
const rawSourceFile = fs.readFileSync(filePath).toString("utf8");
|
|
|
|
|
2023-06-19 00:49:40 +02:00
|
|
|
if (!rawSourceFile.includes("messagesPerField")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-06-19 00:09:21 +02:00
|
|
|
fieldNames.push(
|
2023-06-19 02:00:02 +02:00
|
|
|
...Array.from(rawSourceFile.matchAll(/(?:(?:printIfExists)|(?:existsError)|(?:get)|(?:exists))\(\s*["']([^"']+)["']/g), m => m[1])
|
2023-06-19 00:09:21 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const out = fieldNames.reduce(...removeDuplicates<string>());
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|