-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-page.bash
executable file
·143 lines (109 loc) · 4.1 KB
/
create-page.bash
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
#!/bin/bash
# Clear the screen
clear
# Read the page name from the user input
echo -n "Enter page name (CamelCase): "
read page_name
if [ -z "$page_name" ]; then
echo "Page name is required"
exit 1
fi
# Transform the first letter of the page name to uppercase
page_name=$(echo $page_name | tr '[:lower:]' '[:upper:]' | cut -c1)$(echo $page_name | cut -c2-)
# Transform the page name to lowercase
page_name_lower=$(echo $page_name | tr '[:upper:]' '[:lower:]')
# Transform the name to caterpillar-case
page_name_caterpillar=$(echo $page_name | sed -r 's/([a-z0-9])([A-Z])/\1-\2/g' | tr '[:upper:]' '[:lower:]')
# Transform the name to snake_case
page_name_snake=$(echo $page_name | sed -r 's/([a-z0-9])([A-Z])/\1-\2/g' | tr '[:upper:]' '[:lower:]' | tr '_' '-')
# Read the description of the page from the user input
echo -n "Enter page description: "
read page_description
if [ -z "$page_description" ]; then
echo "Page description is required"
exit 1
fi
# Read if the page requires locale files
echo -n "Does the page require locale files? (y/n): "
read page_locale
if [ -z "$page_locale" ]; then
echo "Page locale is required"
exit 1
fi
# Check whether the page_locale is y or n
if [ "$page_locale" != "y" ] && [ "$page_locale" != "n" ]; then
echo "Page locale must be y or n"
exit 1
fi
# Check if the page directory already exists
if [ -d "src/pages/$page_name" ]; then
echo "Page already exists. Please choose a different page name."
exit 1
fi
# Create the page directory
mkdir "src/pages/$page_name"
# Create the page files
touch "src/pages/$page_name/index.js"
touch "src/pages/$page_name/$page_name.jsx"
touch "src/pages/$page_name/$page_name_caterpillar.scss"
# Add the page to the page index file
echo "export * from \"./$page_name.jsx\";" >> "src/pages/$page_name/index.js"
# Add the page to the page group index file
echo "export * from \"./$page_name\";" >> "src/pages/index.js"
# Create the page locale files if page_locale is y
if [ "$page_locale" == "y" ]; then
mkdir "src/pages/$page_name/locales"
touch "src/pages/$page_name/locales/en.json"
echo "{}" >> "src/pages/$page_name/locales/en.json"
touch "src/pages/$page_name/locales/kk.json"
echo "{}" >> "src/pages/$page_name/locales/kk.json"
touch "src/pages/$page_name/locales/ru.json"
echo "{}" >> "src/pages/$page_name/locales/ru.json"
touch "src/pages/$page_name/locales/uk.json"
echo "{}" >> "src/pages/$page_name/locales/uk.json"
touch "src/pages/$page_name/locales/pl.json"
echo "{}" >> "src/pages/$page_name/locales/pl.json"
touch "src/pages/$page_name/locales.js"
echo "export * as en from \"./locales/en.json\";" >> "src/pages/$page_name/locales.js"
echo "export * as kk from \"./locales/kk.json\";" >> "src/pages/$page_name/locales.js"
echo "export * as ru from \"./locales/ru.json\";" >> "src/pages/$page_name/locales.js"
echo "export * as uk from \"./locales/uk.json\";" >> "src/pages/$page_name/locales.js"
echo "export * as pl from \"./locales/pl.json\";" >> "src/pages/$page_name/locales.js"
echo "export * as $page_name from './$page_name/locales.js';" >> "src/pages/locales.js"
fi
# Add the page to the main page file
echo "import React from 'react';
`
if [ "$page_locale" == "y" ]; then
echo "import { useTranslation } from 'react-i18next';" >> "src/pages/$page_name/$page_name.jsx"
fi
`
import { Page } from '#blocks';
import './$page_name_caterpillar.scss';
/**
* $page_name
*
* $page_description
*
* @returns {JSX.Element}
*/
export const $page_name = () => {
`
if [ "$page_locale" = "y" ]; then
echo "const { t } = useTranslation('$page_name_lower-page')"
fi
`
return (
<Page classes='page__$page_name_snake'>
$page_name Page
</Page>
);
}; " >> "src/pages/$page_name/$page_name.jsx"
# Add the theme to the page styles file
echo "/* $page_name styles */
@import '@USupport-components-library/styles';
.page__$page_name_caterpillar{
}
" >> "src/pages/$page_name/$page_name_caterpillar.scss"
# Outout to the user's console
echo "Successfully created $page_name into src/pages/$page_name"