yarn updated to 4.11, prep for refactoring

This commit is contained in:
Oleksandr 2025-11-11 10:26:00 +02:00
parent a5fcc7b5e9
commit 9b2ec20636
Signed by: Xanazf
GPG key ID: 821EEC32761AC17C
11 changed files with 21561 additions and 447 deletions

View file

View file

@ -3,34 +3,43 @@ import path from "node:path";
import type { VersionsData, ModuleData } from "./types";
async function readModulesData(basePath: string): Promise<ModuleData[]> {
async function readModulesData(
basePath: string
): Promise<ModuleData[]> {
const moduleDirs = await fs.readdir(basePath);
const modules = await Promise.all(moduleDirs.map(async moduleDir => {
const modulePath = path.join(basePath, moduleDir);
const modules = await Promise.all(
moduleDirs.map(async moduleDir => {
const modulePath = path.join(basePath, moduleDir);
const indexPromise = async () => {
const indexPath = path.join(modulePath, "index.json");
const indexContent = await fs.readFile(indexPath, "utf8");
return JSON.parse(indexContent);
};
const indexPromise = async () => {
const indexPath = path.join(modulePath, "index.json");
const indexContent = await fs.readFile(indexPath, "utf8");
return JSON.parse(indexContent);
};
const typeNames = (await fs.readdir(modulePath)).filter(name => name !== "index.json");
const typePromises = typeNames.map(async fileName => {
const typePath = path.join(modulePath, fileName);
const fileContent = await fs.readFile(typePath, "utf8");
return JSON.parse(fileContent);
});
const typeNames = (await fs.readdir(modulePath)).filter(
name => name !== "index.json"
);
const typePromises = typeNames.map(async fileName => {
const typePath = path.join(modulePath, fileName);
const fileContent = await fs.readFile(typePath, "utf8");
return JSON.parse(fileContent);
});
const [index, ...types] = await Promise.all([indexPromise(), ...typePromises]);
const [index, ...types] = await Promise.all([
indexPromise(),
...typePromises,
]);
return {
name: index.name,
description: index.description,
details: index.details,
types,
}
}));
return {
name: index.name,
description: index.description,
details: index.details,
types,
};
})
);
return modules;
}
@ -44,19 +53,31 @@ async function readVersionsData(): Promise<VersionsData> {
);
}
const resolvedPath = path.join(process.cwd(), versionsPath);
console.log(resolvedPath);
const content = await fs.readFile(versionsPath, "utf8");
const data = JSON.parse(content);
const versions = await Promise.all(data.versions.map(async (d: { name: string, changelog?: string, types: any }) => ({
name: d.name,
changelog: d.changelog ? await fs.readFile(d.changelog, "utf8") : undefined,
modules: await readModulesData(d.types),
})));
const versions = await Promise.all(
data.versions.map(
async (d: {
name: string;
changelog?: string;
types: any;
}) => ({
name: d.name,
changelog: d.changelog
? await fs.readFile(d.changelog, "utf8")
: undefined,
modules: await readModulesData(d.types),
})
)
);
return {
versions,
default: data.default,
}
};
}
let globalVersionsData: Promise<VersionsData>;
@ -71,5 +92,6 @@ export function getVersionsData(): Promise<VersionsData> {
export async function getModulesData(): Promise<ModuleData[]> {
const versions = await getVersionsData();
return versions.versions.find(v => v.name === versions.default)!.modules;
return versions.versions.find(v => v.name === versions.default)!
.modules;
}