docs-util: fixes following packages reorg (#9326)
- 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
This commit is contained in:
@@ -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[]
|
||||
@@ -50,7 +51,7 @@ abstract class AbstractGenerator {
|
||||
)
|
||||
})
|
||||
|
||||
this.program = ts.createProgram(files, {})
|
||||
this.program = ts.createProgram(files, this.getBaseCompilerOptions())
|
||||
|
||||
this.checker = this.program.getTypeChecker()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user