Skip to content

Instantly share code, notes, and snippets.

@stedman
Last active March 16, 2021 22:43
Show Gist options
  • Save stedman/fcc16cde140314c86c8219df4871ed15 to your computer and use it in GitHub Desktop.
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 (`~/`).
# 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
# OS generated #
#--------------------#
.DS_Store
# IDE-generated
#--------------------#
# App-generated
#--------------------#
node_modules
{
"printWidth": 100,
"tabWidth": 2,
"tabs": false,
"semi": true,
"singleQuote": true,
"quoteProps": "as-needed",
"trailingCommas": "none",
"bracketSpacing": true,
"arrowParens": "avoid"
}
#!/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
@stedman
Copy link
Author

stedman commented Mar 16, 2021

Install

Copy files to your User directory (~/).

Usage

  1. from the command line, enter
    sh ~/.init-node-project.sh
  2. follow the prompts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment