Skip to content

Commit

Permalink
feat: Filter enums for only real pseudo ones
Browse files Browse the repository at this point in the history
  • Loading branch information
d3xter666 committed Apr 8, 2024
1 parent 66bd651 commit 9cfd3af
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 3 deletions.
78 changes: 77 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 27 additions & 2 deletions scripts/metadataProvider/createPseudoModulesInfo.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import {pipeline} from "node:stream/promises";
import {Extract} from "unzip-stream";
import MetadataProvider from "./MetadataProvider.js";
import {writeFile} from "node:fs/promises";
import {writeFile, readdir} from "node:fs/promises";
import {createRequire} from "module";
const require = createRequire(import.meta.url);

import type {UI5Enum, UI5EnumValue} from "@ui5-language-assistant/semantic-model-types";
import path from "node:path";

const RAW_API_JSON_FILES_FOLDER = "tmp/apiJson";

Expand All @@ -20,13 +23,35 @@ async function downloadAPIJsons(url: string) {
}
}

async function extractPseudoModuleNames() {
const apiJsonList = await readdir(RAW_API_JSON_FILES_FOLDER);

Check failure on line 28 in scripts/metadataProvider/createPseudoModulesInfo.ts

View workflow job for this annotation

GitHub Actions / General checks, tests and coverage reporting

Trailing spaces not allowed
return apiJsonList.flatMap((library) => {
const libApiJson = require(path.resolve(RAW_API_JSON_FILES_FOLDER, library));

Check failure on line 30 in scripts/metadataProvider/createPseudoModulesInfo.ts

View workflow job for this annotation

GitHub Actions / General checks, tests and coverage reporting

Unsafe assignment of an `any` value
return libApiJson.symbols;

Check failure on line 31 in scripts/metadataProvider/createPseudoModulesInfo.ts

View workflow job for this annotation

GitHub Actions / General checks, tests and coverage reporting

Unsafe return of an `any` typed value

Check failure on line 31 in scripts/metadataProvider/createPseudoModulesInfo.ts

View workflow job for this annotation

GitHub Actions / General checks, tests and coverage reporting

Unsafe member access .symbols on an `any` value
}).reduce((acc: Record<string, boolean>, symbol) => {
if (symbol.kind === "enum" && symbol.resource.endsWith("library.js")) {

Check failure on line 33 in scripts/metadataProvider/createPseudoModulesInfo.ts

View workflow job for this annotation

GitHub Actions / General checks, tests and coverage reporting

Unsafe member access .kind on an `any` value

Check failure on line 33 in scripts/metadataProvider/createPseudoModulesInfo.ts

View workflow job for this annotation

GitHub Actions / General checks, tests and coverage reporting

Unsafe call of an `any` typed value

Check failure on line 33 in scripts/metadataProvider/createPseudoModulesInfo.ts

View workflow job for this annotation

GitHub Actions / General checks, tests and coverage reporting

Unsafe member access .resource on an `any` value
acc[symbol.name] = true;

Check failure on line 34 in scripts/metadataProvider/createPseudoModulesInfo.ts

View workflow job for this annotation

GitHub Actions / General checks, tests and coverage reporting

Computed name [symbol.name] resolves to an any value

Check failure on line 34 in scripts/metadataProvider/createPseudoModulesInfo.ts

View workflow job for this annotation

GitHub Actions / General checks, tests and coverage reporting

Unsafe member access .name on an `any` value
}

return acc;
}, Object.create(null) as Record<string, boolean>);
}

async function transformFiles() {
const metadataProvider = new MetadataProvider();
await metadataProvider.init(RAW_API_JSON_FILES_FOLDER);
await metadataProvider.init(RAW_API_JSON_FILES_FOLDER, "1.120.12" /** TODO: Extract it from URL */);

const pseudoModuleNames = await extractPseudoModuleNames();

const {enums} = metadataProvider.getModel();

const groupedEnums = Object.keys(enums).reduce((acc: Record<string, UI5Enum[]>, enumKey: string) => {
// Filter only real pseudo modules i.e. defined within library.js files
if (!pseudoModuleNames[enumKey]) {
return acc;
}

const curEnum = enums[enumKey];

acc[curEnum.library] = acc[curEnum.library] ?? [];
Expand Down

0 comments on commit 9cfd3af

Please sign in to comment.