Skip to content

Commit

Permalink
chore: follow contributing
Browse files Browse the repository at this point in the history
  • Loading branch information
GerkinDev committed Jun 10, 2023
1 parent 85e8a1b commit b8d2198
Show file tree
Hide file tree
Showing 26 changed files with 1,025 additions and 1,974 deletions.
6 changes: 4 additions & 2 deletions src/lib/converter/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,8 @@ export class Converter extends ChildableComponent<
// Special case for when we're giving a single entry point, we don't need to
// create modules for each entry. Register the project as this module.
context.project.registerReflection(context.project, symbol);
context.project.entrypointInfos = EntrypointInfos.fromDocumentationEntrypoint(entryPoint);
context.project.entrypointInfos =
EntrypointInfos.fromDocumentationEntrypoint(entryPoint);
context.project.comment = symbol
? context.getComment(symbol, context.project.kind)
: context.getFileComment(node);
Expand Down Expand Up @@ -412,7 +413,8 @@ export class Converter extends ChildableComponent<
}

reflection.packageVersion = entryPoint.version;
reflection.entrypointInfos = EntrypointInfos.fromDocumentationEntrypoint(entryPoint);
reflection.entrypointInfos =
EntrypointInfos.fromDocumentationEntrypoint(entryPoint);

context.finalizeDeclarationReflection(reflection);
moduleContext = context.withScope(reflection);
Expand Down
51 changes: 31 additions & 20 deletions src/lib/models/EntrypointInfos.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DocumentationEntryPoint, normalizePath } from "../utils";
import type { Deserializer, JSONOutput, Serializer } from "../serialization";
import type { JSONOutput } from "../serialization";
import { isAbsolute, relative } from "path";

