#! /bin/bash NAME=$(echo $1 | sed -E "s/([A-Z])/-\1/g" | sed -E "s/^-//g" | sed -E "s/_/-/g" | tr "A-Z" "a-z") FILE_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")/../packages" && pwd) re="[[:space:]]+" if [ "$#" -ne 1 ] || [[ $NAME =~ $re ]] || [ "$NAME" == "" ]; then echo "Usage: pnpm gen \${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 NAME=$(echo $NAME | awk -F'-' '{ for(i=1; i<=NF; i++) { $i = toupper(substr($i,1,1)) tolower(substr($i,2)) } print $0 }' OFS='') PROP_NAME=$(echo "${NAME:0:1}" | tr '[:upper:]' '[:lower:]')${NAME:1} mkdir -p "$DIRNAME" mkdir -p "$DIRNAME/src" mkdir -p "$DIRNAME/style" mkdir -p "$DIRNAME/__tests__" cat > $DIRNAME/src/$INPUT_NAME.vue <
EOF cat > $DIRNAME/src/$INPUT_NAME.ts < export const ${PROP_NAME}Emits = {} export type ${NAME}Emits = typeof ${PROP_NAME}Emits EOF cat > $DIRNAME/src/instance.ts < EOF cat <"$DIRNAME/index.ts" import { withInstall } from '@element-plus/utils' import $NAME from './src/$INPUT_NAME.vue' import type { SFCWithInstall } from '@element-plus/utils' export const El$NAME: SFCWithInstall = withInstall($NAME) export default El$NAME export * from './src/$INPUT_NAME' export type { ${NAME}Instance } from './src/instance' EOF cat > $DIRNAME/__tests__/$INPUT_NAME.test.tsx < { test('render test', () => { const wrapper = mount(() => <$NAME>{AXIOM}) expect(wrapper.text()).toEqual(AXIOM) }) }) EOF cat > $DIRNAME/style/index.ts < $DIRNAME/style/css.ts < $FILE_PATH/theme-chalk/src/$INPUT_NAME.scss <