|
| 1 | +import { writeFileSync } from 'node:fs'; |
| 2 | +import { resolve } from 'node:path'; |
| 3 | +import process from 'node:process'; |
| 4 | + |
| 5 | +// 模拟插件生成类型文件的过程 |
| 6 | +async function generateAutoImportTypes() { |
| 7 | + try { |
| 8 | + console.log('🔄 Generating auto-import types...'); |
| 9 | + |
| 10 | + // 创建基本的 auto-import.d.ts 文件内容 |
| 11 | + const autoImportContent = `/* eslint-disable */ |
| 12 | +/* prettier-ignore */ |
| 13 | +// @ts-nocheck |
| 14 | +// noinspection JSUnusedGlobalSymbols |
| 15 | +// Generated by unplugin-auto-import |
| 16 | +// biome-ignore lint: disable |
| 17 | +export {} |
| 18 | +declare global { |
| 19 | + const EffectScope: typeof import('vue')['EffectScope'] |
| 20 | + const computed: typeof import('vue')['computed'] |
| 21 | + const createApp: typeof import('vue')['createApp'] |
| 22 | + const customRef: typeof import('vue')['customRef'] |
| 23 | + const defineAsyncComponent: typeof import('vue')['defineAsyncComponent'] |
| 24 | + const defineComponent: typeof import('vue')['defineComponent'] |
| 25 | + const effectScope: typeof import('vue')['effectScope'] |
| 26 | + const getCurrentInstance: typeof import('vue')['getCurrentInstance'] |
| 27 | + const getCurrentScope: typeof import('vue')['getCurrentScope'] |
| 28 | + const inject: typeof import('vue')['inject'] |
| 29 | + const isProxy: typeof import('vue')['isProxy'] |
| 30 | + const isReactive: typeof import('vue')['isReactive'] |
| 31 | + const isReadonly: typeof import('vue')['isReadonly'] |
| 32 | + const isRef: typeof import('vue')['isRef'] |
| 33 | + const markRaw: typeof import('vue')['markRaw'] |
| 34 | + const nextTick: typeof import('vue')['nextTick'] |
| 35 | + const onActivated: typeof import('vue')['onActivated'] |
| 36 | + const onBeforeMount: typeof import('vue')['onBeforeMount'] |
| 37 | + const onBeforeUnmount: typeof import('vue')['onBeforeUnmount'] |
| 38 | + const onBeforeUpdate: typeof import('vue')['onBeforeUpdate'] |
| 39 | + const onDeactivated: typeof import('vue')['onDeactivated'] |
| 40 | + const onErrorCaptured: typeof import('vue')['onErrorCaptured'] |
| 41 | + const onMounted: typeof import('vue')['onMounted'] |
| 42 | + const onRenderTracked: typeof import('vue')['onRenderTracked'] |
| 43 | + const onRenderTriggered: typeof import('vue')['onRenderTriggered'] |
| 44 | + const onScopeDispose: typeof import('vue')['onScopeDispose'] |
| 45 | + const onServerPrefetch: typeof import('vue')['onServerPrefetch'] |
| 46 | + const onUnmounted: typeof import('vue')['onUnmounted'] |
| 47 | + const onUpdated: typeof import('vue')['onUpdated'] |
| 48 | + const onWatcherCleanup: typeof import('vue')['onWatcherCleanup'] |
| 49 | + const provide: typeof import('vue')['provide'] |
| 50 | + const reactive: typeof import('vue')['reactive'] |
| 51 | + const readonly: typeof import('vue')['readonly'] |
| 52 | + const ref: typeof import('vue')['ref'] |
| 53 | + const resolveComponent: typeof import('vue')['resolveComponent'] |
| 54 | + const shallowReactive: typeof import('vue')['shallowReactive'] |
| 55 | + const shallowReadonly: typeof import('vue')['shallowReadonly'] |
| 56 | + const shallowRef: typeof import('vue')['shallowRef'] |
| 57 | + const toRaw: typeof import('vue')['toRaw'] |
| 58 | + const toRef: typeof import('vue')['toRef'] |
| 59 | + const toRefs: typeof import('vue')['toRefs'] |
| 60 | + const toValue: typeof import('vue')['toValue'] |
| 61 | + const triggerRef: typeof import('vue')['triggerRef'] |
| 62 | + const unref: typeof import('vue')['unref'] |
| 63 | + const useAttrs: typeof import('vue')['useAttrs'] |
| 64 | + const useCssModule: typeof import('vue')['useCssModule'] |
| 65 | + const useCssVars: typeof import('vue')['useCssVars'] |
| 66 | + const useId: typeof import('vue')['useId'] |
| 67 | + const useModel: typeof import('vue')['useModel'] |
| 68 | + const useSlots: typeof import('vue')['useSlots'] |
| 69 | + const useTemplateRef: typeof import('vue')['useTemplateRef'] |
| 70 | + const watch: typeof import('vue')['watch'] |
| 71 | + const watchEffect: typeof import('vue')['watchEffect'] |
| 72 | + const watchPostEffect: typeof import('vue')['watchPostEffect'] |
| 73 | + const watchSyncEffect: typeof import('vue')['watchSyncEffect'] |
| 74 | +} |
| 75 | +// for type re-export |
| 76 | +declare global { |
| 77 | + // @ts-ignore |
| 78 | + export type { Component, Slot, Slots, ComponentPublicInstance, ComputedRef, DirectiveBinding, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, MaybeRef, MaybeRefOrGetter, VNode, WritableComputedRef } from 'vue' |
| 79 | + import('vue') |
| 80 | +} |
| 81 | +
|
| 82 | +// for vue template auto import |
| 83 | +import { UnwrapRef } from 'vue' |
| 84 | +declare module 'vue' { |
| 85 | + interface GlobalComponents {} |
| 86 | + interface ComponentCustomProperties { |
| 87 | + readonly EffectScope: UnwrapRef<typeof import('vue')['EffectScope']> |
| 88 | + readonly computed: UnwrapRef<typeof import('vue')['computed']> |
| 89 | + readonly createApp: UnwrapRef<typeof import('vue')['createApp']> |
| 90 | + readonly customRef: UnwrapRef<typeof import('vue')['customRef']> |
| 91 | + readonly defineAsyncComponent: UnwrapRef<typeof import('vue')['defineAsyncComponent']> |
| 92 | + readonly defineComponent: UnwrapRef<typeof import('vue')['defineComponent']> |
| 93 | + readonly effectScope: UnwrapRef<typeof import('vue')['effectScope']> |
| 94 | + readonly getCurrentInstance: UnwrapRef<typeof import('vue')['getCurrentInstance']> |
| 95 | + readonly getCurrentScope: UnwrapRef<typeof import('vue')['getCurrentScope']> |
| 96 | + readonly inject: UnwrapRef<typeof import('vue')['inject']> |
| 97 | + readonly isProxy: UnwrapRef<typeof import('vue')['isProxy']> |
| 98 | + readonly isReactive: UnwrapRef<typeof import('vue')['isReactive']> |
| 99 | + readonly isReadonly: UnwrapRef<typeof import('vue')['isReadonly']> |
| 100 | + readonly isRef: UnwrapRef<typeof import('vue')['isRef']> |
| 101 | + readonly markRaw: UnwrapRef<typeof import('vue')['markRaw']> |
| 102 | + readonly nextTick: UnwrapRef<typeof import('vue')['nextTick']> |
| 103 | + readonly onActivated: UnwrapRef<typeof import('vue')['onActivated']> |
| 104 | + readonly onBeforeMount: UnwrapRef<typeof import('vue')['onBeforeMount']> |
| 105 | + readonly onBeforeUnmount: UnwrapRef<typeof import('vue')['onBeforeUnmount']> |
| 106 | + readonly onBeforeUpdate: UnwrapRef<typeof import('vue')['onBeforeUpdate']> |
| 107 | + readonly onDeactivated: UnwrapRef<typeof import('vue')['onDeactivated']> |
| 108 | + readonly onErrorCaptured: UnwrapRef<typeof import('vue')['onErrorCaptured']> |
| 109 | + readonly onMounted: UnwrapRef<typeof import('vue')['onMounted']> |
| 110 | + readonly onRenderTracked: UnwrapRef<typeof import('vue')['onRenderTracked']> |
| 111 | + readonly onRenderTriggered: UnwrapRef<typeof import('vue')['onRenderTriggered']> |
| 112 | + readonly onScopeDispose: UnwrapRef<typeof import('vue')['onScopeDispose']> |
| 113 | + readonly onServerPrefetch: UnwrapRef<typeof import('vue')['onServerPrefetch']> |
| 114 | + readonly onUnmounted: UnwrapRef<typeof import('vue')['onUnmounted']> |
| 115 | + readonly onUpdated: UnwrapRef<typeof import('vue')['onUpdated']> |
| 116 | + readonly onWatcherCleanup: UnwrapRef<typeof import('vue')['onWatcherCleanup']> |
| 117 | + readonly provide: UnwrapRef<typeof import('vue')['provide']> |
| 118 | + readonly reactive: UnwrapRef<typeof import('vue')['reactive']> |
| 119 | + readonly readonly: UnwrapRef<typeof import('vue')['readonly']> |
| 120 | + readonly ref: UnwrapRef<typeof import('vue')['ref']> |
| 121 | + readonly resolveComponent: UnwrapRef<typeof import('vue')['resolveComponent']> |
| 122 | + readonly shallowReactive: UnwrapRef<typeof import('vue')['shallowReactive']> |
| 123 | + readonly shallowReadonly: UnwrapRef<typeof import('vue')['shallowReadonly']> |
| 124 | + readonly shallowRef: UnwrapRef<typeof import('vue')['shallowRef']> |
| 125 | + readonly toRaw: UnwrapRef<typeof import('vue')['toRaw']> |
| 126 | + readonly toRef: UnwrapRef<typeof import('vue')['toRef']> |
| 127 | + readonly toRefs: UnwrapRef<typeof import('vue')['toRefs']> |
| 128 | + readonly toValue: UnwrapRef<typeof import('vue')['toValue']> |
| 129 | + readonly triggerRef: UnwrapRef<typeof import('vue')['triggerRef']> |
| 130 | + readonly unref: UnwrapRef<typeof import('vue')['unref']> |
| 131 | + readonly useAttrs: UnwrapRef<typeof import('vue')['useAttrs']> |
| 132 | + readonly useCssModule: UnwrapRef<typeof import('vue')['useCssModule']> |
| 133 | + readonly useCssVars: UnwrapRef<typeof import('vue')['useCssVars']> |
| 134 | + readonly useId: UnwrapRef<typeof import('vue')['useId']> |
| 135 | + readonly useModel: UnwrapRef<typeof import('vue')['useModel']> |
| 136 | + readonly useSlots: UnwrapRef<typeof import('vue')['useSlots']> |
| 137 | + readonly useTemplateRef: UnwrapRef<typeof import('vue')['useTemplateRef']> |
| 138 | + readonly watch: UnwrapRef<typeof import('vue')['watch']> |
| 139 | + readonly watchEffect: UnwrapRef<typeof import('vue')['watchEffect']> |
| 140 | + readonly watchPostEffect: UnwrapRef<typeof import('vue')['watchPostEffect']> |
| 141 | + readonly watchSyncEffect: UnwrapRef<typeof import('vue')['watchSyncEffect']> |
| 142 | + } |
| 143 | +}`; |
| 144 | + |
| 145 | + // 写入文件 |
| 146 | + const filePath = resolve(process.cwd(), 'src/auto-import.d.ts'); |
| 147 | + writeFileSync(filePath, autoImportContent, 'utf8'); |
| 148 | + |
| 149 | + console.log('✅ Auto-import types generated successfully!'); |
| 150 | + } catch (error) { |
| 151 | + console.error('❌ Failed to generate auto-import types:', error); |
| 152 | + process.exit(1); |
| 153 | + } |
| 154 | +} |
| 155 | + |
| 156 | +generateAutoImportTypes(); |
0 commit comments