export class EntrypointInfos {
Expand All @@ -13,13 +13,20 @@ export class EntrypointInfos {
this.entrySourceFilePath = entrySourceFilePath;
}

static fromDocumentationEntrypoint(docEntryPoint: DocumentationEntryPoint): EntrypointInfos {
const entrypointInfos = new EntrypointInfos(toRelative(docEntryPoint.rootDir), toRelative(docEntryPoint.sourceFile.fileName));
if(docEntryPoint.readmeFile){
entrypointInfos.readmeFile = toRelative(docEntryPoint.readmeFile)
static fromDocumentationEntrypoint(
docEntryPoint: DocumentationEntryPoint
): EntrypointInfos {
const entrypointInfos = new EntrypointInfos(
toRelative(docEntryPoint.rootDir),
toRelative(docEntryPoint.sourceFile.fileName)
);
if (docEntryPoint.readmeFile) {
entrypointInfos.readmeFile = toRelative(docEntryPoint.readmeFile);
}
if(docEntryPoint.packageJsonFile){
entrypointInfos.packageJsonFile = toRelative(docEntryPoint.packageJsonFile)
if (docEntryPoint.packageJsonFile) {
entrypointInfos.packageJsonFile = toRelative(
docEntryPoint.packageJsonFile
);
}
return entrypointInfos;
}
Expand All @@ -38,7 +45,7 @@ export class EntrypointInfos {
return entrypointInfos;
}

toObject(serializer: Serializer): JSONOutput.EntrypointInfos {
toObject(): JSONOutput.EntrypointInfos {
return {
readmeFile: this.readmeFile,
rootDir: this.rootDir,
Expand All @@ -47,29 +54,33 @@ export class EntrypointInfos {
};
}


static fromObject(de: Deserializer, obj?: JSONOutput.EntrypointInfos) {
if(!obj){
static fromObject(obj?: JSONOutput.EntrypointInfos) {
if (!obj) {
return undefined;
}
const entrypointInfos = new EntrypointInfos(obj.rootDir, obj.entrySourceFilePath);
entrypointInfos.fromObject(de, obj);
const entrypointInfos = new EntrypointInfos(
obj.rootDir,
obj.entrySourceFilePath
);
entrypointInfos.fromObject(obj);
return entrypointInfos;
}
fromObject(de: Deserializer, obj: JSONOutput.EntrypointInfos) {
if(obj.readmeFile){

fromObject(obj: JSONOutput.EntrypointInfos) {
if (obj.readmeFile) {
this.readmeFile = obj.readmeFile;
}
if(obj.packageJsonFile){
if (obj.packageJsonFile) {
this.packageJsonFile = obj.packageJsonFile;
}
}
}

const toRelative = <T extends string | undefined>(path: T): T => {
if(path){
return normalizePath(isAbsolute(path) ? relative(process.cwd(), path) : path) as T;
if (path) {
return normalizePath(
isAbsolute(path) ? relative(process.cwd(), path) : path
) as T;
}
return path;
}
};
6 changes: 4 additions & 2 deletions src/lib/models/reflections/declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,9 @@ export class DeclarationReflection extends ContainerReflection {
if (obj.variant === "project") {
this.kind = ReflectionKind.Module;
this.packageVersion = obj.packageVersion;
this.entrypointInfos = EntrypointInfos.fromObject(de, obj.entrypointInfos);
this.entrypointInfos = EntrypointInfos.fromObject(
obj.entrypointInfos
);
if (obj.readme) {
this.readme = Comment.deserializeDisplayParts(de, obj.readme);
}
Expand All @@ -354,7 +356,7 @@ export class DeclarationReflection extends ContainerReflection {
}

this.packageVersion = obj.packageVersion;
this.entrypointInfos = EntrypointInfos.fromObject(de, obj.entrypointInfos);
this.entrypointInfos = EntrypointInfos.fromObject(obj.entrypointInfos);
this.sources = de.reviveMany(
obj.sources,
(src) => new SourceReference(src.fileName, src.line, src.character)
Expand Down
4 changes: 2 additions & 2 deletions src/lib/models/reflections/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export class ProjectReflection extends ContainerReflection {
variant: this.variant,
packageName: this.packageName,
packageVersion: this.packageVersion,
entrypointInfos: this.entrypointInfos?.toObject(serializer),
entrypointInfos: this.entrypointInfos?.toObject(),
readme: Comment.serializeDisplayParts(serializer, this.readme),
symbolIdMap,
};
Expand All @@ -301,7 +301,7 @@ export class ProjectReflection extends ContainerReflection {
if (obj.readme) {
this.readme = Comment.deserializeDisplayParts(de, obj.readme);
}
this.entrypointInfos = EntrypointInfos.fromObject(de, obj.entrypointInfos);
this.entrypointInfos = EntrypointInfos.fromObject(obj.entrypointInfos);

de.defer(() => {
for (const [id, sid] of Object.entries(obj.symbolIdMap || {})) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/serialization/deserializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export class Deserializer {
}

const project = new ProjectReflection(name);
project.entrypointInfos = new EntrypointInfos('.')
project.entrypointInfos = new EntrypointInfos(".");
project.children = [];
this.project = project;

Expand Down
13 changes: 10 additions & 3 deletions src/lib/serialization/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ export interface ProjectReflection
extends Omit<ContainerReflection, "variant">,
S<
M.ProjectReflection,
"variant" | "packageName" | "packageVersion" | "readme" | "entrypointInfos"
| "variant"
| "packageName"
| "packageVersion"
| "readme"
| "entrypointInfos"
> {
symbolIdMap: Record<number, ReflectionSymbolId>;
}
Expand Down Expand Up @@ -359,5 +363,8 @@ export interface InlineTagDisplayPart {
export interface SourceReference
extends S<M.SourceReference, "fileName" | "line" | "character" | "url"> {}

export interface EntrypointInfos
extends S<M.EntrypointInfos, "readmeFile" | "rootDir" | "packageJsonFile" | "entrySourceFilePath"> {}
export interface EntrypointInfos
extends S<
M.EntrypointInfos,
"readmeFile" | "rootDir" | "packageJsonFile" | "entrySourceFilePath"
> {}
4 changes: 2 additions & 2 deletions src/lib/utils/entry-point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ function getEntryPointsForPaths(
displayName: getModuleName(resolve(check), baseDir),
sourceFile,
program,
rootDir
rootDir,
});
continue entryLoop;
}
Expand Down Expand Up @@ -483,7 +483,7 @@ function getEntryPointsForLegacyPackages(
program,
sourceFile,
rootDir: packagePath,
packageJsonFile: packageJsonPath
packageJsonFile: packageJsonPath,
});
}

Expand Down
18 changes: 6 additions & 12 deletions src/test/converter/alias/specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
{
"fileName": "alias.ts",
"line": 16,
"character": 12,
"url": "typedoc://alias.ts#L16"
"character": 12
}
],
"typeParameters": [
Expand Down Expand Up @@ -77,8 +76,7 @@
{
"fileName": "alias.ts",
"line": 26,
"character": 12,
"url": "typedoc://alias.ts#L26"
"character": 12
}
],
"type": {
Expand Down Expand Up @@ -109,8 +107,7 @@
{
"fileName": "alias.ts",
"line": 21,
"character": 12,
"url": "typedoc://alias.ts#L21"
"character": 12
}
],
"typeParameters": [
Expand Down Expand Up @@ -169,8 +166,7 @@
{
"fileName": "alias.ts",
"line": 6,
"character": 12,
"url": "typedoc://alias.ts#L6"
"character": 12
}
],
"typeParameters": [
Expand All @@ -194,8 +190,7 @@
{
"fileName": "alias.ts",
"line": 6,
"character": 34,
"url": "typedoc://alias.ts#L6"
"character": 34
}
],
"signatures": [
Expand Down Expand Up @@ -268,8 +263,7 @@
{
"fileName": "alias.ts",
"line": 11,
"character": 12,
"url": "typedoc://alias.ts#L11"
"character": 12
}
],
"type": {
Expand Down

0 comments on commit b8d2198

Please sign in to comment.