#! /bin/bash NAME=$1 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" 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 mkdir -p "$DIRNAME" mkdir -p "$DIRNAME/src" mkdir -p "$DIRNAME/__tests__" cat > $DIRNAME/src/$INPUT_NAME.vue <
EOF cat > $DIRNAME/src/$INPUT_NAME.ts < export type ${NAME}Instance = InstanceType EOF cat <"$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' EOF cat > $DIRNAME/__tests__/$INPUT_NAME.test.tsx < { test('render test', () => { const wrapper = mount(() => <$NAME>{AXIOM}) expect(wrapper.text()).toEqual(AXIOM) }) }) EOF