Exit

Configure a TypeScript project with CI/CD

posted on July 16, 2024, last updated on Saturday, November 23, 2024 at 10:51 AM

[!NOTE]

The project to be configured:

  Value Note
  multi-stage-cd  
     
     

Initialize the project

  1. Make the directory

    1
    2
    
    mkdir multi-stage-cd
    cd multi-stage-cd
    
  2. Initialize git repo

    1
    
    git init
    
  3. Install typescript and node env for ts

    1
    
    npm install typescript ts-node @types/node --save-dev
    

    (--save-dev flag indicates that the packages are necessary for development purposes.)

  4. Configure .gitignore to prevent packages being added to git repo

    1
    
    echo "node_modules/*" > .gitignore
    
  5. Initalize ts project

    1
    
    tsc --init
    

Configure Jest test env

  1. Install jest

    1
    
    npm install jest ts-jest @types/jest --save-dev
    
  2. Configure jest

    1
    
    npx ts-jest config:init
    
  3. Modify tsconfig.json

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    
    {
      "compilerOptions": {
        "target": "ES6",
        "module": "commonjs",
        "strict": true,
        "esModuleInterop": true,
        "outDir": "./dist",
        "rootDir": "./src"
      },
      "include": ["src/**/*.ts", "tests/**/*.ts"],
      "exclude": ["node_modules"]
    }