stages:
  - install
  - test
  - build

cache:
  paths:
    - node_modules/
    - .pnpm-store/

npm-install:
  stage: install
  image: node:18
  before_script:
    - npm install -g pnpm
    - pnpm config set store-dir .pnpm-store
  script:
    - pnpm install --frozen-lockfile
  cache:
    policy: pull-push
    untracked: false
    when: on_success
    key: ${CI_COMMIT_REF_SLUG}
    paths:
      - node_modules/

prettier-check-styling:
  stage: test
  image: node:18
  before_script:
    - npm install -g pnpm
    - pnpm config set store-dir .pnpm-store
  script:
    - pnpm install --frozen-lockfile
    - pnpm check-prettier
  cache:
    policy: pull
    untracked: false
    when: on_success
    key: ${CI_COMMIT_REF_SLUG}
    paths:
      - node_modules/

typescript:
  stage: build
  image: node:18
  before_script:
    - npm install -g pnpm
    - pnpm config set store-dir .pnpm-store
  script:
    - pnpm install --frozen-lockfile
    - pnpm build
  cache:
    policy: pull
    untracked: false
    when: on_success
    key: ${CI_COMMIT_REF_SLUG}
    paths:
      - node_modules/

deploy-webpage:
  stage: build
  image: node:18
  before_script:
    - npm install -g pnpm
    - pnpm config set store-dir .pnpm-store
  only:
    - main
  script:
    - pnpm install --frozen-lockfile
    - pnpm build
    - npx netlify-cli deploy --dir=dist --site 8673dfdb-86f5-4084-8b67-6c5d0df04964 --auth $NETLIFY_TOKEN --prod
  cache:
    policy: pull
    untracked: false
    when: on_success
    key: ${CI_COMMIT_REF_SLUG}
    paths:
      - node_modules/
