docs-util: fixes to package renames + other options (#9671)

This commit is contained in:
Shahed Nasser authored and GitHub committed 2024-10-21 09:53:47 +03:00
1 parent 4829b16e6f
commit 34621f53a3
11 files changed
+200 -131

No files matched your search

@@ -1,11 +1,11 @@
{ {
"$schema": "http://json.schemastore.org/tsconfig", "$schema": "http://json.schemastore.org/tsconfig",
"extends": [ "extends": [
"../../../../packages/modules/inventory-next/tsconfig.json" "../../../../packages/modules/inventory/tsconfig.json"
], ],
"include": ["../../../../packages/modules/inventory-next/src"], "include": ["../../../../packages/modules/inventory/src"],
"exclude": [ "exclude": [
"../../../../packages/modules/inventory-next/dist", "../../../../packages/modules/inventory/dist",
"../../../../packages/modules/inventory-next/node_modules" "../../../../packages/modules/inventory/node_modules"
] ]
} }
@@ -1,11 +1,11 @@
{ {
"$schema": "http://json.schemastore.org/tsconfig", "$schema": "http://json.schemastore.org/tsconfig",
"extends": [ "extends": [
"../../../../packages/modules/stock-location-next/tsconfig.json" "../../../../packages/modules/stock-location/tsconfig.json"
], ],
"include": ["../../../../packages/modules/stock-location-next/src"], "include": ["../../../../packages/modules/stock-location/src"],
"exclude": [ "exclude": [
"../../../../packages/modules/stock-location-next/dist", "../../../../packages/modules/stock-location/dist",
"../../../../packages/modules/stock-location-next/node_modules" "../../../../packages/modules/stock-location/node_modules"
] ]
} }
@@ -40,14 +40,22 @@ export default async function generate(
outputType: "json", outputType: "json",
}) })
const modelReferenceName = `${referenceName}-models`
const modelOptions = getModelOptions({ const modelOptions = getModelOptions({
moduleName: referenceName, moduleName: referenceName,
typedocOptions: Object.hasOwn(
customModulesOptions,
modelReferenceName
)
? customModulesOptions[modelReferenceName]
: undefined,
}) })
try { try {
await generateReference({ await generateReference({
options: modelOptions, options: modelOptions,
referenceName: `${referenceName}-models`, referenceName: modelReferenceName,
outputType: "json", outputType: "json",
}) })
} catch (e) { } catch (e) {
@@ -58,6 +58,7 @@ const customOptions: Record<string, Partial<TypeDocOptions>> = {
tsConfigName: "js-sdk.json", tsConfigName: "js-sdk.json",
name: "js-sdk", name: "js-sdk",
enableInternalResolve: true, enableInternalResolve: true,
exclude: [...(baseOptions.exclude || []), "**/dist/**"],
}), }),
"helper-steps": getOptions({ "helper-steps": getOptions({
entryPointPath: "packages/core/core-flows/src/common/index.ts", entryPointPath: "packages/core/core-flows/src/common/index.ts",
@@ -37,7 +37,7 @@ const jsSdkOptions: FormattingOptionsType = {
reflectionDescription: reflectionDescription:
"This documentation provides a reference to the `sdk.store.{{alias}}` set of methods used to send requests to Medusa's Store API routes.", "This documentation provides a reference to the `sdk.store.{{alias}}` set of methods used to send requests to Medusa's Store API routes.",
}, },
"^js_sdk/store/classes/.*Admin": { "^js_sdk/admin/classes/.*Admin": {
frontmatterData: { frontmatterData: {
slug: "/references/js-sdk/admin", slug: "/references/js-sdk/admin",
}, },
@@ -60,7 +60,7 @@ const jsSdkOptions: FormattingOptionsType = {
reflectionDescription: reflectionDescription:
"This documentation provides a reference to the `sdk.admin.{{alias}}` set of methods used to send requests to Medusa's Admin API routes.", "This documentation provides a reference to the `sdk.admin.{{alias}}` set of methods used to send requests to Medusa's Admin API routes.",
}, },
"^js_sdk/store/classes/.*Auth": { "^js_sdk/auth/classes/.*Auth": {
frontmatterData: { frontmatterData: {
slug: "/references/js-sdk/auth", slug: "/references/js-sdk/auth",
}, },
@@ -1,4 +1,4 @@
import { TypeDocOptions } from "typedoc" import { ReflectionKind, TypeDocOptions } from "typedoc"
import { baseOptions } from "./base-options.js" import { baseOptions } from "./base-options.js"
import path from "path" import path from "path"
import { jsonOutputPathPrefix, rootPathPrefix } from "./general.js" import { jsonOutputPathPrefix, rootPathPrefix } from "./general.js"
@@ -8,7 +8,7 @@ import {
customModuleTitles, customModuleTitles,
dmlModules, dmlModules,
} from "./references-details.js" } from "./references-details.js"
import { FormattingOptionType } from "types" import { AllowedProjectDocumentsOption, FormattingOptionType } from "types"
import { kebabToCamel, kebabToPascal, kebabToSnake, kebabToTitle } from "utils" import { kebabToCamel, kebabToPascal, kebabToSnake, kebabToTitle } from "utils"
import baseSectionsOptions from "./base-section-options.js" import baseSectionsOptions from "./base-section-options.js"
import mergerCustomOptions from "./merger-custom-options/index.js" import mergerCustomOptions from "./merger-custom-options/index.js"
@@ -17,6 +17,39 @@ import {
getNamespaceNames, getNamespaceNames,
} from "../utils/get-namespaces.js" } from "../utils/get-namespaces.js"
const commonAllowedDocuments = {
[ReflectionKind.Variable]: true,
[ReflectionKind.Function]: true,
[ReflectionKind.Method]: true,
}
const allowedProjectDocuments: AllowedProjectDocumentsOption = {
dml: commonAllowedDocuments,
"helper-steps": commonAllowedDocuments,
workflows: commonAllowedDocuments,
"js-sdk": {
[ReflectionKind.Method]: true,
[ReflectionKind.Property]: true,
},
}
modules.forEach((module) => {
allowedProjectDocuments[module] = {
...commonAllowedDocuments,
}
})
dmlModules.forEach((module) => {
allowedProjectDocuments[`${module}-models`] = {
...commonAllowedDocuments,
}
})
getNamespaceNames(getCoreFlowNamespaces()).forEach((namespace) => {
allowedProjectDocuments[namespace] = {
...commonAllowedDocuments,
}
})
const mergerOptions: Partial<TypeDocOptions> = { const mergerOptions: Partial<TypeDocOptions> = {
...baseOptions, ...baseOptions,
entryPoints: [path.join(jsonOutputPathPrefix, "*.json")], entryPoints: [path.join(jsonOutputPathPrefix, "*.json")],
@@ -33,17 +66,8 @@ const mergerOptions: Partial<TypeDocOptions> = {
objectLiteralTypeDeclarationStyle: "component", objectLiteralTypeDeclarationStyle: "component",
mdxOutput: true, mdxOutput: true,
maxLevel: 3, maxLevel: 3,
allReflectionsHaveOwnDocument: [ // @ts-expect-error this is due to a typing issue in typedoc
...modules, allowedProjectDocuments,
...dmlModules.map((module) => `${module}-models`),
"dml",
"helper-steps",
"workflows",
],
allPropertyReflectionsHaveOwnDocument: ["js-sdk"],
allReflectionsHaveOwnDocumentInNamespace: [
...getNamespaceNames(getCoreFlowNamespaces()),
],
formatting: { formatting: {
"*": { "*": {
showCommentsAsHeader: true, showCommentsAsHeader: true,
@@ -22,6 +22,16 @@ export const customModulesOptions: Record<string, Partial<TypeDocOptions>> = {
"packages/core/types/src/stock-location/service.ts" "packages/core/types/src/stock-location/service.ts"
), ),
}, },
"inventory-next-models": {
entryPoints: getEntryPoints(
"packages/modules/inventory/src/models/index.ts"
),
},
"stock-location-next-models": {
entryPoints: getEntryPoints(
"packages/modules/stock-location/src/models/index.ts"
),
},
} }
// a list of modules that now support DML // a list of modules that now support DML
@@ -33,13 +33,6 @@ export function load(app: Application) {
defaultValue: false, defaultValue: false,
}) })
app.options.addDeclaration({
help: "[Markdown Plugin] Specify module names where all reflections are outputted into seperate files.",
name: "allReflectionsHaveOwnDocument",
type: ParameterType.Array,
defaultValue: [],
})
app.options.addDeclaration({ app.options.addDeclaration({
help: "[Markdown Plugin] Specify module names where property reflections are outputted into seperate files.", help: "[Markdown Plugin] Specify module names where property reflections are outputted into seperate files.",
name: "allPropertyReflectionsHaveOwnDocument", name: "allPropertyReflectionsHaveOwnDocument",
@@ -48,9 +41,9 @@ export function load(app: Application) {
}) })
app.options.addDeclaration({ app.options.addDeclaration({
help: "[Markdown Plugin] Specify namespace names where all reflections are outputted into seperate files.", help: "[Markdown Plugin] Specify for each project / module the allowed document types",
name: "allReflectionsHaveOwnDocumentInNamespace", name: "allowedProjectDocuments",
type: ParameterType.Array, type: ParameterType.Mixed,
defaultValue: [], defaultValue: [],
}) })
@@ -14,13 +14,15 @@ export default function (theme: MarkdownTheme) {
function (this: ProjectReflection | DeclarationReflection) { function (this: ProjectReflection | DeclarationReflection) {
const md: string[] = [] const md: string[] = []
const { hideInPageTOC, allReflectionsHaveOwnDocumentInNamespace } = theme const { hideInPageTOC } = theme
const { hideTocHeaders, reflectionGroupRename = {} } = const { hideTocHeaders, reflectionGroupRename = {} } =
theme.getFormattingOptionsForLocation() theme.getFormattingOptionsForLocation()
const isNamespaceVisible = const isNamespaceVisible =
this.kind === ReflectionKind.Namespace && this.kind === ReflectionKind.Namespace &&
allReflectionsHaveOwnDocumentInNamespace.includes(this.name) theme.getMappings(this as DeclarationReflection)[
ReflectionKind.Namespace
]
const isVisible = const isVisible =
isNamespaceVisible || isNamespaceVisible ||
this.groups?.some((group) => { this.groups?.some((group) => {
@@ -22,6 +22,7 @@ import {
import { formatContents } from "./utils" import { formatContents } from "./utils"
import type { import type {
AllowedProjectDocumentsOption,
FormattingOptionType, FormattingOptionType,
FormattingOptionsType, FormattingOptionsType,
ParameterStyle, ParameterStyle,
@@ -29,9 +30,8 @@ import type {
import { Mapping } from "./types" import { Mapping } from "./types"
export class MarkdownTheme extends Theme { export class MarkdownTheme extends Theme {
allReflectionsHaveOwnDocument!: string[]
allPropertyReflectionsHaveOwnDocument!: string[] allPropertyReflectionsHaveOwnDocument!: string[]
allReflectionsHaveOwnDocumentInNamespace: string[] allowedProjectDocuments: AllowedProjectDocumentsOption
entryDocument: string entryDocument: string
entryPoints!: string[] entryPoints!: string[]
filenameSeparator!: string filenameSeparator!: string
@@ -64,14 +64,12 @@ export class MarkdownTheme extends Theme {
constructor(renderer: Renderer) { constructor(renderer: Renderer) {
super(renderer) super(renderer)
// prettier-ignore
this.allReflectionsHaveOwnDocument = this.getOption("allReflectionsHaveOwnDocument") as string[]
this.allPropertyReflectionsHaveOwnDocument = this.getOption( this.allPropertyReflectionsHaveOwnDocument = this.getOption(
"allPropertyReflectionsHaveOwnDocument" "allPropertyReflectionsHaveOwnDocument"
) as string[] ) as string[]
this.allReflectionsHaveOwnDocumentInNamespace = this.getOption( this.allowedProjectDocuments = this.getOption(
"allReflectionsHaveOwnDocumentInNamespace" "allowedProjectDocuments"
) as string[] ) as AllowedProjectDocumentsOption
this.entryDocument = this.getOption("entryDocument") as string this.entryDocument = this.getOption("entryDocument") as string
this.entryPoints = this.getOption("entryPoints") as string[] this.entryPoints = this.getOption("entryPoints") as string[]
this.filenameSeparator = this.getOption("filenameSeparator") as string this.filenameSeparator = this.getOption("filenameSeparator") as string
@@ -338,33 +336,52 @@ export class MarkdownTheme extends Theme {
return parents return parents
} }
getAllReflectionsHaveOwnDocument( getAllowedReflectionDocuments(reflection: DeclarationReflection) {
reflection: DeclarationReflection, const documents = {
checkProperties?: boolean [ReflectionKind.Module]: true,
): boolean { [ReflectionKind.Namespace]: true,
[ReflectionKind.Enum]: true,
[ReflectionKind.Class]: true,
[ReflectionKind.Interface]: true,
[ReflectionKind.TypeAlias]: true,
[ReflectionKind.Variable]: false,
[ReflectionKind.Function]: false,
[ReflectionKind.Method]: false,
[ReflectionKind.Property]: false,
}
let options: Record<ReflectionKind, boolean> | undefined
const moduleParents = this.getParentsOfKind( const moduleParents = this.getParentsOfKind(
reflection, reflection,
ReflectionKind.Module ReflectionKind.Module
) ).reverse() // projects come last, this changes the direction to give projects higher priority
const namespaceParents = this.getParentsOfKind( const namespaceParents = this.getParentsOfKind(
reflection, reflection,
ReflectionKind.Namespace ReflectionKind.Namespace
) )
if (checkProperties) { moduleParents.some((parent) => {
return moduleParents.some((parent) => if (!Object.hasOwn(this.allowedProjectDocuments, parent.name)) {
this.allPropertyReflectionsHaveOwnDocument.includes(parent.name) return false
) }
}
return ( options = this.allowedProjectDocuments[parent.name]
moduleParents.some((parent) => return true
this.allReflectionsHaveOwnDocument.includes(parent.name) }) ||
) || namespaceParents.some((parent) => {
namespaceParents.some((parent) => if (!Object.hasOwn(this.allowedProjectDocuments, parent.name)) {
this.allReflectionsHaveOwnDocumentInNamespace.includes(parent.name) return false
) }
)
options = this.allowedProjectDocuments[parent.name]
return true
})
return {
...documents,
...(options || {}),
}
} }
getFileNameSeparator(pathPrefix: string): string { getFileNameSeparator(pathPrefix: string): string {
@@ -376,8 +393,11 @@ export class MarkdownTheme extends Theme {
reflection: DeclarationReflection, reflection: DeclarationReflection,
directoryPrefix?: string directoryPrefix?: string
): Mapping[] { ): Mapping[] {
return [ const allowedDocuments = this.getAllowedReflectionDocuments(reflection)
{ const mappings: Mapping[] = []
if (allowedDocuments[ReflectionKind.Module]) {
mappings.push({
kind: [ReflectionKind.Module], kind: [ReflectionKind.Module],
modifiers: { modifiers: {
has: [], has: [],
@@ -386,8 +406,10 @@ export class MarkdownTheme extends Theme {
isLeaf: false, isLeaf: false,
directory: path.join(directoryPrefix || "", "modules"), directory: path.join(directoryPrefix || "", "modules"),
template: this.getReflectionTemplate(), template: this.getReflectionTemplate(),
}, })
{ }
if (allowedDocuments[ReflectionKind.Namespace]) {
mappings.push({
kind: [ReflectionKind.Namespace], kind: [ReflectionKind.Namespace],
modifiers: { modifiers: {
has: [], has: [],
@@ -396,8 +418,10 @@ export class MarkdownTheme extends Theme {
isLeaf: false, isLeaf: false,
directory: path.join(directoryPrefix || ""), directory: path.join(directoryPrefix || ""),
template: this.getReflectionTemplate(), template: this.getReflectionTemplate(),
}, })
{ }
if (allowedDocuments[ReflectionKind.Enum]) {
mappings.push({
kind: [ReflectionKind.Enum], kind: [ReflectionKind.Enum],
modifiers: { modifiers: {
has: [], has: [],
@@ -406,8 +430,10 @@ export class MarkdownTheme extends Theme {
isLeaf: false, isLeaf: false,
directory: path.join(directoryPrefix || "", "enums"), directory: path.join(directoryPrefix || "", "enums"),
template: this.getReflectionTemplate(), template: this.getReflectionTemplate(),
}, })
{ }
if (allowedDocuments[ReflectionKind.Class]) {
mappings.push({
kind: [ReflectionKind.Class], kind: [ReflectionKind.Class],
modifiers: { modifiers: {
has: [], has: [],
@@ -416,8 +442,10 @@ export class MarkdownTheme extends Theme {
isLeaf: false, isLeaf: false,
directory: path.join(directoryPrefix || "", "classes"), directory: path.join(directoryPrefix || "", "classes"),
template: this.getReflectionTemplate(), template: this.getReflectionTemplate(),
}, })
{ }
if (allowedDocuments[ReflectionKind.Interface]) {
mappings.push({
kind: [ReflectionKind.Interface], kind: [ReflectionKind.Interface],
modifiers: { modifiers: {
has: [], has: [],
@@ -426,8 +454,11 @@ export class MarkdownTheme extends Theme {
isLeaf: false, isLeaf: false,
directory: path.join(directoryPrefix || "", "interfaces"), directory: path.join(directoryPrefix || "", "interfaces"),
template: this.getReflectionTemplate(), template: this.getReflectionTemplate(),
}, })
{ }
if (allowedDocuments[ReflectionKind.TypeAlias]) {
mappings.push({
kind: [ReflectionKind.TypeAlias], kind: [ReflectionKind.TypeAlias],
modifiers: { modifiers: {
has: [], has: [],
@@ -436,56 +467,59 @@ export class MarkdownTheme extends Theme {
isLeaf: true, isLeaf: true,
directory: path.join(directoryPrefix || "", "types"), directory: path.join(directoryPrefix || "", "types"),
template: this.getReflectionMemberTemplate(), template: this.getReflectionMemberTemplate(),
}, })
...(this.getAllReflectionsHaveOwnDocument(reflection) }
? [
{ if (allowedDocuments[ReflectionKind.Variable]) {
kind: [ReflectionKind.Variable], mappings.push({
modifiers: { kind: [ReflectionKind.Variable],
has: [], modifiers: {
not: [], has: [],
}, not: [],
isLeaf: true, },
directory: path.join(directoryPrefix || "", "variables"), isLeaf: true,
template: this.getReflectionMemberTemplate(), directory: path.join(directoryPrefix || "", "variables"),
}, template: this.getReflectionMemberTemplate(),
{ })
kind: [ReflectionKind.Function], }
modifiers: { if (allowedDocuments[ReflectionKind.Function]) {
has: [], mappings.push({
not: [], kind: [ReflectionKind.Function],
}, modifiers: {
isLeaf: true, has: [],
directory: path.join(directoryPrefix || "", "functions"), not: [],
template: this.getReflectionMemberTemplate(), },
}, isLeaf: true,
{ directory: path.join(directoryPrefix || "", "functions"),
kind: [ReflectionKind.Method], template: this.getReflectionMemberTemplate(),
modifiers: { })
has: [], }
not: [], if (allowedDocuments[ReflectionKind.Method]) {
}, mappings.push({
isLeaf: true, kind: [ReflectionKind.Method],
directory: path.join(directoryPrefix || "", "methods"), modifiers: {
template: this.getReflectionMemberTemplate(), has: [],
}, not: [],
] },
: []), isLeaf: true,
...(this.getAllReflectionsHaveOwnDocument(reflection, true) directory: path.join(directoryPrefix || "", "methods"),
? [ template: this.getReflectionMemberTemplate(),
{ })
kind: [ReflectionKind.Property], }
modifiers: { if (allowedDocuments[ReflectionKind.Property]) {
has: [], mappings.push({
not: [], kind: [ReflectionKind.Property],
}, modifiers: {
isLeaf: true, has: [],
directory: path.join(directoryPrefix || "", "properties"), not: [],
template: this.getReflectionMemberTemplate(), },
}, isLeaf: true,
] directory: path.join(directoryPrefix || "", "properties"),
: []), template: this.getReflectionMemberTemplate(),
] })
}
return mappings
} }
/** /**
+5 -8
View File
@@ -86,6 +86,10 @@ export type FormattingOptionType = {
workflowDiagramComponent?: string workflowDiagramComponent?: string
} }
export type AllowedProjectDocumentsOption = {
[k: string]: Record<number, boolean>
}
export declare module "typedoc" { export declare module "typedoc" {
declare interface TypeDocOptionMap { declare interface TypeDocOptionMap {
/** /**
@@ -136,14 +140,7 @@ export declare module "typedoc" {
* @defaultValue false * @defaultValue false
*/ */
namedAnchors: boolean namedAnchors: boolean
/** allowedProjectDocuments: AllowedProjectDocumentsOption
* [Markdown Plugin] Specify module names where all reflections are outputted into seperate files.
*/
allReflectionsHaveOwnDocument: string[]
/**
* [Markdown Plugin] Specify module names where property reflections are outputted into seperate files.
*/
allPropertyReflectionsHaveOwnDocument: string[]
/** /**
* [Markdown Plugin] Separator used to format filenames. * [Markdown Plugin] Separator used to format filenames.
* @defaultValue "." * @defaultValue "."