-
Notifications
You must be signed in to change notification settings - Fork 2
/
ash-install.sh
111 lines (92 loc) · 3.51 KB
/
ash-install.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
#!/usr/bin/env sh
# ---------------------------------------------------------------------------------------
# Configuration
# https://raw.githubusercontent.com/mirego/elixir-boilerplate/master/boilerplate-setup.sh
# https://github.com/mirego/elixir-boilerplate/blob/master/LICENSE.md
# ---------------------------------------------------------------------------------------
pascalCaseBefore="AshServer"
snakeCaseBefore="ash_server"
kebabCaseBefore="ash-server"
# The identifiers above will be replaced in the content of the files found below
content=$(find . -type f \( \
-name "*.ex" -or \
-name "*.exs" -or \
-name "*.ees" -or \
-name "*.sh" -or \
-name "*.json" -or \
-name "*.js" -or \
-name "*.yml" -or \
-name "*.md" -or \
-name ".env.*" -or \
-name "Dockerfile" -or \
-name "Makefile" \
\) \
-and ! -path "./ash-install.sh" \
-and ! -path "./_build/*" \
-and ! -path "./deps/*" \
)
# The identifiers above will be replaced in the path of the files and directories found here
paths=$(find . -depth 2 \( \
-path "./lib/${snakeCaseBefore}*" -or \
-path "./lib/${snakeCaseBefore}_*" -or \
-path "./lib/${snakeCaseBefore}.*" -or \
-path "./test/${snakeCaseBefore}" -or \
-path "./test/${snakeCaseBefore}_*" \
\))
# -----------------------------------------------------------------------------
# Validation
# -----------------------------------------------------------------------------
if [[ -z "$1" ]] ; then
echo 'You must specify your project name in PascalCase as first argument.'
exit 0
fi
pascalCaseAfter=$1
snakeCaseAfter=$(echo $pascalCaseAfter | /usr/bin/sed 's/\(.\)\([A-Z]\)/\1_\2/g' | tr '[:upper:]' '[:lower:]')
kebabCaseAfter=$(echo $snakeCaseAfter | tr '_' '-')
# -----------------------------------------------------------------------------
# Helper functions
# -----------------------------------------------------------------------------
header() {
echo "\033[0;33m▶ $1\033[0m"
}
success() {
echo "\033[0;32m▶ $1\033[0m"
}
run() {
echo ${@}
eval "${@}"
}
# -----------------------------------------------------------------------------
# Execution
# -----------------------------------------------------------------------------
header "Configuration"
echo "${pascalCaseBefore} → ${pascalCaseAfter}"
echo "${snakeCaseBefore} → ${snakeCaseAfter}"
echo "${kebabCaseBefore} → ${kebabCaseAfter}"
echo ""
header "Replacing boilerplate identifiers in content"
for file in $content; do
run /usr/bin/sed -i "''" "s/$snakeCaseBefore/$snakeCaseAfter/g" $file
run /usr/bin/sed -i "''" "s/$kebabCaseBefore/$kebabCaseAfter/g" $file
run /usr/bin/sed -i "''" "s/$pascalCaseBefore/$pascalCaseAfter/g" $file
done
success "Done!\n"
header "Replacing boilerplate identifiers in file and directory paths"
for path in $paths; do
run mv $path $(echo $path | /usr/bin/sed "s/$snakeCaseBefore/$snakeCaseAfter/g" | /usr/bin/sed "s/$kebabCaseBefore/$kebabCaseAfter/g" | /usr/bin/sed "s/$pascalCaseBefore/$pascalCaseAfter/g")
done
success "Done!\n"
# header "Removing boilerplate license → https://choosealicense.com"
# run rm -fr LICENSE.md
# success "Done!\n"
# header "Removing boilerplate changelog"
# run rm -fr CHANGELOG.md
# success "Done!\n"
# header "Removing boilerplate code of conduct and contribution information → https://help.github.com/articles/setting-guidelines-for-repository-contributors/"
# run rm -fr CODE_OF_CONDUCT.md CONTRIBUTING.md
# success "Done!\n"
header "Removing boilerplate script"
run rm -fr ash-create-test.sh
run rm -fr ash-run-test.shs
run rm -fr ash-install.sh
success "Done!\n"