-
Notifications
You must be signed in to change notification settings - Fork 2
/
generate.sh
executable file
·111 lines (93 loc) · 3.61 KB
/
generate.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
#!/bin/sh
#define parameters which are passed in.
COMPONENT_NAME=$1
DDS_NAME=$(echo "$COMPONENT_NAME" | gsed -e 's/\(^\|-\)\([a-z]\)/\1\u\2/g')
DDS_NAME=$(echo "$DDS_NAME" | gsed -e 's/-//g')
DDS_NAME_SPACE=$(echo "$DDS_NAME" | gsed -r -e "s/([^A-Z])([A-Z])/\1 \2/g")
DDS_REACT_NAME_SPACE=$(echo "$COMPONENT_NAME" | gsed -e "s/^\(.\)/\U\1/g;s/-/ /g")
COMPONENT_DIR="src/components/$COMPONENT_NAME"
COMPONENT_REACT_DIR="../react/src/components/$DDS_NAME"
STORIES_DIR="$COMPONENT_DIR/__stories__"
STORIES_REACT_DIR="$COMPONENT_REACT_DIR/__stories__"
STYLE_DIR="../styles/scss/components/$COMPONENT_NAME"
SANDBOX_DIR="examples/codesandbox/components/$COMPONENT_NAME"
SANDBOX_REACT_DIR="examples/codesandbox/components-react/$COMPONENT_NAME"
E2E_DIR="tests/e2e/__tests__/$COMPONENT_NAME"
if [ "$3" == "-dev" ]; then
rm -r "$STORIES_DIR"
rm -r "$STYLE_DIR"
rm -r "$SANDBOX_DIR/src"
rm -r "$SANDBOX_REACT_DIR/src"
rm -r "$E2E_DIR"
fi
if [ "$2" == "-wrapper-only" ]; then
mkdir -p "$SANDBOX_REACT_DIR/src"
else
mkdir -p "$STORIES_DIR"
mkdir -p "$STYLE_DIR"
mkdir -p "$SANDBOX_DIR/src"
mkdir -p "$SANDBOX_REACT_DIR/src"
mkdir -p "$E2E_DIR"
fi
if [ ! -d $COMPONENT_REACT_DIR ]; then
mkdir -p "$STORIES_REACT_DIR"
fi
function generate_file() {
eval "cat <<-EOF
$(<./templates/$1.txt)
EOF
" > "$2"
}
function generate_component() {
generate_file "component" "$COMPONENT_DIR/$COMPONENT_NAME.ts"
generate_file "style" "$COMPONENT_DIR/$COMPONENT_NAME.scss"
generate_file "style-origin" "$STYLE_DIR/_$COMPONENT_NAME.scss"
generate_file "index" "$COMPONENT_DIR/index.ts"
}
function generate_stories() {
generate_file "stories" "$STORIES_DIR/$COMPONENT_NAME.stories.ts"
generate_file "readme" "$STORIES_DIR/README.stories.mdx"
}
function generate_e2e() {
generate_file "e2e" "$E2E_DIR/$COMPONENT_NAME.e2e.js"
generate_file "cdn-e2e" "$E2E_DIR/$COMPONENT_NAME.cdn.e2e.js"
}
function generate_sandbox() {
generate_file "sandbox-package" "$SANDBOX_DIR/package.json"
generate_file "sandbox-config" "$SANDBOX_DIR/sandbox.config.json"
generate_file "sandbox-index" "$SANDBOX_DIR/index.html"
generate_file "sandbox-cdn" "$SANDBOX_DIR/cdn.html"
generate_file "sandbox-gitignore" "$SANDBOX_DIR/.gitignore"
generate_file "sandbox-babel" "$SANDBOX_DIR/.babelrc"
generate_file "sandbox-index-js" "$SANDBOX_DIR/src/index.js"
}
function generate_react_wrapper() {
generate_file "stories-react" "$STORIES_DIR/$COMPONENT_NAME.stories.react.tsx"
generate_file "readme-react" "$STORIES_DIR/README.stories.react.mdx"
}
function generate_react_sandbox() {
generate_file "webpack-config" "$SANDBOX_REACT_DIR/webpack.config.js"
generate_file "sandbox-config" "$SANDBOX_REACT_DIR/sandbox.config.json"
generate_file "sandbox-react-package" "$SANDBOX_REACT_DIR/package.json"
generate_file "sandbox-react-index" "$SANDBOX_REACT_DIR/index.html"
generate_file "sandbox-react-gitignore" "$SANDBOX_REACT_DIR/.gitignore"
generate_file "sandbox-react-index-js" "$SANDBOX_REACT_DIR/src/index.js"
generate_file "sandbox-react-index-css" "$SANDBOX_REACT_DIR/src/index.css"
}
function generate_react_placeholder(){
if [ ! -f "$COMPONENT_REACT_DIR/README.stories.mdx" ] || [ ! -f "$STORIES_REACT_DIR/$DDS_NAME.stories.js" ]; then
generate_file "readme-react-placeholder" "$COMPONENT_REACT_DIR/README.stories.mdx"
generate_file "stories-react-placeholder" "$STORIES_REACT_DIR/$DDS_NAME.stories.js"
fi
}
if [ "$2" != '-wrapper-only' ]; then
generate_component
generate_stories
generate_e2e
generate_sandbox
fi
if [ "$2" == '-wrapper' ] || [ "$2" == '-wrapper-only' ]; then
generate_react_wrapper
generate_react_sandbox
fi
generate_react_placeholder