version: '3'

vars:
  test_node_options: '--experimental-vm-modules'
  coverage_file: 'coverage/coverage.txt'

tasks:
  build:
    desc: Build the project
    cmds:
      - tsc --build

  clean:
    desc: Clean the build artifacts
    cmds:
      - tsc --build --clean

  lint:
    desc: Run ESLint
    cmds:
      - eslint .

  lint-fix:
    desc: Run ESLint and fix issues
    cmds:
      - eslint . --fix

  docs:
    desc: Generate documentation
    cmds:
      - npx typedoc --tsconfig tsconfig.json index.ts src/**/* --includeVersion --entryPointStrategy expand

  test:
    desc: Run all tests
    cmds:
      - task test-ts
      - task test-js

  test-ts:
    desc: Run TypeScript tests
    cmds:
      - NODE_OPTIONS="$NODE_OPTIONS --experimental-vm-modules" jest --workerIdleMemoryLimit=1024 --coverage --silent --runInBand --logHeapUsage 
      - cat {{.coverage_file}}

  test-js:
    desc: Run JavaScript smoke tests
    cmds:
      - rm -rf ./smoke-tests
      - tsc -p tsconfig.smoke.json
      - task test-js-inner

  test-js-inner:
    desc: Run smoke tests in the smoke-tests directory
    dir: smoke-tests
    cmds:
      - cp -R ../node_modules node_modules
      - npm i
      - NODE_OPTIONS="$NODE_OPTIONS {{.test_node_options}}" jest --workerIdleMemoryLimit=1024 --config=./jest.smoke.config.js --coverage --silent --runInBand --logHeapUsage
      - cat ../{{.coverage_file}}

  test-dev:
    desc: Run tests in development mode
    cmds:
      - jest --coverage --runInBand
      - cat {{.coverage_file}}
