Skip to content

Commit

Permalink
docs-util: fixes following packages reorg (#9326)
Browse files Browse the repository at this point in the history
- Typescript config aren't picked up properly anymore since they're moved to `_tsconfig.base.json` in the root. So, we now read the config from the config file.
- Update Typescript version in the `utils` monorepo to match that of the root monorepo
  • Loading branch information
shahednasser authored Sep 26, 2024
1 parent 229da19 commit bd4d2fd
Show file tree
Hide file tree
Showing 15 changed files with 107 additions and 31 deletions.
2 changes: 1 addition & 1 deletion www/utils/packages/docs-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"pluralize": "^8.0.0",
"prettier": "^3.2.4",
"ts-node": "^10.9.1",
"typescript": "5.5",
"typescript": "^5.6.2",
"utils": "*",
"yaml": "^2.3.4"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CommonCliOptions } from "../../types/index.js"
import { existsSync, readdirSync, statSync } from "node:fs"
import path from "node:path"
import getBasePath from "../../utils/get-base-path.js"
import getMonorepoRoot from "../../utils/get-monorepo-root.js"

export type Options = {
paths: string[]
Expand Down Expand Up @@ -50,7 +51,7 @@ abstract class AbstractGenerator {
)
})

this.program = ts.createProgram(files, {})
this.program = ts.createProgram(files, this.getBaseCompilerOptions())

this.checker = this.program.getTypeChecker()

Expand Down Expand Up @@ -90,6 +91,23 @@ abstract class AbstractGenerator {
this.program = undefined
this.checker = undefined
}

getBaseCompilerOptions(): ts.CompilerOptions {
const monorepoPath = getMonorepoRoot()
const tsconfigBasePath = path.join(monorepoPath, "_tsconfig.base.json")

const configStr = ts.sys.readFile(tsconfigBasePath)

if (!configStr) {
return {}
}

return ts.parseJsonConfigFileContent(
JSON.parse(configStr),
ts.sys,
monorepoPath
).options
}
}

