install.sh 5.83 KB
Newer Older
1 2 3
#!/bin/bash

echo -e "\n"
4 5 6 7 8 9 10 11 12
echo -e " \033[33m  ███████╗ ██████╗  ██████╗\033[0m"
echo -e " \033[33m  ██╔════╝██╔════╝ ██╔════╝\033[0m"
echo -e " \033[33m  ███████╗██║  ███╗██║     \033[0m"
echo -e " \033[33m  ╚════██║██║   ██║██║     \033[0m"
echo -e " \033[33m  ███████║╚██████╔╝╚██████╗\033[0m"
echo -e " \033[33m  ╚══════╝ ╚═════╝  ╚═════╝\033[0m\n"

. ./sgc-core/core/version.conf

13 14 15
echo -e "  \033[103m\033[30m                           \033[0m"
echo -e "  \033[103m\033[30m       Welcome to the      \033[0m"
echo -e "  \033[103m\033[30m sgalinski CLI Task Runner \033[0m"
Philipp Nowinski's avatar
Philipp Nowinski committed
16
echo -e "  \033[103m\033[30m          \033[1mv${SGC_VERSION}           \033[0m"
17
echo -e "  \033[103m\033[30m                           \033[0m"
18 19 20 21
echo -e "\n"

echo -e "\033[0;32mWelcome to the sgalinski CLI.\033[0m"

22
if [ ! -e ./sgc-core ]
23
then
24 25 26
	echo -e "\n\e[41m\e[97m Error: \e[49m"
	echo -e "\033[0;31m Wrong directory! Call this script from the directory that contains the sgc-core folder!\033[0m";
	echo -e "\033[0;31m This is usually your project root directory.\033[0m\n";
27 28 29 30 31
	exit 1;
fi

echo -e "\033[0;32mSetup is in progress...\033[0m\n"

32
cd ./sgc-core
33

34
if [ $OSTYPE == "msys" ]
35
then
36
	# nvm installation on windows cannot be automated
37
	if [ -z `which nvm` > /dev/null ]
38
	then
39 40 41
		echo -e "\n\e[41m\e[97m Error: \e[49m"
		echo -e "\033[0;31m You need to install the Node Version Manager for Windows before you can proceed with the installation.\033[0m"
		echo -e "\033[0;31m  ==> https://github.com/coreybutler/nvm-windows\033[0m\n"
42 43 44
		exit 1;
	fi
else
45 46
	# check for nvm and install it if not present
	echo -e "\033[0;32mSetup Node Version Manager...\033[0m\n"
47
	./core/installers/nvm.sh > /dev/null
48
	echo -e "\033[0;32mNVM installed ✓\033[0m\n"
49
	# include nvm
50
	unset NVM_IOJS_ORG_MIRROR NVM_NODEJS_ORG_MIRROR
51
	. ~/.nvm/nvm.sh
