-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.sh
168 lines (150 loc) · 5.08 KB
/
lib.sh
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#! /bin/bash
# variables
# Take User Input for Creating Component or deleting Component
echo "Enter 1 to Atoms"
echo "Enter 2 to Module"
echo "Enter 3 to Organisms"
echo "Enter 4 to Templates"
echo "Enter 5 to Pages"
echo "Enter 6 to Effects"
read choice
Rfce() {
# Write the Component Name
echo "import * as React from 'react';" >>$Path/$1/$1.tsx
echo "import './$1.scss';" >>$Path/$1/$1.tsx
echo "function $1({...props} : any) {" >>$Path/$1/$1.tsx
echo " return ( " >>$Path/$1/$1.tsx
echo " <div {...props}>" >>$Path/$1/$1.tsx
echo " $1" >>$Path/$1/$1.tsx
echo " </div>" >>$Path/$1/$1.tsx
echo " )" >>$Path/$1/$1.tsx
echo "}" >>$Path/$1/$1.tsx
echo "export default $1" >>$Path/$1/$1.tsx
}
index(){
# Write the Component Name
echo "export {default} from './$1';" >>$Path/$1/index.tsx
}
scss() {
echo "@import '../../styles/variable.scss';" >>$Path/$1/$1.scss
}
Story() {
# Write Story For Component
echo "import $1 from './$1';" >>$Path/$1/$1.stories.tsx
echo "import { ComponentStory, ComponentMeta } from '@storybook/react';" >>$Path/$1/$1.stories.tsx
echo "export default { " >>$Path/$1/$1.stories.tsx
echo "title: 'Atoms/$1'," >>$Path/$1/$1.stories.tsx
echo " component: $1," >>$Path/$1/$1.stories.tsx
echo "decorators: [(story) => <div className=\"container\">{story()}</div>]," >>$Path/$1/$1.stories.tsx
echo "} as ComponentMeta<typeof $1>;" >>$Path/$1/$1.stories.tsx
echo "export const Template : ComponentStory<typeof $1> = (args) => <$1 {...args} />;" >>$Path/$1/$1.stories.tsx
}
Test() {
# Test Boilerplate
echo "import { render, screen } from '@testing-library/react';" >>$Path/$1/$1.test.tsx
echo "import { composeStories } from '@storybook/testing-react';" >>$Path/$1/$1.test.tsx
echo "import * as $1Stories from './$1.stories';" >>$Path/$1/$1.test.tsx
echo "const { Template } = composeStories($1Stories);" >>$Path/$1/$1.test.tsx
echo "" >>$Path/$1/$1.test.tsx
echo " it('should render without crashing', () => {" >>$Path/$1/$1.test.tsx
echo " render(<Template/>);" >>$Path/$1/$1.test.tsx
echo " });" >>$Path/$1/$1.test.tsx
}
# if user input is 1 then create component
action() {
if [ "$1" -eq 1 ]; then
echo "Creating Component"
read -p "Enter Component Name: " NAME
if [ -z "$NAME" ]; then
echo "You did not Component Name"
else
# get Path of directory
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# get name of directory
DIR_NAME=$(basename "$DIR")
echo "Component Name: $NAME"
# check if directory exists
DIRECTORY='/home/data'
if [ ! -d "$Path/$NAME" ]; then
mkdir -p $Path/$NAME
touch $Path/$NAME/index.tsx
touch $Path/$NAME/$NAME.scss
touch $Path/$NAME/$NAME.test.tsx
touch $Path/$NAME/$NAME.stories.tsx
# Write in Component Files
Rfce $NAME
Story $NAME
Test $NAME
scss $NAME
index $NAME
# Write in index.tsx
echo "export * from './$NAME';" >>$Path/index.tsx
echo "Component Created"
else
echo "Component Already Exists"
fi
fi
else
echo "Deleting Component"
read -p "Enter Component Name: " NAME
echo "Component Name: $NAME"
rm -rf $Path/$NAME
# Delete in index.tsx
# sed -i "/'./$NAME'/d" $Path/index.tsx // need to fix this
echo "Component Deleted"
fi
}
# Switch Case for Creating Component
case $choice in
1)
Path="src/lib/Atoms"
# Take User Input for Creating Component or deleting Component
echo "Enter 1 to create Component"
echo "Enter 2 to delete Component"
read InputChoise
action $InputChoise
;;
2)
Path="src/lib/Module"
# Take User Input for Creating Component or deleting Component
echo "Enter 1 to create Module"
echo "Enter 2 to delete Moduleent"
read InputChoise
action $InputChoise
;;
3)
Path="src/lib/Organisms"
# Take User Input for Creating Component or deleting Component
echo "Enter 1 to create Organisms"
echo "Enter 2 to delete Organisms"
read InputChoise
action $InputChoise
;;
4)
Path="src/lib/Templates"
# Take User Input for Creating Component or deleting Component
echo "Enter 1 to create Templates"
echo "Enter 2 to delete Templates"
read InputChoise
action $InputChoise
;;
5)
Path="src/lib/Pages"
# Take User Input for Creating Component or deleting Component
echo "Enter 1 to create Pages"
echo "Enter 2 to delete Pagesnent"
read InputChoise
action $InputChoise
;;
6)
Path="src/lib/Effects"
# Take User Input for Creating Component or deleting Component
echo "Enter 1 to create Effects"
echo "Enter 2 to delete Effects"
read InputChoise
action $InputChoise
;;
*)
echo "Invalid Input"
;;
esac