name: Publish to NPM

on:
  workflow_dispatch:

jobs:
  publish:
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          registry-url: 'https://registry.npmjs.org'

      - name: Install TypeScript
        run: npm install -g typescript

      - name: Install dependencies
        run: npm install --ignore-scripts

      - name: Compile TypeScript
        run: tsc index.ts --target ES2020 --module commonjs --esModuleInterop true --skipLibCheck true || true

      - name: Publish to NPM
        run: npm publish --access public
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
