forked from element-plus/element-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgc.sh
More file actions
executable file
·89 lines (76 loc) · 1.68 KB
/
gc.sh
File metadata and controls
executable file
·89 lines (76 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#! /bin/bash
NAME=$1
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"
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
mkdir -p "$DIRNAME"
mkdir -p "$DIRNAME/src"
mkdir -p "$DIRNAME/__tests__"
cat > $DIRNAME/src/index.vue <<EOF
<template>
<div>
<slot/>
</div>
</template>
<script lang='ts'>
export default {
NAME: 'El${NAME}',
props: {
},
setup(props,ctx) { }
};
</script>
<style scoped>
</style>
EOF
cat > $DIRNAME/index.ts <<EOF
import { App } from 'vue'
import ${NAME} from './src/index.vue'
export default (app: App) => {
app.component(${NAME}.name, ${NAME})
}
EOF
cat > $DIRNAME/package.json <<EOF
{
"name": "@element-plus/$INPUT_NAME",
"version": "0.0.0",
"main": "dist/index.js",
"license": "MIT",
"peerDependencies": {
"vue": "^3.0.0-rc.1"
},
"devDependencies": {
"@vue/test-utils": "^2.0.0-beta.0"
}
}
EOF
cat > $DIRNAME/__tests__/$INPUT_NAME.spec.ts <<EOF
import {mount} from '@vue/test-utils'
import $NAME from '../src/index.vue'
const AXIOM = 'Rem is the best girl'
describe('$NAME.vue', () => {
test('render test', () => {
const instance = mount($NAME, {
slots: {
default: AXIOM
},
})
expect(instance.text()).toEqual(AXIOM)
})
})
EOF