Skip to content

Commit 1eeeb18

Browse files
chenxchholazz
andauthored
chore: update gen script (element-plus#10641)
Co-authored-by: zz <2418184580@qq.com>
1 parent f0439af commit 1eeeb18

File tree

1 file changed

+34
-25
lines changed

1 file changed

+34
-25
lines changed

scripts/gc.sh

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,50 +30,59 @@ mkdir -p "$DIRNAME"
3030
mkdir -p "$DIRNAME/src"
3131
mkdir -p "$DIRNAME/__tests__"
3232

33-
cat > $DIRNAME/src/index.vue <<EOF
33+
cat > $DIRNAME/src/$INPUT_NAME.vue <<EOF
3434
<template>
3535
<div>
36-
<slot></slot>
36+
<slot />
3737
</div>
3838
</template>
39-
<script lang='ts'>
40-
import { defineComponent } from 'vue'
41-
export default defineComponent({
42-
name: 'El${NAME}',
43-
props: { },
44-
setup(props) {
45-
// init here
46-
},
39+
40+
<script lang="ts" setup>
41+
import { ${INPUT_NAME}Props } from './$INPUT_NAME'
42+
43+
defineOptions({
44+
name: 'El$NAME',
4745
})
46+
47+
const props = defineProps(${INPUT_NAME}Props)
48+
49+
// init here
4850
</script>
49-
<style>
50-
</style>
51+
EOF
52+
53+
cat > $DIRNAME/src/$INPUT_NAME.ts <<EOF
54+
import { buildProps } from '@element-plus/utils'
55+
56+
import type { ExtractPropTypes } from 'vue'
57+
import type $NAME from './$INPUT_NAME.vue'
58+
59+
export const ${INPUT_NAME}Props = buildProps({})
60+
61+
export type ${NAME}Props = ExtractPropTypes<typeof ${INPUT_NAME}Props>
62+
export type ${NAME}Instance = InstanceType<typeof $NAME>
5163
EOF
5264

5365
cat <<EOF >"$DIRNAME/index.ts"
54-
import { App } from 'vue'
55-
import ${NAME} from './src/index.vue'
66+
import { withInstall } from '@element-plus/utils'
67+
import $NAME from './src/$INPUT_NAME.vue'
5668
57-
${NAME}.install = (app: App): void => {
58-
app.component(${NAME}.name, ${NAME})
59-
}
69+
export const El$NAME = withInstall($NAME)
70+
export default El$NAME
6071
61-
export default ${NAME}
72+
export * from './src/$INPUT_NAME'
6273
EOF
6374

64-
cat > $DIRNAME/__tests__/$INPUT_NAME.spec.ts <<EOF
75+
cat > $DIRNAME/__tests__/$INPUT_NAME.test.tsx <<EOF
6576
import { mount } from '@vue/test-utils'
66-
import $NAME from '../src/index.vue'
77+
import { describe, expect, test } from 'vitest'
78+
import $NAME from '../src/$INPUT_NAME.vue'
6779
6880
const AXIOM = 'Rem is the best girl'
6981
7082
describe('$NAME.vue', () => {
7183
test('render test', () => {
72-
const wrapper = mount($NAME, {
73-
slots: {
74-
default: AXIOM,
75-
},
76-
})
84+
const wrapper = mount(() => <$NAME>{AXIOM}</$NAME>)
85+
7786
expect(wrapper.text()).toEqual(AXIOM)
7887
})
7988
})

0 commit comments

Comments
 (0)