element-plus/scripts/gc.sh

90 lines
1.9 KiB
Bash
Raw Normal View History

#! /bin/bash
2020-07-22 21:33:14 +08:00
NAME=$1
2020-07-22 21:33:14 +08:00
FILE_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")/../packages" && pwd)
re="[[:space:]]+"
if [ "$#" -ne 1 ] || [[ $NAME =~ $re ]] || [ "$NAME" == "" ]; then
echo "Usage: pnpm gc \${name} with no space"
exit 1
fi
DIRNAME="$FILE_PATH/components/$NAME"
2020-07-22 21:33:14 +08:00
INPUT_NAME=$NAME
if [ -d "$DIRNAME" ]; then
echo "$NAME component already exists, please change it"
exit 1
fi
NORMALIZED_NAME=""
for i in $(echo $NAME | sed 's/[_|-]\([a-z]\)/\ \1/;s/^\([a-z]\)/\ \1/'); do
C=$(echo "${i:0:1}" | tr "[:lower:]" "[:upper:]")
NORMALIZED_NAME="$NORMALIZED_NAME${C}${i:1}"
done
NAME=$NORMALIZED_NAME
2020-07-24 19:28:18 +08:00
mkdir -p "$DIRNAME"
mkdir -p "$DIRNAME/src"
mkdir -p "$DIRNAME/__tests__"
cat > $DIRNAME/src/$INPUT_NAME.vue <<EOF
2020-07-24 19:28:18 +08:00
<template>
<div>
<slot />
2020-07-24 19:28:18 +08:00
</div>
</template>
<script lang="ts" setup>
import { ${INPUT_NAME}Props } from './$INPUT_NAME'
defineOptions({
name: 'El$NAME',
})
const props = defineProps(${INPUT_NAME}Props)
// init here
2020-07-24 19:28:18 +08:00
</script>
EOF
cat > $DIRNAME/src/$INPUT_NAME.ts <<EOF
import { buildProps } from '@element-plus/utils'
import type { ExtractPropTypes } from 'vue'
import type $NAME from './$INPUT_NAME.vue'
export const ${INPUT_NAME}Props = buildProps({})
export type ${NAME}Props = ExtractPropTypes<typeof ${INPUT_NAME}Props>
export type ${NAME}Instance = InstanceType<typeof $NAME>
2020-07-24 19:28:18 +08:00
EOF
cat <<EOF >"$DIRNAME/index.ts"
import { withInstall } from '@element-plus/utils'
import $NAME from './src/$INPUT_NAME.vue'
export const El$NAME = withInstall($NAME)
export default El$NAME
export * from './src/$INPUT_NAME'
2020-07-24 19:28:18 +08:00
EOF
cat > $DIRNAME/__tests__/$INPUT_NAME.test.tsx <<EOF
import { mount } from '@vue/test-utils'
import { describe, expect, test } from 'vitest'
import $NAME from '../src/$INPUT_NAME.vue'
2020-07-24 19:28:18 +08:00
const AXIOM = 'Rem is the best girl'
describe('$NAME.vue', () => {
test('render test', () => {
const wrapper = mount(() => <$NAME>{AXIOM}</$NAME>)
expect(wrapper.text()).toEqual(AXIOM)
2020-07-24 19:28:18 +08:00
})
})
EOF