element-plus/scripts/gc.sh

95 lines
1.8 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: yarn gc \${name} with no space"
exit 1
fi
DIRNAME="$FILE_PATH/$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/index.vue <<EOF
<template>
<div>
<slot></slot>
2020-07-24 19:28:18 +08:00
</div>
</template>
<script lang='ts'>
import { defineComponent } from 'vue'
export default defineComponent({
name: 'El${NAME}',
props: { },
setup(props) {
// init here
},
})
2020-07-24 19:28:18 +08:00
</script>
<style>
2020-07-24 19:28:18 +08:00
</style>
EOF
cat <<EOF >"$DIRNAME/index.ts"
2020-07-24 19:28:18 +08:00
import { App } from 'vue'
import ${NAME} from './src/index.vue'
${NAME}.install = (app: App): void => {
2020-07-24 19:28:18 +08:00
app.component(${NAME}.name, ${NAME})
}
export default ${NAME}
2020-07-24 19:28:18 +08:00
EOF
2020-07-24 19:28:18 +08:00
cat > $DIRNAME/package.json <<EOF
{
"name": "@element-plus/$INPUT_NAME",
"version": "0.0.0",
"main": "dist/index.js",
"license": "MIT",
"peerDependencies": {
"vue": "3.1.1"
2020-07-24 19:28:18 +08:00
},
"devDependencies": {
2020-08-29 23:24:10 +08:00
"@vue/test-utils": "^2.0.0-beta.3"
2020-07-24 19:28:18 +08:00
}
}
EOF
cat > $DIRNAME/__tests__/$INPUT_NAME.spec.ts <<EOF
import { mount } from '@vue/test-utils'
2020-07-24 19:28:18 +08:00
import $NAME from '../src/index.vue'
const AXIOM = 'Rem is the best girl'
describe('$NAME.vue', () => {
test('render test', () => {
const wrapper = mount($NAME, {
2020-07-24 19:28:18 +08:00
slots: {
default: AXIOM,
2020-07-24 19:28:18 +08:00
},
})
expect(wrapper.text()).toEqual(AXIOM)
2020-07-24 19:28:18 +08:00
})
})
EOF