Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
feat: classDependsOn()
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Kloubert committed Feb 5, 2024
1 parent 848f972 commit bec7fe2
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log (@egomobile/documentation)

## 0.5.0

- add `classDependsOn()` function
- code cleanup and improvements

## 0.4.2

- add tools to add function dependencies
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@egomobile/documentation",
"version": "0.4.2",
"version": "0.5.0",
"description": "Tools for documenting (TypeScript) code.",
"main": "lib/index.js",
"engines": {
Expand Down
15 changes: 9 additions & 6 deletions src/decorators/DependsOn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import type { IDependencyInformation, IParameterDependencyItem, IPropertyDependencyItem, IMethodDependencyItem, IClassDependencyItem, DependencyInfoResolver, DependencyInfoCollectionArg } from "../types";
import type { IDependencyInformation, IParameterDependencyItem, IPropertyDependencyItem, IMethodDependencyItem, DependencyInfoResolver, DependencyInfoCollectionArg } from "../types";
import type { ClassPropKey, CreateDependsOnHelpersFunc, Nilable, Optional } from "../types/internal";

/**
Expand Down Expand Up @@ -169,12 +169,15 @@ export function DependsOn(
else if (args.length === 1) {
// class

const newClassItem: IClassDependencyItem = {
"constructor": target,
"type": "class"
};
const {
classDependsOn
} = require("../functions/dependsOn");

addItem(newClassItem);
classDependsOn(
target,
infoOrResolver,
dependenciesOrResolver
);
}
}
else {
Expand Down
77 changes: 75 additions & 2 deletions src/functions/dependsOn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,85 @@
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import type { DependencyInfoCollectionArg, DependencyInfoResolver, IDependencyInformation, IFunctionDependencyItem } from "../types";
import type { CreateDependsOnHelpersFunc, Func, Nilable } from "../types/internal";
import type { DependencyInfoCollectionArg, DependencyInfoResolver, IClassDependencyItem, IDependencyInformation, IFunctionDependencyItem } from "../types";
import type { Constructor, CreateDependsOnHelpersFunc, Func, Nilable } from "../types/internal";

/**
* Adds dependency information for a class.
*
* @example
* ```
* import {
* classDependsOn,
* getDependencies
* } from "@egomobile/documentation"
*
* class MyClass {
* // ...
* }
*
* classDependsOn(
* MyClass
* {
* // your information here...
* }
* )
*
* console.log(
* getDependencies()
* )
* ```
*
* @param {Constructor<any>} classConstructor The class constructor.
* @param {IDependencyInformation|DependencyInfoResolver} infoOrResolver The dependency information or the function that resolves it.
* @param {Nilable<DependenciesArg>} [dependenciesOrResolver] The custom collection for the dependency info items or the function that resolves it.
*/
export function classDependsOn(
classConstructor: Constructor<any>,
infoOrResolver: IDependencyInformation | DependencyInfoResolver,
dependenciesOrResolver?: Nilable<DependencyInfoCollectionArg>
) {
const createDependsOnHelpers: CreateDependsOnHelpersFunc =
require("../utils/internal").createDependsOnHelpers;

const {
addItem
} = createDependsOnHelpers(infoOrResolver, dependenciesOrResolver);

const newClassItem: IClassDependencyItem = {
"constructor": classConstructor,
"type": "class"
};

addItem(newClassItem);
}

/**
* Adds dependency information for a function.
*
* @example
* ```
* import {
* functionDependsOn,
* getDependencies
* } from "@egomobile/documentation"
*
* function myFunction() {
* // ...
* }
*
* functionDependsOn(
* myFunction
* {
* // your information here...
* }
* )
*
* console.log(
* getDependencies()
* )
* ```
*
* @param {Func} func The function.
* @param {IDependencyInformation|DependencyInfoResolver} infoOrResolver The dependency information or the function that resolves it.
* @param {Nilable<DependenciesArg>} [dependenciesOrResolver] The custom collection for the dependency info items or the function that resolves it.
Expand Down

0 comments on commit bec7fe2

Please sign in to comment.