project_name: jfa-go
release:
    github:
        owner: hrfee
        name: jfa-go
    name_template: "v{{.Version}}"
before:
  hooks:
    - go mod download
    - rm -rf data/web
    - mkdir -p data/web/css
    - bash -c 'cp -r static/* data/web/'
    - npm install
    - npm install esbuild
    - cp node_modules/remixicon/fonts/remixicon.css node_modules/remixicon/fonts/remixicon.woff2 data/web/css/
    - cp -r html data/
    - node scripts/missing-colors.js html data/html
    - cp -r lang data/
    - cp LICENSE data/
    - cp jfa-go.service data/
    - python3 scripts/enumerate_config.py -i config/config-base.json -o data/config-base.json
    - python3 scripts/generate_ini.py -i config/config-base.json -o data/config-default.ini
    - python3 scripts/compile_mjml.py -o data/
    - rm -rf tempts
    - cp -r ts tempts
    - scripts/dark-variant.sh tempts
    - scripts/dark-variant.sh tempts/modules
    - mkdir -p data/web/js
    - npx esbuild --target=es6 --bundle tempts/admin.ts {{.Env.JFA_GO_SOURCEMAP}} --outfile=./data/web/js/admin.js {{.Env.JFA_GO_MINIFY}}
    - npx esbuild --target=es6 --bundle tempts/user.ts {{.Env.JFA_GO_SOURCEMAP}} --outfile=./data/web/js/user.js {{.Env.JFA_GO_MINIFY}}
    - npx esbuild --target=es6 --bundle tempts/pwr.ts {{.Env.JFA_GO_SOURCEMAP}} --outfile=./data/web/js/pwr.js {{.Env.JFA_GO_MINIFY}}
    - npx esbuild --target=es6 --bundle tempts/form.ts {{.Env.JFA_GO_SOURCEMAP}} --outfile=./data/web/js/form.js {{.Env.JFA_GO_MINIFY}}
    - npx esbuild --target=es6 --bundle tempts/setup.ts {{.Env.JFA_GO_SOURCEMAP}} --outfile=./data/web/js/setup.js {{.Env.JFA_GO_MINIFY}}
    - npx esbuild --target=es6 --bundle tempts/crash.ts {{.Env.JFA_GO_SOURCEMAP}} --outfile=./data/crash.js {{.Env.JFA_GO_MINIFY}}
    - bash -c "{{.Env.JFA_GO_COPYTS}}"
    - rm -r tempts
    - npx esbuild --bundle css/base.css --outfile=./data/web/css/bundle.css --external:remixicon.css --external:../fonts/hanken* --minify
    - cp html/crash.html data/
    - npx tailwindcss -i data/web/css/bundle.css -o data/bundle.css --content "html/crash.html"
    - node scripts/inline.js root data data/crash.html data/crash.html
    - rm data/bundle.css
    - npx tailwindcss -i data/web/css/bundle.css -o data/web/css/bundle.css
    - mv data/crash.html data/html/
    - go install github.com/swaggo/swag/cmd/swag@latest
    - swag init -g main.go
    - mv data/web/css/bundle.css data/web/css/{{.Env.JFA_GO_CSS_VERSION}}bundle.css
builds:
    - id: notray
      dir: ./
      env:
        - CGO_ENABLED=0
      ldflags:
        - -X main.version={{.Env.JFA_GO_VERSION}} -X main.commit={{.ShortCommit}} -X main.updater=binary {{.Env.JFA_GO_STRIP}} -X main.cssVersion={{.Env.JFA_GO_CSS_VERSION}} -X main.buildTimeUnix={{.Env.JFA_GO_BUILD_TIME}} -X main.builtBy="{{.Env.JFA_GO_BUILT_BY}}"
      goos:
        - linux
        - darwin
      goarch:
        - arm
        - arm64
        - amd64
    - id: windows-tray
      dir: ./
      env:
        - CGO_ENABLED=1
        - CC=x86_64-w64-mingw32-gcc
        - CXX=x86_64-w64-mingw32-g++
      flags:
        - -tags=tray
      ldflags:
        - -X main.version={{.Env.JFA_GO_VERSION}} -X main.commit={{.ShortCommit}} -X main.updater=binary {{.Env.JFA_GO_STRIP}} -X main.cssVersion={{.Env.JFA_GO_CSS_VERSION}} -X main.buildTimeUnix={{.Env.JFA_GO_BUILD_TIME}} -X main.builtBy="{{.Env.JFA_GO_BUILT_BY}}" -H=windowsgui
      goos:
        - windows
      goarch:
        - amd64
    - id: linux-tray
      dir: ./
      env:
        - CGO_ENABLED=1
      flags:
        - -tags=tray
      ldflags:
        - -X main.version={{.Env.JFA_GO_VERSION}} -X main.commit={{.ShortCommit}} -X main.updater=binary {{.Env.JFA_GO_STRIP}} -X main.cssVersion={{.Env.JFA_GO_CSS_VERSION}} -X main.buildTimeUnix={{.Env.JFA_GO_BUILD_TIME}} -X main.builtBy="{{.Env.JFA_GO_BUILT_BY}}"
      goos:
        - linux
      goarch:
        - amd64
