element-plus/scripts/gc.sh

102 lines
1.9 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"
2020-07-24 19:44:48 +08:00
mkdir -p "$DIRNAME/doc"
2020-07-24 19:28:18 +08:00
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 scoped>
</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'
export default (app: App): void => {
2020-07-24 19:28:18 +08:00
app.component(${NAME}.name, ${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": {
2020-08-23 22:04:02 +08:00
"vue": "^3.0.0-rc.7"
2020-07-24 19:28:18 +08:00
},
"devDependencies": {
"@vue/test-utils": "^2.0.0-beta.0"
}
}
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
cat <<EOF >"$DIRNAME/doc/index.stories.ts"
import El${NAME} from '../index'
export default {
title: '${NAME}',
}
EOF