'How to watch file changes with ts and js build

I have a project with fastify, apollo server fastify and nx. I want to add a script to build my code and run the js files. the problem is that if I make any changes in ts file it wont recognize to re run the js files. what should I do? btw I can't use ts-node for runnig my ts code because I have used custom libraries and I have to first build my code.

my current script:

"serve": {
      "executor": "@nrwl/workspace:run-commands",
      "options": {
        "commands": [
          "tsc -p tsconfig.app.json -w",
          "tsc-alias -p tsconfig.app.json -w",
          "nodemon ../../dist/apps/server/authentication/index.js"
        ],
        "cwd": "apps/authentication",
        "parallel": true
      }
    }


Solution 1:[1]

I made a custom executor, I hope this help someone else:

    "start": {
      "executor": "@nrwl/workspace:run-commands",
      "options": {
        "commands": [
          "nodemon -e ts,graphql --exec \"nx run server-authentication:start-nodemon\""
        ],
        "cwd": "apps/server/authentication",
        "parallel": false
      }
    },
    "start-nodemon": {
      "executor": "@nrwl/workspace:run-commands",
      "options": {
        "commands": [
          "nx run server-authentication:ts-build",
          "node ../../../../dist/apps/server/authentication/src/index.js"
        ],
        "cwd": "apps/server/authentication",
        "parallel": false
      }
    },
    "ts-build": {
      "executor": "@nrwl/workspace:run-commands",
      "options": {
        "commands": [
          "tsc -p tsconfig.app.json",
          "tsc-alias -p tsconfig.app.json",
          "ncp src/schema ../../../../dist/apps/server/authentication/src/schema",
          "ncp .env ../../../../dist/apps/server/authentication/src/.env"
        ],
        "cwd": "apps/server/authentication",
        "parallel": false
      }
    },

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mj Ebrahimzadeh