Justin Dalrymple d9cd4c9a91 refactor: 💡 Migrated to a monorepo structure
Gitbeaker has been split up into 5 subpackages: gitbeaker-core, gitbeaker-node, gitbeaker-cli, gitbeaker-browser and gitbeaker-requester-utils.

gitbeaker-[node,cli,browser] are enviroment
specific sub packages. For example, if you want to use gitbeaker in a NodeJS environment, use gitbeaker-node. gitbeaker-core is where all the
base logic exists, and gitbeaker-requester-utils is a collection of utility functions for making custom requester libraries.

BREAKING CHANGE: 🧨 This migration requires users to import specific subpackages. For NodeJS
usage, that would be @gitbeaker/node.
2020-02-02 16:53:54 +01:00

62 lines
1.5 KiB
TypeScript

import getParamNames from 'get-param-names';
import { outputJsonSync } from 'fs-extra';
import * as Gitbeaker from '../src';
import { BaseService } from '../src/infrastructure';
function isGetter(x, name) {
return (Object.getOwnPropertyDescriptor(x, name) || {}).get;
}
function isFunction(x, name) {
return typeof x[name] === 'function';
}
function deepFunctions(x) {
return (
x &&
x !== Object.prototype &&
Object.getOwnPropertyNames(x)
.filter(name => isGetter(x, name) || isFunction(x, name))
.concat(deepFunctions(Object.getPrototypeOf(x)) || [])
);
}
function distinctDeepFunctions(x): string[] {
return Array.from(new Set(deepFunctions(x)));
}
function getInstanceMethods(x) {
return distinctDeepFunctions(x).filter(name => name !== 'constructor' && !~name.indexOf('__'));
}
function removeOptionalArg(list) {
if (['options', '_a'].includes(list[list.length - 1])) list.pop();
return list;
}
function buildMap() {
const map = {};
const baseArgs = Object.keys(getParamNames(BaseService)[0]);
for (const [name, service] of Object.entries(Gitbeaker as object)) {
if (name.includes('Bundle') || name === 'Gitlab') continue;
const s = new service({ requester: {} });
map[name] = [{ name: 'constructor', args: baseArgs }];
for (const m of getInstanceMethods(s) as string[]) {
map[name].push({
name: m,
args: removeOptionalArg(getParamNames(s[m])),
});
}
}
return map;
}
// Generate the services map
outputJsonSync('./dist/map.json', buildMap());