52 53 54 55 56 57 58 59 60 61
	# check if nvm should be updated
	if ! nvm --version | grep -q '0.33.11'
	then
		echo -e "\033[0;32mUpdate to NVM 0.33.11 ✓\033[0m\n"
		(
			cd "$NVM_DIR"
			git fetch --tags origin
			git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)`
		) && \. "$NVM_DIR/nvm.sh"
	fi
62
fi
63 64 65

# include version config
. ./core/node.sh
66
echo -e "\033[0;34mInstall Node ${nodeversion}...\033[0m\n"
67 68 69 70

# set node version
nvm install ${nodeversion}

71 72 73
# nvm-windows won't set the version by default after installing it
if [ $OSTYPE == "msys" ]
then
74
	nvm use --delete-prefix ${nodeversion}
75 76
fi

77 78 79 80 81
echo -e "\033[0;32mNode installed ✓\033[0m\n"

# install node deps
echo -e "\033[0;34mInstall dependencies\033[0m";
rm -rf ./node_modules
82

83
npm set progress=false
84 85
# hacky, yes. comment remove th /dev/null thing if you need to debug
npm ci --prefer-offline --no-audit &> /dev/null
86
npm set progress=true
87 88
echo -e "\033[0;32mDependencies installed ✓\033[0m\n"

89 90 91 92 93
if [ "$1" == "--local" ]; then
	# install cli locally
	echo -e "\033[0;34mInstall sgc\033[0m";
	cp ./core/sgc ../sgc
else
94
	if [ -z `which sgc` > /dev/null ]
95
	then
96 97 98 99
		# install cli globally
		echo -e "\033[0;34mInstall sgc\033[0m";

		if [ $OSTYPE == "msys" ]
100
		then
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
			cp ./core/sgc /c/Windows/System32
		else
			echo -e "\033[0;34mYou need to grant permission in order to install the sgc command\033[0m";
			if [ ! -e /usr/local/bin ]
			then
				sudo mkdir -p /usr/local/bin
			fi
			sudo cp ./core/sgc /usr/local/bin
			if [ -e /etc/bash_completion.d ]
			then
				# linux autocompletion path
				sudo cp ./core/autocompletion.sh /etc/bash_completion.d/sgc
				autocompletePath="/etc/bash_completion.d/sgc"
			elif [ -e /usr/local/etc/bash_completion.d ]
			then
				# osx autocompletion path; if bash completion is installed
				sudo cp ./core/autocompletion.sh /usr/local/etc/bash_completion.d/sgc
				autocompletePath="/usr/local/etc/bash_completion.d/sgc"
			fi
120
		fi
121 122
	else
		echo -e "\033[0;32msgc is already installed globally ✓\033[0m\n"
123
	fi
124
fi
125 126 127 128 129

# store current version number
. ./core/version.conf
echo "INSTALLED_SGC_VERSION=$SGC_VERSION" > .sgc_version

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
if [ ! -e ../.sgc-config.json ]
then
	echo -e "\033[33mNo .sgc-config.json file found.\033[0m";
	echo -e "\033[33mDo you want me to create an example config-file? [Y/N]\033[0m";
	read -n 1 -r
	echo # move to a new line
	if [[ $REPLY =~ ^[Yy]$ ]]
	then
		cp ./core/installers/example-sgc-config.json ../.sgc-config.json
	fi
	echo -e "\033[0;32mCreated .sgc-config.json ✓\033[0m\n"
fi

if [ ! -e ../.stylelintrc ]
then
	echo -e "\033[33mNo .stylelintrc file found.\033[0m";
	echo -e "\033[33mDo you want to use the sgalinski default configuration? [Y/N]\033[0m";
	read -n 1 -r
	echo # move to a new line
	if [[ $REPLY =~ ^[Yy]$ ]]
	then
		curl -s https://gitlab.sgalinski.de/snippets/29/raw >> ../.stylelintrc
	fi
	echo -e "\033[0;32mCreated .stylelintrc ✓\033[0m\n"
fi

if [ ! -e ../.eslintrc.js ]
then
	echo -e "\033[33mNo .eslintrc.js file found.\033[0m";
	echo -e "\033[33mDo you want to use the sgalinski default configuration? [Y/N]\033[0m";
	read -n 1 -r
	echo # move to a new line
	if [[ $REPLY =~ ^[Yy]$ ]]
	then
		curl -s https://gitlab.sgalinski.de/snippets/28/raw >> ../.eslintrc.js
	fi
	echo -e "\033[0;32mCreated .eslintrc.js ✓\033[0m\n"
fi
168

169 170 171 172 173 174
# go back to the root folder
cd ..
echo -e "\033[0;32msgc installed ✓\033[0m\n"
echo -e "\033[0;32mYou can now use the 'sgc' command inside your project root.\033[0m\n"
echo -e "\033[0;32mRestart your shell in order to activate the autocompletion feature.\033[0m\n";

175
if [[ $SHELL == *"zsh"* && "$1" != "--local" ]]
176 177 178 179 180 181
then
	echo -e "\033[0;34mIt seems like you are using zsh.\033[0m";
	echo -e "\033[0;34mYou might want to put these lines in your .zshrc-file to enable sgc autocompletion\033[0m";

	echo -e "\n\tautoload bashcompinit";
	echo -e "\tbashcompinit";
182
	echo -e "\t. $autocompletePath\n"
183
fi