This guide provides the necessary steps to set up the project, install required tools, and configure your Visual Studio Code (VSCode) editor to ensure consistency in code formatting and linting.
-
Visual Studio Code: Make sure you have VSCode installed.
-
Node.js: Install Node.js and NPM.
-
Yarn: Install Yarn.
-
TypeScript Compiler: Install globally by running the following command:
yarn global add typescript
-
TypeScript Node Extension: Install globally by running the following command:
yarn global add ts-node
-
Clone the Repository
git clone https://github.com/danganhphu/design-pattern-tsc.git cd design-pattern-tsc
-
Install Dependencies
Run the following command to install the necessary dependencies:
yarn install
-
VSCode Extensions: Install the following VSCode extensions (if using VSCode):
-
Create VSCode Settings (if using VSCode)
If you are using VSCode, create a
.vscode
folder in the root of your project and add asettings.json
file with the following content:mkdir -p .vscode echo '{ "editor.formatOnPaste": true, "editor.formatOnSave": true, "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.codeActionsOnSave": { "source.fixAll.eslint": true, "source.fixAll.format": true } }' > .vscode/settings.json
-
Setup Husky (if applicable)
If you are using Husky for Git hooks, make sure to set it up:
yarn prepare
Create a file named pre-commit in the .husky directory with the following content:
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
echo '🏗️👷 Styling, testing and building your project before committing'
# Check Prettier standards
yarn check-format ||
(
echo '🤢🤮🤢🤮 Its FOKING RAW - Your styling looks disgusting. 🤢🤮🤢🤮
Prettier Check Failed. Run yarn format, add changes and try commit again.';
false;
)
# Check ESLint Standards
yarn check-lint ||
(
echo '😤🏀👋😤 Get that weak shit out of here! 😤🏀👋😤
ESLint Check Failed. Make the required changes listed above, add changes and try to commit again.'
false;
)
# Check tsconfig standards
yarn check-types ||
(
echo '🤡😂❌🤡 Failed Type check. 🤡😂❌🤡
Are you seriously trying to write that? Make the changes required above.'
false;
)
# If everything passes... Now we can commit
echo '🤔🤔🤔🤔... Alright.... Code looks good to me... Trying to build now. 🤔🤔🤔🤔'
# Uncomment the following code if you want to run a build before committing:
# yarn build ||
# (
# echo '❌👷🔨❌ Better call Bob... Because your build failed ❌👷🔨❌
# Next build failed: View the errors above to see why.
# '
# false;
# )
# If everything passes... Now we can commit
echo '✅✅✅✅ You win this time... I am committing this now. ✅✅✅✅'
- Ensure that you have the Prettier and ESLint extensions installed and enabled in VSCode.
- The settings provided will automatically format and lint your code on save and paste.
Happy coding!