-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate-modal.bash
executable file
·106 lines (81 loc) · 2.87 KB
/
create-modal.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
#!/bin/bash
# Clear the screen
clear
# Read the modal name from the user input
echo -n "Enter modal name (CamelCase): "
read modal_name
if [ -z "$modal_name" ]; then
echo "Modal name is required"
exit 1
fi
# Transform the first letter of the modal name to uppercase
modal_name=$(echo $modal_name | tr '[:lower:]' '[:upper:]' | cut -c1)$(echo $modal_name | cut -c2-)
# Transform the modal name to lowercase
modal_name_lower=$(echo $modal_name | tr '[:upper:]' '[:lower:]')
# Transform the name to caterpillar-case
modal_name_kebab=$(echo $modal_name | sed -r 's/([a-z0-9])([A-Z])/\1-\2/g' | tr '[:upper:]' '[:lower:]')
# Create the description of the modal
modal_description="The $modal_name modal"
# Read if the modal requires locale files
echo -n "Does the modal require locale files? (y/n): "
read modal_locale
if [ -z "$modal_locale" ]; then
echo "Modal locale is required"
exit 1
fi
# Check whether the modal_locale is y or n
if [ "$modal_locale" != "y" ] && [ "$modal_locale" != "n" ]; then
echo "Modal locale must be y or n"
exit 1
fi
# Check if the modal directory already exists
if [ -d "src/modals/$modal_name" ]; then
echo "Modal already exists. Please choose a different modal name."
exit 1
fi
# Create the modal directory
mkdir "src/modals/$modal_name"
# Create the modal files
touch "src/modals/$modal_name/index.js"
touch "src/modals/$modal_name/$modal_name.jsx"
touch "src/modals/$modal_name/$modal_name_kebab.scss"
# Add the modal to the modal index file
echo "export * from './$modal_name.jsx';" >> "src/modals/$modal_name/index.js"
# Add the modal to the modal group index file
echo "export * from './$modal_name';" >> "src/modals/index.js"
# Create the locale file if modal_locales is y
if [ "$modal_locale" == "y" ]; then
mkdir "src/modals/$modal_name/locales"
touch "src/modals/$modal_name/locales/en.json"
echo "{}" >> "src/modals/$modal_name/locales/en.json"
touch "src/modals/$modal_name/locales.js"
echo "export * as en from './locales/en.json';" >> "src/modals/$modal_name/locales.js"
echo "export * as $modal_name from './$modal_name/locales.js';" >> "src/modals/locales.js"
fi
# Add the modal to the main modal file
echo "import React from 'react';
import { Modal } from '@USupport-components-library/src';
import './$modal_name_kebab.scss';
/**
* $modal_name
*
* $modal_description
*
* @return {jsx}
*/
export const $modal_name = ({ isOpen, onClose }) => {
return (
<Modal
classes='$modal_name_kebab'
heading='$modal_name'
isOpen={isOpen}
closeModal={onClose}
></Modal>
);
};" >> "src/modals/$modal_name/$modal_name.jsx"
# Add the theme to the modal styles file
echo "@import '@USupport-components-library/styles';
.$modal_name_kebab{
}" >> "src/modals/$modal_name/$modal_name_kebab.scss"
# Output to the user's console
echo "Successfully created $modal_name into src/modals/$modal_name"