image: node:18

stages:
  - build
  - deploy

variables:
  # Define the NPM registry and NPM token (you should configure these as environment variables in GitLab CI/CD settings)
  NPM_REGISTRY: "https://registry.npmjs.org/"
  NPM_TOKEN: $NPM_TOKEN

cache:
  paths:
    - node_modules/

before_script:
  - npm install

build:
  stage: build
  script:
    - npm run build
  artifacts:
    paths:
      - dist/
    expire_in: 1 day

publish:
  stage: deploy
  script:
    - echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc
    - npm publish --registry $NPM_REGISTRY
  only:
    - master
  when: manual
  environment:
    name: production
