improve intellisense
This commit is contained in:
parent
ac412b798c
commit
6a5addb383
15 changed files with 39393 additions and 483 deletions
|
|
@ -6,32 +6,47 @@ function toCamelCase(str: string) {
|
|||
return str.replace(/[-_]\w/g, m => m[1].toUpperCase())
|
||||
}
|
||||
|
||||
const type: string[] = []
|
||||
const $$namespace: string[] = []
|
||||
const intelliSense: string[] = [
|
||||
'import { Type as T } from "../enums/Type.js"\n',
|
||||
"export type Namespace = keyof IntelliSense;",
|
||||
"export type Element<T extends Namespace> = IntelliSense[T]",
|
||||
"export type VanillaType<T extends Namespace, K extends Element<T>> = IntelliSense[T][K]\n",
|
||||
"export type IntelliSense = {",
|
||||
]
|
||||
|
||||
const intelliSense: string[] = ['import * as mc from "./elements.js"\n', "export type IntelliSense = {"]
|
||||
const intelliSenseTypeEachNamespace: string[] = []
|
||||
|
||||
const paths: string[] = ["export const paths = {"]
|
||||
|
||||
for (const [namespace, element] of Object.entries(data)) {
|
||||
if (namespace === "undefined") continue
|
||||
$$namespace.push(`"${namespace}"`)
|
||||
const $namespace = toCamelCase("_" + namespace)
|
||||
|
||||
const eType: string[] = []
|
||||
const eType: string[] = [],
|
||||
eType3: string[] = [`export type ${$namespace}Type = {`],
|
||||
ePaths: string[] = [` "${namespace}": {`]
|
||||
|
||||
for (const [ePath, info] of Object.entries(<any>element)) {
|
||||
const { file, type, extend } = <any>info
|
||||
eType.push(`"${ePath}"`)
|
||||
eType3.push(` "${ePath}": T.${type.toUpperCase()},`)
|
||||
ePaths.push(` "${ePath}": "${file}",`)
|
||||
}
|
||||
|
||||
intelliSense.push(` "${namespace}": mc.${$namespace},`)
|
||||
eType3.push("}\n")
|
||||
ePaths.push(" },")
|
||||
|
||||
type.push(`export type ${$namespace} = ${eType.join(" | ")};`)
|
||||
paths.push(ePaths.join("\n"))
|
||||
intelliSense.push(` "${namespace}": ${$namespace}Type,`)
|
||||
intelliSenseTypeEachNamespace.push(eType3.join("\n"))
|
||||
}
|
||||
|
||||
intelliSense.push("}")
|
||||
|
||||
fs.writeFileSync(
|
||||
"src/types/vanilla/elements.ts",
|
||||
`export type Namespace = ${$$namespace.join(" | ")}\n\n` + type.join("\n"),
|
||||
)
|
||||
paths.push("}")
|
||||
|
||||
fs.writeFileSync("src/types/vanilla/intellisense.ts", intelliSense.join("\n"))
|
||||
fs.writeFileSync(
|
||||
"src/types/vanilla/intellisense.ts",
|
||||
intelliSense.join("\n") + "\n\n" + intelliSenseTypeEachNamespace.join("\n"),
|
||||
)
|
||||
fs.writeFileSync("src/types/vanilla/paths.ts", paths.join("\n"))
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
export {} // 👈 BẮT BUỘC
|
||||
export {}
|
||||
|
||||
declare global {
|
||||
interface String {
|
||||
|
|
|
|||
|
|
@ -35,6 +35,10 @@ for (const key in schema) {
|
|||
}
|
||||
}
|
||||
|
||||
if (enumName === "Type") {
|
||||
fileData.push(` UNKNOWN = "unknown",`)
|
||||
}
|
||||
|
||||
fileData.push("}")
|
||||
|
||||
fs.writeFile(`${enumPath}${enumName}.ts`, fileData.join("\n"))
|
||||
|
|
|
|||
Reference in a new issue