-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·124 lines (110 loc) · 4.15 KB
/
setup.sh
File metadata and controls
executable file
·124 lines (110 loc) · 4.15 KB
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
#!/usr/bin/env bash
# Bold
BRed='\033[1;31m' # Red
BGreen='\033[1;32m' # Green
BYellow='\033[1;33m' # Yellow
BPurple='\033[1;35m' # Purple
verify_jq_linux() {
if [ $(dpkg-query -W -f='${Status}' jq 2>/dev/null | grep -c "ok installed") -eq 0 ]; then
echo -e "${BYellow}Installing jq ..."
sudo apt-get install jq -y
fi
}
verify_jq_mac_os() {
if brew list jq &>/dev/null; then
echo "jq is already installed"
else
brew install jq && echo "jq is installed"
fi
}
verify_jq_windows() {
IS_CHOCO="$(choco -v)"
if [ "$IS_CHOCO" == "" ]; then
echo -e "\n"
echo -e "${BRed}Seems Chocolatey is not installed, installing now following: ${BYellow}https://chocolatey.org/install${BYellow}"
echo -e "${BRed}After that, run ${BGreen}choco install jq${BGreen} ${BRed}to continue installing the dependencies ..."
echo -e "${BRed}Run this installation again after it has been installed"
exit 1
fi
}
verify_os_is_running() {
# Verify that system os is running script
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) verify_jq_linux ;;
Darwin*) verify_jq_mac_os ;;
CYGWIN*) verify_jq_windows ;;
MINGW*) verify_jq_windows ;;
*) echo -e "${BRed}UNKNOWN:${unameOut}" && exit 1 ;;
esac
}
verify_package_json_exists() {
if [ -f "package.json" ]; then
echo -e "\n"
echo -e "${BGreen}This is a valid Node project"
else
echo -e "${BRed}package.json does not found, please run this script in the root of your Node project"
exit 1
fi
}
install_dependencies() {
echo -e "\n"
echo -e "${BPurple}Installing following depecies as dev ..."
echo -e "${BGreen}@commitlint/cli @commitlint/config-conventional @rocketseat/eslint-config commitizen eslint husky prettier"
npm i @commitlint/cli @commitlint/config-conventional @rocketseat/eslint-config commitizen eslint husky prettier -D
}
update_package_json() {
echo -e "\n"
echo -e "${BPurple}Adding script in your package.json ..."
echo "$(jq '.scripts += {"prepare": "husky install"}' package.json)" >package.json
echo "$(jq '.scripts += {"commit": "git-cz"}' package.json)" >package.json
echo "$(jq '.scripts += {"lint": "eslint src --ext .tsx,.ts"}' package.json)" >package.json
echo "$(jq '.scripts += {"lint:fix": "npm run lint -- --fix"}' package.json)" >package.json
echo "$(jq '.["lint-staged"] += { "**/*": "prettier --write --ignore-unknown", "src/**": "npm run lint:fix" }' package.json)" >package.json
echo "$(jq '.config += { "commitizen": {"path": "./node_modules/cz-conventional-changelog" } }' package.json)" >package.json
echo -e "${BGreen}Scripts has been addded!"
}
add_lint_files() {
echo -e "\n"
echo -e "${BPurple}Add lint config files ..."
echo "module.exports = { extends: ['@commitlint/config-conventional'] }" >commitlint.config.js
echo '{ "extends": ["@rocketseat/eslint-config/react"] }' >.eslintrc.json
echo -e "node_modules\nsrc/**/*.css" >.eslintignore
echo -e '{
"arrowParens": "always",
"bracketSpacing": true,
"htmlWhitespaceSensitivity": "ignore",
"insertPragma": false,
"jsxSingleQuote": false,
"printWidth": 80,
"proseWrap": "always",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all",
"useTabs": false,
"vueIndentScriptAndStyle": false,
"embeddedLanguageFormatting": "off",
"endOfLine": "auto"
}' >.prettierrc.json
echo -e 'node_modules\nbuild\ndist' >.prettierignore
echo -e "${BGreen}Lint files has been addded!"
}
setup_husky() {
echo -e "\n"
echo -e "${BPurple}Initiallizing husky ..."
npm run prepare
npx husky add .husky/pre-commit "npx lint-staged"
npx husky add .husky/commit-msg 'npx commitlint --edit'
echo -e "${BGreen}husky has been configured successfully!"
}
echo -e "${BPurple}Initiallizing configuration ..."
verify_os_is_running
verify_package_json_exists
install_dependencies
update_package_json
add_lint_files
setup_husky
echo -e "${BYellow}Trying to run command 'git add .' and 'npm run commit' to check configuration"