From f23e4b294e2c59bcf9cbc3bc4f174a6a21212ec3 Mon Sep 17 00:00:00 2001 From: qiang Date: Mon, 4 Nov 2024 21:19:29 +0800 Subject: [PATCH] chore: gen script does not support hyphens (#18704) * chore: gen script does not support hyphens * chore: optimize regular matching * chore: optimize regular matching * chore: updata template * feat: generate style files * chore: add instance --- scripts/gc.sh | 53 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/scripts/gc.sh b/scripts/gc.sh index b9c86deb85..785c681f8f 100755 --- a/scripts/gc.sh +++ b/scripts/gc.sh @@ -1,13 +1,13 @@ #! /bin/bash -NAME=$1 +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 gc \${name} with no space" + echo "Usage: pnpm gen \${name} with no space" exit 1 fi @@ -19,15 +19,12 @@ if [ -d "$DIRNAME" ]; then 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 +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 < $DIRNAME/src/$INPUT_NAME.vue < @@ -54,22 +52,30 @@ 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 < export type ${NAME}Instance = InstanceType 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 = withInstall($NAME) +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 < { }) }) EOF + +cat > $DIRNAME/style/index.ts < $DIRNAME/style/css.ts < $FILE_PATH/theme-chalk/src/$INPUT_NAME.scss <