export default AbstractGenerator
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,34 @@ class SchemaFactory {
BigNumberValue: {
type: "number",
},
expand: {
type: "string",
title: "expand",
description:
"Comma-separated relations that should be expanded in the returned data.",
},
fields: {
type: "string",
title: "fields",
description:
"Comma-separated fields that should be included in the returned data. if a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields. without prefix it will replace the entire default fields.",
},
offset: {
type: "number",
title: "offset",
description: "The number of items to skip when retrieving a list.",
},
limit: {
type: "number",
title: "limit",
description: "Limit the number of items returned in the list.",
},
order: {
type: "string",
title: "order",
description:
"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.",
},
File: {
type: "object",
description: "A File to upload.",
Expand Down
30 changes: 29 additions & 1 deletion www/utils/packages/docs-generator/src/classes/helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ export default class TypesHelper {
}

cleanUpTypes(types: ts.Type[]): ts.Type[] {
let cleanedUpTypes = this.removeStringRegExpTypeOverlaps(types)
let cleanedUpTypes = this.removeUndefinedNullTypes(types)

cleanedUpTypes = this.removeExtraBoolean(cleanedUpTypes)

cleanedUpTypes = this.removeStringRegExpTypeOverlaps(cleanedUpTypes)

cleanedUpTypes = this.joinDateAndString(cleanedUpTypes)

Expand Down Expand Up @@ -80,4 +84,28 @@ export default class TypesHelper {

return dateType && hasStringType ? [dateType] : types
}

private removeUndefinedNullTypes(types: ts.Type[]): ts.Type[] {
return types.filter(
(type) =>
type.flags !== ts.TypeFlags.Undefined &&
type.flags !== ts.TypeFlags.Null
)
}

private removeExtraBoolean(types: ts.Type[]): ts.Type[] {
let found = false
return types.filter((tsType) => {
if (tsType.flags !== ts.TypeFlags.BooleanLiteral) {
return true
}

if (!found) {
found = true
return true
}

return false
})
}
}
4 changes: 3 additions & 1 deletion www/utils/packages/docs-generator/src/classes/kinds/oas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,9 @@ class OasKindGenerator extends FunctionKindGenerator {
name: title,
}),
}
case "intrinsicName" in itemType && itemType.intrinsicName === "boolean":
case ("intrinsicName" in itemType &&
itemType.intrinsicName === "boolean") ||
itemType.flags === ts.TypeFlags.BooleanLiteral:
return {
type: "boolean",
title: title || typeAsString,
Expand Down
2 changes: 1 addition & 1 deletion www/utils/packages/react-docs-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"ts-node": "^10.9.1",
"typedoc": "^0.26.2",
"typedoc-plugin-custom": "*",
"typescript": "5.5",
"typescript": "^5.6.2",
"utils": "*"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion www/utils/packages/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"glob": "^10.3.10",
"randomcolor": "^0.6.2",
"ts-node": "^10.9.1",
"typescript": "5.5"
"typescript": "^5.6.2"
},
"devDependencies": {
"@types/node": "^20.12.10",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"typedoc-plugin-rename-defaults": "^0.7.0",
"typedoc-plugin-workflows": "*",
"types": "*",
"typescript": "5.5",
"typescript": "^5.6.2",
"utils": "*",
"yaml": "^2.3.4"
},
Expand Down
2 changes: 1 addition & 1 deletion www/utils/packages/typedoc-plugin-custom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@types/eslint": "^8.56.6",
"@types/node": "^20.12.10",
"types": "*",
"typescript": "5.5"
"typescript": "^5.6.2"
},
"keywords": [
"typedocplugin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"copyfiles": "^2.4.1",
"typedoc": "^0.26.2",
"types": "*",
"typescript": "5.5"
"typescript": "^5.6.2"
},
"keywords": [
"typedocplugin",
Expand Down
2 changes: 1 addition & 1 deletion www/utils/packages/typedoc-plugin-workflows/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@types/eslint": "^8.56.6",
"@types/node": "^20.12.10",
"types": "*",
"typescript": "5.5"
"typescript": "^5.6.2"
},
"keywords": [
"typedocplugin",
Expand Down
2 changes: 1 addition & 1 deletion www/utils/packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"typedoc": "0.26.x"
},
"devDependencies": {
"typescript": "5.5"
"typescript": "^5.6.2"
},
"version": "0.0.0",
"main": "./lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion www/utils/packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"devDependencies": {
"@types/node": "^20.12.10",
"typescript": "5.5"
"typescript": "^5.6.2"
},
"dependencies": {
"octokit": "^3.1.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@mermaid-js/mermaid-cli": "^10.6.1",
"commander": "^11.1.0",
"ts-node": "^10.9.1",
"typescript": "5.5"
"typescript": "^5.6.2"
},
"devDependencies": {
"@types/node": "^20.12.10"
Expand Down
36 changes: 18 additions & 18 deletions www/utils/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2387,7 +2387,7 @@ __metadata:
prettier: ^3.2.4
ts-node: ^10.9.1
types: "*"
typescript: 5.5
typescript: ^5.6.2
utils: "*"
yaml: ^2.3.4
languageName: unknown
Expand Down Expand Up @@ -4651,7 +4651,7 @@ __metadata:
ts-node: ^10.9.1
typedoc: ^0.26.2
typedoc-plugin-custom: "*"
typescript: 5.5
typescript: ^5.6.2
utils: "*"
peerDependencies:
typedoc: 0.25.x
Expand Down Expand Up @@ -4855,7 +4855,7 @@ __metadata:
glob: ^10.3.10
randomcolor: ^0.6.2
ts-node: ^10.9.1
typescript: 5.5
typescript: ^5.6.2
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -5369,7 +5369,7 @@ __metadata:
typedoc-plugin-rename-defaults: ^0.7.0
typedoc-plugin-workflows: "*"
types: "*"
typescript: 5.5
typescript: ^5.6.2
utils: "*"
yaml: ^2.3.4
peerDependencies:
Expand All @@ -5387,7 +5387,7 @@ __metadata:
glob: ^10.3.10
minimatch: ^10.0.1
types: "*"
typescript: 5.5
typescript: ^5.6.2
utils: "*"
yaml: ^2.3.3
peerDependencies:
Expand All @@ -5404,7 +5404,7 @@ __metadata:
handlebars: ^4.7.8
typedoc: ^0.26.2
types: "*"
typescript: 5.5
typescript: ^5.6.2
utils: "*"
peerDependencies:
typedoc: 0.26.x
Expand Down Expand Up @@ -5433,7 +5433,7 @@ __metadata:
eslint: ^8.53.0
glob: ^10.3.10
types: "*"
typescript: 5.5
typescript: ^5.6.2
utils: "*"
yaml: ^2.3.3
peerDependencies:
Expand Down Expand Up @@ -5462,29 +5462,29 @@ __metadata:
version: 0.0.0-use.local
resolution: "types@workspace:packages/types"
dependencies:
typescript: 5.5
typescript: ^5.6.2
peerDependencies:
typedoc: 0.26.x
languageName: unknown
linkType: soft

"typescript@npm:5.5":
version: 5.5.2
resolution: "typescript@npm:5.5.2"
"typescript@npm:^5.6.2":
version: 5.6.2
resolution: "typescript@npm:5.6.2"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 8ca39b27b5f9bd7f32db795045933ab5247897660627251e8254180b792a395bf061ea7231947d5d7ffa5cb4cc771970fd4ef543275f9b559f08c9325cccfce3
checksum: 3ed8297a8c7c56b7fec282532503d1ac795239d06e7c4966b42d4330c6cf433a170b53bcf93a130a7f14ccc5235de5560df4f1045eb7f3550b46ebed16d3c5e5
languageName: node
linkType: hard

"typescript@patch:typescript@5.5#~builtin<compat/typescript>":
version: 5.5.2
resolution: "typescript@patch:typescript@npm%3A5.5.2#~builtin<compat/typescript>::version=5.5.2&hash=7ad353"
"typescript@patch:typescript@^5.6.2#~builtin<compat/typescript>":
version: 5.6.2
resolution: "typescript@patch:typescript@npm%3A5.6.2#~builtin<compat/typescript>::version=5.6.2&hash=7ad353"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 6721ac8933a70c252d7b640b345792e103d881811ff660355617c1836526dbb71c2044e2e77a8823fb3570b469f33276875a4cab6d3c4de4ae7d7ee1c3074ae4
checksum: e6c1662e4852e22fe4bbdca471dca3e3edc74f6f1df043135c44a18a7902037023ccb0abdfb754595ca9028df8920f2f8492c00fc3cbb4309079aae8b7de71cd
languageName: node
linkType: hard

Expand Down Expand Up @@ -5635,7 +5635,7 @@ __metadata:
"@types/node": ^20.12.10
octokit: ^3.1.2
rimraf: ^5.0.5
typescript: 5.5
typescript: ^5.6.2
peerDependencies:
typedoc: 0.26.x
languageName: unknown
Expand Down Expand Up @@ -5722,7 +5722,7 @@ __metadata:
"@types/node": ^20.12.10
commander: ^11.1.0
ts-node: ^10.9.1
typescript: 5.5
typescript: ^5.6.2
bin:
workflow-diagrams-generator: dist/index.js
languageName: unknown
Expand Down

0 comments on commit bd4d2fd

Please sign in to comment.