-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredux-cli
189 lines (139 loc) · 3.45 KB
/
redux-cli
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/bin/bash
set -e
createComponent() {
FILENAME="$1"
FILENAME=`echo ${FILENAME:0:1} | tr '[a-z]' '[A-Z]'`${FILENAME:1}
cat > "$FILENAME".js <<EOF
import React, { Component, PropTypes } from 'react';
class $FILENAME extends Component {
render() {
return (
<div> content </div>
);
}
}
$FILENAME.propTypes = {
};
export default "$FILENAME";
EOF
return 0
}
createCSSComponent() {
FILENAME="$1"
FILENAME=`echo ${FILENAME:0:1} | tr '[a-z]' '[A-Z]'`${FILENAME:1}
cat > "$FILENAME".js <<EOF
import React, { Component, PropTypes } from 'react';
import styles from './$FILENAME.scss';
@cssModules(styles)
class $FILENAME extends Component {
render() {
return (
<div> content </div>
);
}
}
$FILENAME.propTypes = {
};
export default "$FILENAME";
EOF
echo '' > $FILENAME.scss
return 0
}
createContainer() {
FILENAME="$1"
FILENAME=`echo ${FILENAME:0:1} | tr '[a-z]' '[A-Z]'`${FILENAME:1}
cat > index.js <<EOF
import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
@cssModules(styles)
class $FILENAME extends Component {
render() {
return (
<div> content </div>
);
}
}
$FILENAME.propTypes = {
};
function mapStateToProps(state) {
return {
};
}
export default connect(mapStateToProps)($FILENAME);
EOF
return 0
}
createFolderAndMove() {
FILENAME="$1"
FILENAME=`echo ${FILENAME:0:1} | tr '[a-z]' '[A-Z]'`${FILENAME:1}
mkdir $FILENAME
mv $FILENAME.* $FILENAME
}
createFolderAndIndex() {
FILENAME="$1"
FILENAME=`echo ${FILENAME:0:1} | tr '[a-z]' '[A-Z]'`${FILENAME:1}
mkdir $FILENAME
mv index.js $FILENAME
}
if [ "$1" = "new" ]; then
if [ "$2" = "" ]; then
echo '--- ELEMENT not specified'
echo '--- Usage: ./redux-cli new dumbcomponent'
exit 0
fi
TYPE="$2"
if [ "$TYPE" = "filecomponent" ]; then
if [ "$3" = "" ]; then
echo '--- NAME not specified'
echo '--- Usage: ./redux-cli new filecomponent "filename"'
exit 0
fi
FILENAME="$3"
createComponent $FILENAME
if [ "$4" = "folder" ]; then
createFolderAndMove $FILENAME
fi
exit 0
fi
#--------------------------------------------------------------
if [ "$TYPE" = "filecomponentcss" ]; then
if [ "$3" = "" ]; then
echo '--- NAME not specified'
echo '--- Usage: ./redux-cli new filecomponentcss "filename"'
exit 0
fi
FILENAME="$3"
createCSSComponent $FILENAME
if [ "$4" = "folder" ]; then
createFolderAndMove $3
fi
exit 0
fi
if [ "$TYPE" = "container" ]; then
if [ "$3" = "" ]; then
echo '--- NAME not specified'
echo '--- Usage: ./redux-cli new filecomponentcss "filename"'
exit 0
fi
FILENAME="$3"
createContainer $FILENAME
createFolderAndIndex $3
exit 0
fi
#--------------------------------
fi
if [ "$1" = "" ]; then
echo "==========================================================================="
echo 'Redux cli commands:'
echo ""
echo "Create file component"
echo "Usage: ./redux-cli new filecomponent <filename>"
echo "Create file component in folder"
echo "Usage: ./redux-cli new filecomponent <filename> folder"
echo "Create file component with css"
echo "Usage: ./redux-cli new filecomponentcss <filename>"
echo "Create file component with css and folder"
echo "Usage: ./redux-cli new filecomponentcss <filename> folder"
echo "Create a container"
echo "Usage: ./redux-cli new container <foldername>"
fi