Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/template-generator #14

Merged
merged 2 commits into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"scripts": {
"dev": "vite",
"build": "vite build",
"cz": "npx git-cz"
"cz": "npx git-cz",
"gc": "sh ./scripts/gc.sh"
},
"dependencies": {
"vue": "^3.0.0-rc.1",
Expand Down
65 changes: 65 additions & 0 deletions scripts/gc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#! /bin/bash

export NAME=$1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need export here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, not at all.


export FILE_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")/../packages" && pwd)

re="[[:space:]]+"

if [ "$#" -ne 1 ] || [[ $NAME =~ $re ]] || [ "$NAME" == "" ]; then
echo "Usage: yarn gc \${name} with no space"
exit 1
fi

DIRNAME="$FILE_PATH/$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

TEMPLATE_INDEX_VUE="<template>\n
<div>\n
</div>\n
</template>\n
<script lang='ts'>\n
export default {\n
NAME: 'El${NAME}',\n
props: {\n
},\n
setup(props,ctx) { }\n
};\n
</script>\n
<style>\n
</style>\n
"

TEMPLATE_INDEX_TS="\n
import { App } from 'vue'\n
import ${NAME} from './src/index.vue'\n
export default (app: App) => {\n
app.component(${NAME}.name, ${NAME})\n
}
"
TEMPLATE_PKG_JSON="\n
{\n
\"name\": \"eleplus-${NAME}\",\n
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should use @element-plus/name

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

\"description\": \"\",\n
\"version\": \"0.1.0\",\n
\"main\": \"./index.ts\",\n
\"license\": \"MIT\",\n
\"dependencies\": {}\n
}\n
"

mkdir -p "$DIRNAME"
mkdir -p "$DIRNAME/src"
echo $TEMPLATE_INDEX_VUE >>"$DIRNAME/src/index.vue"
echo $TEMPLATE_INDEX_TS >>"$DIRNAME/index.ts"
echo $TEMPLATE_PKG_JSON >>"$DIRNAME/package.json"