name: NPM Registry

on:
  release:
    types: [published]

jobs:
  push-to-npm-registry-as-latest:
    if: "!github.event.release.prerelease"
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3
    - uses: actions/setup-node@v3
      with:
        node-version: "18"
    - uses: JS-DevTools/npm-publish@v2
      with:
        token: ${{ secrets.NPM_TOKEN }}
        access: public
        tag: latest

  push-to-npm-registry-as-next:
    if: "github.event.release.prerelease"
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3
    - uses: actions/setup-node@v3
      with:
        node-version: "18"
    - uses: JS-DevTools/npm-publish@v2
      with:
        token: ${{ secrets.NPM_TOKEN }}
        access: public
        tag: next