archives:
  - id: windows-tray
    builds:
        - windows-tray
    format: zip
    name_template: >-
      {{ .ProjectName }}_{{ .Version }}_TrayIcon_
      {{- if eq .Os "darwin" }}macOS
      {{- else }}{{- title .Os }}{{ end }}_
      {{- if eq .Arch "amd64" }}x86_64
      {{- else }}{{ .Arch }}{{ end }}
  - id: linux-tray
    builds:
        - linux-tray
    format: zip
    name_template: >-
      {{ .ProjectName }}_{{ .Version }}_TrayIcon_
      {{- if eq .Os "darwin" }}macOS
      {{- else }}{{- title .Os }}{{ end }}_
      {{- if eq .Arch "amd64" }}x86_64
      {{- else }}{{ .Arch }}{{ end }}
  - id: notray
    builds:
        - notray
    format: zip
    name_template: >-
      {{ .ProjectName }}_{{ .Version }}_
      {{- if eq .Os "darwin" }}macOS
      {{- else }}{{- title .Os }}{{ end }}_
      {{- if eq .Arch "amd64" }}x86_64
      {{- else }}{{ .Arch }}{{ end }}
checksum:
    name_template: 'checksums.txt'
snapshot:
    name_template: "0.0.0-{{ .Env.JFA_GO_NFPM_EPOCH }}"
changelog:
    sort: asc
    filters:
        exclude:
            - '^docs:'
            - '^test:'
nfpms:
  - id: notray
    file_name_template: '{{ .ProjectName }}{{ if .IsSnapshot }}-git{{ end }}_{{ .Arch }}_{{ if .IsSnapshot }}{{ .ShortCommit }}{{ else }}v{{ .Version }}{{ end }}'
    package_name: jfa-go
    homepage: https://github.com/hrfee/jfa-go
    description: A web app for managing users on Jellyfin
    maintainer: Harvey Tindall <hrfee@hrfee.dev>
    license: MIT
    vendor: hrfee.dev
    version_metadata: git
    builds:
      - notray
    contents:
      - src: ./LICENSE
        dst: /usr/share/licenses/jfa-go
    formats:
      - apk
      - deb
      - rpm
  - id: tray
    file_name_template: '{{ .ProjectName }}{{ if .IsSnapshot }}-git{{ end }}_TrayIcon_{{ .Arch }}_{{ if .IsSnapshot }}{{ .ShortCommit }}{{ else }}v{{ .Version }}{{ end }}'
    package_name: jfa-go-tray
    homepage: https://github.com/hrfee/jfa-go
    description: A web app for managing users on Jellyfin
    maintainer: Harvey Tindall <hrfee@hrfee.dev>
    license: MIT
    vendor: hrfee.dev
    version_metadata: git
    builds:
      - linux-tray
    contents:
      - src: ./LICENSE
        dst: /usr/share/licenses/jfa-go
    formats:
      - apk
      - deb
      - rpm
    overrides:
        deb:
            conflicts:
                - jfa-go
            replaces:
                - jfa-go
            dependencies:
                - libayatana-appindicator
        rpm:
            dependencies:
                - libappindicator-gtk3
        apk:
            dependencies:
                - libayatana-appindicator
