Skip to content

Instantly share code, notes, and snippets.

@pingcheng
Last active September 27, 2023 12:13
Show Gist options
  • Save pingcheng/11f23e340a5a038d2342df0c2440aca2 to your computer and use it in GitHub Desktop.
Save pingcheng/11f23e340a5a038d2342df0c2440aca2 to your computer and use it in GitHub Desktop.
Create TypeScript codes with ESLint + Prettier + Nodemon for auto reload
# install ts
npm i typescript --save-dev
npx tsc --init
# update ts config
sed -i '' -e 's/"target": "es2016"/"target": "ES2020"/' tsconfig.json
sed -i '' -e 's/\/\/ "noImplicitAny": true/"noImplicitAny": true/' tsconfig.json
sed -i '' -e 's/\/\/ "strictNullChecks": true/"strictNullChecks": true/' tsconfig.json
# install prettier
npm install --save-dev prettier
# add prettier config
cat << 'EOF' > .prettierrc
{
"semi": true,
"singleQuote": false,
}
EOF
# eslint
npm install eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-config-prettier --save-dev
# add config
cat << 'EOF' > .eslintrc
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"],
"env": {
"browser": true,
"es2021": true
}
}
EOF
# setup nodemon
npm install --save-dev ts-node nodemon
cat << 'EOF' > nodemon.json
{
"watch": ["src"],
"ext": "ts,json",
"ignore": ["src/**/*.spec.ts"],
"exec": "ts-node ./src/index.ts"
}
EOF
# add the entry ts file
mkdir src
cat << 'EOF' > src/index.ts
console.log('TypeScript is running and being watched');
EOF
# set git
git init
cat << 'EOF' > ./.gitignore
.idea
node_modules
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment