mirror of
https://github.com/jdalrymple/gitbeaker.git
synced 2026-01-18 15:55:30 +00:00
**gitbeaker** @typescript-eslint/eslint-plugin ^5.60.1 → ^5.61.0 @typescript-eslint/parser ^5.60.1 → ^5.61.0 eslint ^8.43.0 → ^8.44.0 jest ^29.5.0 → ^29.6.1 @swc/core ^1.3.66 → ^1.3.68 lerna ^7.1.0 → ^7.1.1 lint-staged ^13.2.2 → ^13.2.3 typescript ^5.1.3 → ^5.1.6 eslint-plugin-prettier ^4.2.1 → ^5.0.0-alpha.1 **@gitbeaker/cli** typescript ^5.1.3 → ^5.1.6 **@gitbeaker/core** @types/node ^20.3.1 → ^20.4.0 typescript ^5.1.3 → ^5.1.6 **@gitbeaker/requester-utils** @types/node ^20.3.1 → ^20.4.0 typescript ^5.1.3 → ^5.1.6 **@gitbeaker/rest** @types/node ^20.3.1 → ^20.4.0 typescript ^5.1.3 → ^5.1.6
52 lines
1.7 KiB
TypeScript
52 lines
1.7 KiB
TypeScript
import FS from 'node:fs';
|
|
import getParamNames from 'get-param-names';
|
|
import { BaseResource, RequesterType } from '@gitbeaker/requester-utils';
|
|
import * as resources from '../src/resources';
|
|
|
|
function getInstanceMethods(x: object): string[] {
|
|
if (!x) return [];
|
|
|
|
const proto = Reflect.getPrototypeOf(x);
|
|
|
|
if (!proto) return [];
|
|
|
|
const methods = new Set(Reflect.ownKeys(proto));
|
|
|
|
return Array.from(methods)
|
|
.filter((name) => name !== 'constructor')
|
|
.map((name) => name.toString());
|
|
}
|
|
|
|
function removeOptionalArg(list: (string | Record<string, unknown>)[] = []): string[] {
|
|
// Only the last item could be an object
|
|
if (list.length > 0) {
|
|
if (list.at(-1) === 'options') list.pop();
|
|
else if (list.at(-1)?.constructor === Object) list.pop();
|
|
}
|
|
|
|
return list as string[];
|
|
}
|
|
|
|
export function buildMap() {
|
|
const map: Record<string, { name: string; args: string[] }[]> = {};
|
|
const baseArgs = Object.keys(getParamNames(BaseResource)[0] as Record<string, unknown>);
|
|
const { Gitlab, ...directResources } = resources;
|
|
|
|
Object.entries(directResources).forEach(([name, Resource]) => {
|
|
const r = new Resource({ token: 'dummey', requesterFn: () => ({}) as RequesterType });
|
|
const formattedInstanceMethods = getInstanceMethods(r).map((m) => ({
|
|
name: m,
|
|
args: removeOptionalArg(getParamNames(r[m]) as (string | Record<string, unknown>)[]),
|
|
}));
|
|
|
|
map[name] = [{ name: 'constructor', args: baseArgs }].concat(formattedInstanceMethods);
|
|
});
|
|
|
|
return map;
|
|
}
|
|
|
|
// Generate the resources map
|
|
FS.rmSync('./dist/map.json', { recursive: true, force: true });
|
|
FS.mkdirSync('dist', { recursive: true });
|
|
FS.writeFileSync('./dist/map.json', JSON.stringify(buildMap(), null, 2));
|