Last active
March 16, 2021 22:43
-
-
Save stedman/fcc16cde140314c86c8219df4871ed15 to your computer and use it in GitHub Desktop.
Set up common Node projects with npm, ESLint (Airbnb config), Prettier, EditorConfig, and .gitignore. Note that all files are saved in user directory (`~/`).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://editorconfig.org | |
root = true | |
[*] | |
end_of_line = lf | |
insert_final_newline = true | |
indent_size = 2 | |
indent_style = space | |
trim_trailing_whitespace = true | |
[*.{js,jsx,ts,tsx}] | |
curly_bracket_next_line = false | |
indent_brace_style = BSD KNF | |
quote_type = single | |
spaces_around_brackets = inside | |
spaces_around_operators = true | |
[*.{js,py}] | |
# Set default charset | |
charset = utf-8 | |
[*.md] | |
trim_trailing_whitespace = false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# OS generated # | |
#--------------------# | |
.DS_Store | |
# IDE-generated | |
#--------------------# | |
# App-generated | |
#--------------------# | |
node_modules |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"printWidth": 100, | |
"tabWidth": 2, | |
"tabs": false, | |
"semi": true, | |
"singleQuote": true, | |
"quoteProps": "as-needed", | |
"trailingCommas": "none", | |
"bracketSpacing": true, | |
"arrowParens": "avoid" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
echo "=========================" | |
echo "π§° Project Initializer π§°" | |
echo "=========================" | |
echo " π· This script bootstraps typical" | |
echo " Node project format and lint tools." | |
echo | |
echo "-----------------------" | |
echo "π§° Checking for existing Node packages..." | |
if [ -f package.json ]; then | |
echo " β Node packages already installed." | |
else | |
echo " π· No pre-existing packages. Installing npm packages..." | |
echo | |
# TODO: offer choice of Yarn | |
npm init -y | |
echo " β Node packages installed." | |
fi | |
echo | |
echo "-----------------------" | |
echo "π§° Checking for existing ESLint config..." | |
if [ -f .eslintrc.json ]; then | |
echo " β ESLint config already installed." | |
else | |
echo " πΆ No pre-existing config..." | |
echo " β Do you want to install ESLint (Airbnb config)? (Y|n)" | |
read eslint | |
if [[ $eslint != n ]]; then | |
echo " π· ESLint config reference: https://www.npmjs.com/package/eslint-config-airbnb" | |
echo | |
echo " β Which ESLint variant would you like to install? (1|2) 1=base (default), 2=react." | |
read eslint | |
if [[ $eslint != 2 ]]; then | |
echo " π· Installing ESLint base version..." | |
echo | |
# TODO: offer choice of Yarn | |
npx install-peerdeps --dev eslint-config-airbnb-base | |
echo "{\n \"extends\": \"airbnb-base\"\n}" >> ./.eslintrc.json | |
echo " β Airbnb ESLint base config installed." | |
else | |
echo " π· Installing ESLint React version." | |
echo | |
# TODO: offer choice of Yarn | |
npx install-peerdeps --dev eslint-config-airbnb | |
echo "{\n \"extends\": \"airbnb\"\n}" >> ./.eslintrc.json | |
echo " β Airbnb ESLint React config installed." | |
fi | |
else | |
echo " β Skipping ESLint install." | |
fi | |
fi | |
echo | |
echo "-----------------------" | |
echo "π§° Checking for existing Prettier config..." | |
if [ -f .prettierrc.json ]; then | |
echo " β Prettier config already installed." | |
else | |
echo " πΆ No pre-existing config..." | |
echo " β Do you want to install Prettier? (Y|n)" | |
read prettier | |
if [[ $prettier != n ]]; then | |
echo " π· Installing Prettier..." | |
echo | |
# TODO: offer choice of Yarn | |
npm install --save-dev --save-exact prettier | |
cp ~/.prettierrc.json ./ | |
echo " β Prettier installed." | |
else | |
echo " β Skipping Prettier install." | |
fi | |
fi | |
echo | |
echo "-----------------------" | |
echo "π§° Checking for existing other configs." | |
echo | |
if [ ! -f .editorconfig ]; then | |
cp ~/.editorconfig ./ | |
echo " β EditorConfig added." | |
echo | |
fi | |
if [ ! -f .gitignore ]; then | |
cp ~/.gitignore ./ | |
echo " β GitIgnore added." | |
echo | |
fi | |
echo | |
echo "==============================" | |
echo "π§° Project Initializer DONE π§°" | |
echo "==============================" | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Install
Copy files to your User directory (
~/
).Usage
sh ~/.init-node-project.sh