Last active
March 19, 2024 23:37
-
-
Save j1n3l0/c7293af3fc7a055ad79850a370613db3 to your computer and use it in GitHub Desktop.
Set up a new development typescript project
This file contains 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/bash | |
set -euxo pipefail | |
git init | |
npm init -y | |
npm install -D depcheck eslint eslint-config-prettier eslint-plugin-jsdoc eslint-plugin-json eslint-plugin-prettier husky lint-staged prettier | |
npm pkg set scripts.depcheck='depcheck' | |
npm pkg set scripts.lint-staged='lint-staged --allow-empty' | |
npm pkg set scripts.prepare='husky install' | |
npx husky install | |
npx husky add .husky/pre-commit 'npm run depcheck' | |
npx husky add .husky/pre-commit 'npm run lint-staged' | |
npx husky add .husky/pre-commit 'npm run cover' | |
cat <<EOF | jq -S | tee .lintstagedrc.json | |
{ | |
"*.{json,ts}": "eslint --fix" | |
} | |
EOF | |
cat <<EOF | jq -S | tee .prettierrc.json | |
{ | |
"singleQuote": true | |
} | |
EOF | |
cat <<EOF | jq -S | tee .eslintrc.json | |
{ | |
"extends": [ | |
"eslint:recommended", | |
"plugin:@typescript-eslint/recommended", | |
"plugin:prettier/recommended", | |
"plugin:jsdoc/recommended", | |
"plugin:json/recommended" | |
], | |
"parser": "@typescript-eslint/parser", | |
"plugins": [ | |
"@typescript-eslint" | |
], | |
"rules": { | |
"json/*": ["error", "allowComments"] | |
} | |
} | |
EOF | |
npm install -D typescript ts-node @tsconfig/recommended @types/node @typescript-eslint/eslint-plugin @typescript-eslint/parser | |
cat <<EOF | jq -S | tee tsconfig.json | |
{ | |
"extends": "@tsconfig/recommended" | |
} | |
EOF | |
npm install -D chai mocha nyc @istanbuljs/nyc-config-typescript @types/chai @types/mocha | |
npm pkg set scripts.test='mocha' | |
npm pkg set scripts.cover='nyc npm test' | |
cat <<EOF | jq -S | tee .mocharc.json | |
{ | |
"exclude": [ | |
"**/*.d.ts" | |
], | |
"extensions": [ | |
"ts", | |
"tsx" | |
], | |
"recursive": true, | |
"reporter": "min", | |
"require": [ | |
"ts-node/register/transpile-only", | |
"source-map-support/register" | |
], | |
"spec": [ | |
"test/**/*.spec.*" | |
], | |
"watchFiles": [ | |
"*.json", | |
"src", | |
"test" | |
] | |
} | |
EOF | |
cat <<EOF | jq -S | tee .nycrc.json | |
{ | |
"branches": 100, | |
"check-coverage": true, | |
"extends": "@istanbuljs/nyc-config-typescript", | |
"extension": [ | |
".ts", | |
".tsx" | |
], | |
"functions": 100, | |
"lines": 100, | |
"statements": 10 | |
} | |
EOF | |
npx prettier -w . | |
git add . | |
mkdir -p test | |
cat <<EOF | tee test/replace-me.spec.ts | |
import { expect } from 'chai'; | |
import { describe } from 'mocha'; | |
describe('FIXME: placeholder test', () => { | |
it('should be replaced by real tests', () => { | |
expect(true).to.be.true; | |
}); | |
}); | |
EOF | |
git commit -m 'configure the application' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment