2020-07-22 21:15:18 +08:00
|
|
|
#! /bin/bash
|
|
|
|
|
2020-07-22 21:33:14 +08:00
|
|
|
NAME=$1
|
2020-07-22 21:15:18 +08:00
|
|
|
|
2020-07-22 21:33:14 +08:00
|
|
|
FILE_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")/../packages" && pwd)
|
2020-07-22 21:15:18 +08:00
|
|
|
|
|
|
|
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
|
2020-07-22 21:15:18 +08:00
|
|
|
|
|
|
|
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>
|
2020-07-29 15:09:29 +08:00
|
|
|
<slot></slot>
|
2020-07-24 19:28:18 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script lang='ts'>
|
2020-07-29 15:09:29 +08:00
|
|
|
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
|
2020-07-22 21:15:18 +08:00
|
|
|
|
2020-07-24 20:23:14 +08:00
|
|
|
cat <<EOF >"$DIRNAME/index.ts"
|
2020-07-24 19:28:18 +08:00
|
|
|
import { App } from 'vue'
|
|
|
|
import ${NAME} from './src/index.vue'
|
2020-07-29 15:09:29 +08:00
|
|
|
export default (app: App): void => {
|
2020-07-24 19:28:18 +08:00
|
|
|
app.component(${NAME}.name, ${NAME})
|
2020-07-22 21:15:18 +08:00
|
|
|
}
|
2020-07-24 19:28:18 +08:00
|
|
|
EOF
|
2020-07-22 21:15:18 +08:00
|
|
|
|
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
|
2020-07-29 15:09:29 +08:00
|
|
|
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', () => {
|
2020-07-27 16:17:23 +08:00
|
|
|
const wrapper = mount($NAME, {
|
2020-07-24 19:28:18 +08:00
|
|
|
slots: {
|
2020-07-29 15:09:29 +08:00
|
|
|
default: AXIOM,
|
2020-07-24 19:28:18 +08:00
|
|
|
},
|
|
|
|
})
|
2020-07-27 16:17:23 +08:00
|
|
|
expect(wrapper.text()).toEqual(AXIOM)
|
2020-07-24 19:28:18 +08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
EOF
|
2020-07-24 20:23:14 +08:00
|
|
|
|
|
|
|
cat <<EOF >"$DIRNAME/doc/index.stories.ts"
|
|
|
|
import El${NAME} from '../index'
|
|
|
|
|
|
|
|
export default {
|
2020-07-29 15:09:29 +08:00
|
|
|
title: '${NAME}',
|
2020-07-24 19:20:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
EOF
|