Skip to content

Instantly share code, notes, and snippets.

@nibble-4bits
Last active July 15, 2021 19:00
Show Gist options
  • Save nibble-4bits/ced1b5fa5a9ac4891f8e642de75a4214 to your computer and use it in GitHub Desktop.
Save nibble-4bits/ced1b5fa5a9ac4891f8e642de75a4214 to your computer and use it in GitHub Desktop.
Bash script to scaffold a Node Typescript project + ESLint + Prettier, in VS Code
#!/usr/bin/env bash
create_package_json() {
cat << EOF > package.json
{
"name": "",
"version": "1.0.0",
"description": "",
"main": "build/main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "npm run build && node build/main.js",
"build": "npx tsc",
"prettier": "prettier --write src/**/*.ts",
"lint": "eslint src/**/*.ts",
"lint:fix": "eslint src/**/*.ts --fix"
},
"keywords": [],
"author": "",
"license": "ISC"
}
EOF
}
install_typescript_eslint_prettier() {
npm install -D \
@tsconfig/node14 \
@types/node \
@typescript-eslint/eslint-plugin \
@typescript-eslint/parser \
eslint \
eslint-config-prettier \
eslint-plugin-prettier \
prettier \
typescript
}
create_tsconfig() {
cat << EOF > tsconfig.json
{
"extends": "@tsconfig/node14/tsconfig.json",
"compileOnSave": true,
"compilerOptions": {
"outDir": "build",
"lib": ["ES2020"]
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
}
EOF
}
create_eslint_config() {
cat << EOF > .eslintrc.json
{
"env": {
"es2021": true,
"node": true
},
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended", "prettier"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": ["@typescript-eslint", "prettier"],
"rules": {
"prettier/prettier": "error",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-non-null-assertion": "off"
}
}
EOF
cat << EOF > .eslintignore
build/
EOF
}
create_prettier_config() {
cat << EOF > .prettierrc
{
"printWidth": 120,
"semi": true,
"singleQuote": true,
"trailingComma": "es5",
"endOfLine": "lf"
}
EOF
cat << EOF > .prettierignore
build/
EOF
}
create_gitignore() {
cat << EOF > .gitignore
node_modules/
build/
EOF
}
create_project_settings() {
mkdir .vscode
cat << EOF > .vscode/settings.json
{
"editor.formatOnSave": true,
"eslint.validate": ["typescript"],
"eslint.alwaysShowStatus": true,
"files.eol": "\n"
}
EOF
}
init_src() {
mkdir src
cat << EOF > src/main.ts
console.log("It's working!");
EOF
}
init_repo() {
git init
git add .
git commit -m "Initial commit"
}
create_package_json
install_typescript_eslint_prettier
create_tsconfig
create_eslint_config
create_prettier_config
create_gitignore
create_project_settings
init_src
init_repo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment