PiedTeam / NikeCloneTraining-BE-Project

1 stars 0 forks source link

Set up & Config Backend Project #3

Closed quyn2904 closed 6 months ago

Buicongbang04 commented 7 months ago

ESlint + Prettier

eslint: Main linter (error checker). prettier: Primary code formatter. eslint-config-prettier: ESLint configuration to avoid conflicts with Prettier. eslint-plugin-prettier: Adds some Prettier rules to ESLint. @typescript-eslint/eslint-plugin: ESLint plugin providing rules for TypeScript. @typescript-eslint/parser: Parser allowing ESLint to check TypeScript errors. ts-node: Used to run TypeScript code directly without needing to build. tsc-alias: Handles aliases during build. tsconfig-paths: When setting alias imports in a project using ts-node, we need tsconfig-paths to understand the paths and baseUrl in the tsconfig.json file. rimraf: Used to remove the 'dist' folder before building. nodemon: Used to automatically restart the server when changes occur in the code.

File tsconfig.json

{
  "compilerOptions": {
    "module": "CommonJS", //Specifies the output module system used. 
    "moduleResolution": "node", // Determines how module resolution is performed.
    "target": "ES2020", // Specifies the ECMAScript target version for the emitted code.
    "outDir": "dist", // Specifies the output directory for compiled files.
    "esModuleInterop": true /* Emit additional JavaScript to enable importing CommonJS modules easily. This facilitates 'allowSyntheticDefaultImports' for type compatibility. */,
    "strict": true /* Enables all strict type-checking options. */,
    "skipLibCheck": true /* Skips type checking of declaration files (.d.ts). */,
    "baseUrl": ".", // Base directory to resolve non-relative module names.
    "paths": {
      "~/*": ["src/*"] // Relative paths for imports (aliases).
    }
  },
  "ts-node": {
    "require": ["tsconfig-paths/register"]
  },
  "files": ["src/type.d.ts"], // Files used to define global types for the project.
  "include": ["src/**/*"] // Specifies paths included for compilation.
}

File .eslintrc

{
  "root": true,
  "parser": "@typescript-eslint/parser",
  "plugins": ["@typescript-eslint", "prettier"],
  "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "eslint-config-prettier", "prettier"],
  "rules": {
    "@typescript-eslint/no-explicit-any": "off",
    "@typescript-eslint/no-unused-vars": "off",
    "prettier/prettier": [
      "warn",
      {
        "arrowParens": "always",
        "semi": false,
        "trailingComma": "none",
        "tabWidth": 4,
        "endOfLine": "auto",
        "useTabs": false,
        "singleQuote": true,
        "printWidth": 80,
        "jsxSingleQuote": true
      }
    ]
  }
}

File .eslintignore

Loại bỏ những file không muốn format code

node_modules/
dist/

File .prettierrc

{
  "arrowParens": "always",
  "semi": false,
  "trailingComma": "none",
  "tabWidth": 4,
  "endOfLine": "auto",
  "useTabs": false,
  "singleQuote": true,
  "printWidth": 80,
  "jsxSingleQuote": true
}

File .prettierignore

Không canh lề cho những cái mình không thích

node_modules/
dist/

File .editorconfig

Install extensions EditorConfig for VS Code

indent_size = 4;
indent_style = space;

File .gitignore

Avoid pushing unnecessary files to github

Access this link find with keyword "nodejs", copy and paste all content to this file.

nodemon.json

{
  "watch": ["src"], // Monitors changes in the 'src' directory.
  "ext": ".ts,.js", // Tracks files with '.ts' and '.js' extensions.
  "ignore": [], // Lists files to ignore tracking changes.
  "exec": "npx ts-node ./src/index.ts" // Executes the 'index.ts' file using ts-node.
}

package.json

Change scripts in file package.json to

  "scripts": {
    "dev": "npx nodemon", // Used for development to auto-reload changes while coding.
    "build": "rimraf ./dist && tsc && tsc-alias", // Compiles and builds the project into the 'dist' directory after cleaning it, also handles TypeScript aliases.
    "start": "node dist/index.js", // Executes the built code, must be built beforehand.
    "lint": "eslint .", // Checks for code style and potential errors.
    "lint:fix": "eslint . --fix", // Fixes linting errors automatically.
    "prettier": "prettier --check .", // Checks code formatting using Prettier.
    "prettier:fix": "prettier --write ." // Automatically fixes code formatting using Prettier.
  }

Create type.d.ts

Create src folder, then create file type.d.ts type.d.ts is a file that helps you define the data types of variables while coding ts

minhhy2801 commented 6 months ago

This ticket has not been finished yet. So I reopen it Please change your status before restart Leader please help assign the member implement this ticket cc @quyn2904