-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
115 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const { getAllVueComponentMetadata, getPropType, isRequiredProp } = require('./lib/metadata') | ||
const { getAllVueComponentMetadata, getPropType, isRequiredProp, getMethodSignature } = require('./lib/metadata') | ||
const cheetahGrid = require('cheetah-grid') | ||
const { EVENT_TYPE } = cheetahGrid.ListGrid | ||
const vue3Emits = Object.keys(EVENT_TYPE) | ||
|
@@ -25,21 +25,34 @@ async function main () { | |
${camelCase(prop.name)}${isRequiredProp(prop) ? '' : '?'}: ${normalizePropType(prop)}; | ||
`.trim() | ||
}) | ||
const methods = component.methods | ||
.filter(method => method.visibility === 'public') | ||
.map(method => { | ||
return ` | ||
/** ${method.description} */ | ||
${method.name}: ${getMethodSignature(method)}; | ||
`.trim() | ||
}) | ||
const emits = Object.keys(vue3Emits).map(emitName => { | ||
return ` | ||
on${pascalCase(emitName)}?: Function; | ||
`.trim() | ||
}) | ||
componentTypes.push(` | ||
/** ${component.description} */ | ||
export type ${componentName} = GlobalComponentConstructor<{ | ||
${indent([...props, ...emits].join('\n'), 2)} | ||
}>; | ||
export const ${componentName}: ComponentConstructor< | ||
{ | ||
${indent([...props, ...emits].join('\n'), 4)} | ||
}, | ||
{ | ||
${indent(methods.join('\n'), 4)} | ||
} | ||
>; | ||
`.trim()) | ||
components.push(` | ||
/** ${component.description} */ | ||
${componentName}: ${componentName}; | ||
"${kebabCase(componentName)}": ${componentName}; | ||
${componentName}: typeof ${componentName}; | ||
"${kebabCase(componentName)}": typeof ${componentName}; | ||
`.trim()) | ||
} | ||
|
||
|
@@ -49,25 +62,14 @@ ${componentName}: ${componentName}; | |
fs.mkdirSync(typeDir) | ||
} | ||
fs.writeFileSync(typePath, `${` | ||
import { VNodeProps, AllowedComponentProps, ComponentCustomProps } from "@vue/runtime-core"; | ||
import { PublicProps } from "vue"; | ||
export * as cheetahGrid from 'cheetah-grid' | ||
// type VueInstance = ComponentPublicInstance | ||
/* @see https://unpkg.com/browse/[email protected]/dist/types/ts-helpers.d.ts */ | ||
// https://github.com/vuejs/vue-next/blob/d84d5ecdbdf709570122175d6565bb61fae877f2/packages/runtime-core/src/apiDefineComponent.ts#L29-L31 | ||
// TODO: This can be imported from vue directly once this PR gets merged: https://github.com/vuejs/vue-next/pull/2403 | ||
type PublicProps = VNodeProps & AllowedComponentProps & ComponentCustomProps; | ||
// Can't use \`DefineComponent\` because of the false prop inferring behavior, it doesn't pick up the required types when an interface is passed | ||
// This PR will probably solve the problem as it moves the prop inferring behavior to \`defineComponent\` function: https://github.com/vuejs/vue-next/pull/4465 | ||
// GlobalComponentConstructor helper is kind of like the ComponentConstructor type helper, but simpler and keeps the Volar errors simpler, | ||
// and also similar to the usage in official Vue packages: https://github.com/vuejs/vue-next/blob/d84d5ecdbdf709570122175d6565bb61fae877f2/packages/runtime-core/src/components/BaseTransition.ts#L258-L264 or https://github.com/vuejs/vue-router-next/blob/5dd5f47515186ce34efb9118dda5aad0bb773439/src/RouterView.ts#L160-L172 etc. | ||
// TODO: This can be replaced with \`DefineComponent\` once this PR gets merged: https://github.com/vuejs/vue-next/pull/4465 | ||
type GlobalComponentConstructor<Props = {}, Slots = {}> = { | ||
type ComponentConstructor<Props = {}, Methods = {}, Slots = {}> = { | ||
new (): { | ||
$props: PublicProps & Props | ||
$slots: Slots | ||
} | ||
} & Methods | ||
} | ||
${componentTypes.join('\n')} | ||
|