Skip to content

Commit

Permalink
Merge branch 'develop' into feat/fulfillment-providers-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
riqwan authored Jul 29, 2024
2 parents cbe1165 + 7ad4e7b commit 3503e84
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 29 deletions.
3 changes: 2 additions & 1 deletion www/utils/packages/docblock-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
},
"devDependencies": {
"@types/node": "^20.9.4",
"@types/pluralize": "^0.0.33"
"@types/pluralize": "^0.0.33",
"types": "*"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { GeneratorEvent } from "../helpers/generator-event-manager.js"
import { minimatch } from "minimatch"
import getBasePath from "../../utils/get-base-path.js"
import toJsonFormatted from "../../utils/to-json-formatted.js"
import { DmlFile } from "../../types/index.js"
import { DmlFile } from "types"

/**
* A class used to generate DML JSON files with descriptions of properties.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getDmlOutputBasePath } from "../../utils/get-output-base-paths.js"
import path from "path"
import { camelToWords, RELATION_NAMES, snakeToPascal } from "utils"
import toJsonFormatted from "../../utils/to-json-formatted.js"
import { DmlFile, DmlObject } from "../../types/index.js"
import { DmlFile, DmlObject } from "types"

/**
* DML generator for data models created with DML.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { readdirSync, existsSync, readFileSync, writeFileSync } from "fs"
import { getDmlOutputBasePath } from "../utils/get-output-base-paths.js"
import path from "path"
import getMonorepoRoot from "../utils/get-monorepo-root.js"
import { DmlFile } from "../types/index.js"
import { DmlFile } from "types"
import toJsonFormatted from "../utils/to-json-formatted.js"

export default async function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "typedoc-generate-references",
"license": "MIT",
"scripts": {
"dev": "cross-env ts-node src/index.ts",
"dev": "node --loader ts-node/esm src/index.ts",
"start": "node dist/index.js",
"build": "tsc",
"watch": "tsc --watch",
Expand Down
1 change: 1 addition & 0 deletions www/utils/packages/typedoc-plugin-custom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"devDependencies": {
"@types/eslint": "^8.56.6",
"@types/node": "^16.11.10",
"types": "*",
"typescript": "5.5"
},
"keywords": [
Expand Down
104 changes: 104 additions & 0 deletions www/utils/packages/typedoc-plugin-custom/src/dml-json-parser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { existsSync, readFileSync } from "fs"
import path from "path"
import {
Application,
Comment,
Context,
Converter,
DeclarationReflection,
ReferenceType,
} from "typedoc"
import { getDmlProperties, isDmlEntity } from "utils"
import { DmlFile } from "types"

const FILE_NAME_REGEX = /packages\/modules\/(?<module>[a-z-]+)/

export function load(app: Application) {
app.converter.on(
Converter.EVENT_CREATE_DECLARATION,
getDescriptionsFromJson,
2
)
}

function getDescriptionsFromJson(
context: Context,
reflection: DeclarationReflection
) {
if (!isDmlEntity(reflection)) {
return
}

const dmlPropertyReflections = getDmlProperties(
reflection.type as ReferenceType
)

if (!dmlPropertyReflections) {
return
}

const fileName = context.project
.getSymbolFromReflection(reflection)
?.valueDeclaration?.parent.getSourceFile().fileName

if (!fileName) {
return
}

const moduleName = FILE_NAME_REGEX.exec(fileName)

if (!moduleName?.groups?.module) {
return
}

const jsonFilePath = path.resolve(
__dirname,
path.join(
"..",
"..",
"..",
"generated",
"dml-output",
`${moduleName.groups.module}.json`
)
)

if (!existsSync(jsonFilePath)) {
return
}

const jsonFileContent = JSON.parse(
readFileSync(jsonFilePath, "utf-8")
) as DmlFile

if (!jsonFileContent[reflection.name]) {
return
}

Object.entries(jsonFileContent[reflection.name].properties).forEach(
([propertyName, description]) => {
const propertyReflection = dmlPropertyReflections.find(
(propertyRef) => propertyRef.name === propertyName
)

if (!propertyReflection) {
return
}

const comment = propertyReflection.comment || new Comment()

const isExpandable = description.includes("@expandable")

comment.summary.push({
kind: "text",
text: description.replace("@expandable", "").trim(),
})

if (isExpandable) {
comment.modifierTags.add("@expandable")
}

propertyReflection.comment = comment
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ export class DmlRelationsResolver {
this.resolveRelationReferences.bind(this),
1
)

// this.app.converter.on(
// Converter.EVENT_RESOLVE_BEGIN,
// this.resolveRelationTargets.bind(this),
// -1
// )
}

addReflection(_context: Context, reflection: DeclarationReflection) {
Expand Down Expand Up @@ -110,24 +104,6 @@ export class DmlRelationsResolver {
})
}

resolveRelationTargets(context: Context) {
if (!this.app.options.getValue("resolveDmlRelations")) {
return
}
this.relationProperties.forEach(({ property, target }) => {
const targetSymbol = context.project.getSymbolFromReflection(target)
if (property.type?.type !== "reference" || !targetSymbol) {
return
}
// change reference to the target itself.
property.type = ReferenceType.createResolvedReference(
`DmlEntity`,
target,
context.project
)
})
}

findReflectionMatchingProperties(
properties: DeclarationReflection[]
): DeclarationReflection | undefined {
Expand Down
2 changes: 2 additions & 0 deletions www/utils/packages/typedoc-plugin-custom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { GenerateNamespacePlugin } from "./generate-namespace"
import { DmlRelationsResolver } from "./dml-relations-resolver"
import { load as dmlTypesNormalizer } from "./dml-types-normalizer"
import { MermaidDiagramDMLGenerator } from "./mermaid-diagram-dml-generator"
import { load as dmlJsonParser } from "./dml-json-parser"

export function load(app: Application) {
resolveReferencesPluginLoad(app)
Expand All @@ -21,6 +22,7 @@ export function load(app: Application) {
signatureModifierPlugin(app)
parentIgnorePlugin(app)
dmlTypesNormalizer(app)
dmlJsonParser(app)

new GenerateNamespacePlugin(app)
new MermaidDiagramGenerator(app)
Expand Down
9 changes: 9 additions & 0 deletions www/utils/packages/types/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,12 @@ export declare module "typedoc" {
normalizeDmlTypes: boolean
}
}

export declare type DmlObject = Record<string, string>

export declare type DmlFile = {
[k: string]: {
filePath: string
properties: DmlObject
}
}
2 changes: 2 additions & 0 deletions www/utils/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2360,6 +2360,7 @@ __metadata:
pluralize: ^8.0.0
prettier: ^3.2.4
ts-node: ^10.9.1
types: "*"
typescript: 5.5
utils: "*"
yaml: ^2.3.4
Expand Down Expand Up @@ -5346,6 +5347,7 @@ __metadata:
"@types/node": ^16.11.10
eslint: ^8.53.0
glob: ^10.3.10
types: "*"
typescript: 5.5
utils: "*"
yaml: ^2.3.3
Expand Down

0 comments on commit 3503e84

Please sign in to comment.