-
Notifications
You must be signed in to change notification settings - Fork 0
/
spine_cli_installer_1.0.0.sh
executable file
·170 lines (153 loc) · 4 KB
/
spine_cli_installer_1.0.0.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
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
#!/bin/bash
#
# @fatherbrennan
#
# Set Spine CLI environment
#
set_spine()
{
mkdir -p ~/.spine/bin/ || exit 1
cat > ~/.spine/bin/spine <<'EOF'
#! /bin/bash
########################################################################
# Spine CLI
########################################################################
#
# @fatherbrennan
#
SPINE_VERSION=1.0.0
SPINE_ENV='Framework/.env'
# Text Properties
TEXT_RESET='\u001b[0m'
TEXT_BOLD='\u001b[1m'
TEXT_UNDERLINE='\u001b[4m'
#
# Throw exception
#
# ?{$1} specific error
# ?{$2} description line 1 (commonly command usage)
# ?{$3} description line 2
#
throw_invalid_exception() {
local invalid='Invalid command: '
[ -z "$1" ] || msg+=("<<${1}>>\n")
[ -z "$2" ] || msg+=("${2}\n")
[ -z "$3" ] || msg+=("${3}\n")
printf '%b' "$invalid" "${msg[@]}" && exit 1
}
#
# Print command usage
#
usage() {
printf 'Usage: spine <command> <extension>'
}
#
# Print command help
#
show_help() {
printf "${TEXT_BOLD}spine${TEXT_RESET}\n $(usage)\n\n${TEXT_UNDERLINE}commands${TEXT_RESET}\n\n ${TEXT_BOLD}dev, start${TEXT_RESET}\n\tbuild app assets in dev mode\n\n ${TEXT_BOLD}clear${TEXT_RESET}\n\tclear the framework cache including assets\n\n ${TEXT_BOLD}open${TEXT_RESET}\n\topen the app in the default web browser\n\n ${TEXT_BOLD}-h, --help${TEXT_RESET}\n\tdisplay command info\n\n ${TEXT_BOLD}-v, --version${TEXT_RESET}\n\tdisplay version info\n\n${TEXT_UNDERLINE}extensions${TEXT_RESET}\n\n ${TEXT_BOLD}-s, --script${TEXT_RESET}\n\textends [ start ] [ dev ]\n\t run config SCRIPT_TAIL after spine build process\n\n${TEXT_UNDERLINE}examples${TEXT_RESET}\n\n ${TEXT_BOLD}spine dev --script${TEXT_RESET}\n\trun dev build process and then run config defined script\n\twhere SCRIPT_TAIL=\"npm dev\". Can be used within framework\n\tenvironments such as the Electron framework\n\n ${TEXT_BOLD}spine open${TEXT_RESET}\n\topen the Public/index.html file using the machine's\n\tdefault web browser"
}
#
# Print help redirect
#
show_help_redirect() {
printf '%s' "Use 'spine --help' for command information"
}
#
# Print version
#
show_version() {
printf '%s' "$SPINE_VERSION"
}
# Exit if no args
[ -z "$1" ] && throw_invalid_exception 'Empty Argument' " $(usage)"
#
# Handle command arguments
#
case "$1" in
-h | --help)
show_help && exit 0
;;
-v | --version)
show_version && exit 0
;;
esac
# Imports
[ -f "$SPINE_ENV" ] && source "$SPINE_ENV" || throw_invalid_exception 'Missing Spinebash Environment'
source "$CONFIG"
# Get relative path
app="$(pwd)/"
#
# Handle command arguments (environment exclusive)
#
case "$1" in
dev | start)
shift
EXTENSION=''
if [ -n "$1" ]
then
case "$1" in
-s | --script) EXTENSION="$SCRIPT_TAIL" ;;
*) throw_invalid_exception "'${1}' is not a valid extension" " $(usage)" "$(show_help_redirect)" ;;
esac
fi
"$SPINE_DEV" "$app" && [ -n "$EXTENSION" ] && $EXTENSION
;;
clear)
"$SPINE_CLEAR" && exit 0
;;
open)
# OS check
a=$(uname -s)
b=$(pwd)
case "$a" in
Linux*)
cmd='xdg-open'
;;
Darwin*)
cmd='open'
;;
CYGWIN*)
cmd='cmd.exe /C start'
;;
MINGW*)
cmd='start'
b=$(pwd -W)
;;
*)
printf '%s' "UNKNOWN MACHINE: ${a}"
;;
esac
# Open homepage in default browser
"$cmd" "file://${b}/Public/index.html" && exit 0
;;
*)
throw_invalid_exception 'Invalid Argument' " $(usage)" "$(show_help_redirect)"
;;
esac
EOF
chmod 777 ~/.spine/bin/spine
}
#
# Add spine path variable and source environments
#
add()
{
local a='PATH=~/.spine/bin:$PATH'
if [ -f ~/"$1" ]
then
if [ "$(grep $a ~/$1 | wc -c)" -eq 0 ]
then
printf '%s\n' "$a" >>~/"$1"
fi
else
printf '%s\n' "$a" >~/"$1"
fi
source ~/"$1"
}
# Add to .bashrc file
set_spine && add '.bashrc' || exit 1
# Add to .zshrc file shell exists on machine
type zsh &>/dev/null && add '.zshrc' || exit 1
printf '%s' 'Spine CLI install successful'
exit 0