---
version: '3'

tasks:
  autocannon:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: autocannon

  bitwarden:
    run: once
    cmds:
      - task: install:npm
        vars:
          BIN_NAME: bw
          PACKAGE: '@bitwarden/cli'

  browserslist:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: browserslist

  bundle:
    cmds:
      - task: :install:modules:global

  clinic:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: clinic

  codecov:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: codecov

  commitizen:
    run: once
    cmds:
      - task: install:npm
        vars:
          BIN_NAME: git-cz
          FORCE_INSTALL: true
          PACKAGE: commitizen
    status:
      - '[ -n "$CI" ] || type git-cz &> /dev/null'

  commitlint:
    run: once
    cmds:
      - task: install:npm
        vars:
          BIN_NAME: commitlint
          PACKAGE: '@commitlint/cli'
    status:
      - '[ -n "$CI" ]'

  crowdin:
    run: once
    cmds:
      - task: install:npm
        vars:
          BIN_NAME: crowdin
          PACKAGE: '@crowdin/cli'

  cspell:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: cspell

  depcheck:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: depcheck

  devcontainer:
    run: once
    cmds:
      - task: install:npm
        vars:
          BIN_NAME: devcontainer
          PACKAGE: '@vscode/dev-container-cli'

  dockerfilelint:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: dockerfilelint

  esbuild:
    run: once
    tags:
      - semantic
    cmds:
      - task: install:npm
        vars:
          PACKAGE: esbuild

  eslint:
    run: once
    tags:
      - update
    cmds:
      - task: install:npm
        vars:
          PACKAGE: eslint

  esprint:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: esprint

  fuite:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: fuite

  git-notify:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: git-notify

  global:library:
    deps:
      - global:package-manager
    env:
      PACKAGE_EXISTS:
        sh: |
          PACKAGE_PATH="$(echo $NODE_PATH | sed 's/^://' | sed 's/:.*$//')/{{.PACKAGE}}/package.json"
          if [ -f "$PACKAGE_PATH" ]; then
            echo 'true'
          else
            echo 'false'
          fi
    run: once
    log:
      error: Error installing `{{.PACKAGE}}` globally
      start: Installing NPM global library `{{.PACKAGE}}` which does not have a CLI
      success: '`{{.PACKAGE}}` has been installed globally'
    cmds:
      - |
        if [ -n "$CI" ]; then echo "*************** npm global --> {{.PACKAGE}}"; fi
      - |
        export PATH="$PATH:$HOME/.local/bin:$HOME/.volta/bin"
        volta install {{.PACKAGE}}'
    status:
      - '[[ "$PACKAGE_EXISTS" == "true" ]]'

  global:package-manager:
    deps:
      - :install:software:node
      - :install:software:volta
    run: once
    cmds:
      - .config/log info 'Installing `{{.NPM_PROGRAM}}`'
      - |
        export PATH="$PATH:$HOME/.local/bin:$HOME/.volta/bin"
        volta install {{.NPM_PROGRAM}}
      - .config/log info 'Successfully installed `{{.NPM_PROGRAM}}`'
    status:
      - type {{.NPM_PROGRAM}} > /dev/null

  htmlhint:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: htmlhint

  husky:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: husky

  ifttt:
    run: once
    cmds:
      - task: install:npm
        vars:
          BIN_NAME: ifttt
          PACKAGE: ifttt-cli

  install:npm:
    deps:
      - global:package-manager
    vars:
      BIN: '{{if .BIN_NAME}}{{.BIN_NAME}}{{else}}{{.PACKAGE}}{{end}}'
    run: when_changed
    cmds:
      - .config/log start 'Installing NPM package `{{.PACKAGE}}` globally'
      - |
        PATH="$PATH:$HOME/.local/bin:$HOME/.volta/bin"
        volta install {{.PACKAGE}}
      - .config/log success 'Installed NPM package `{{.PACKAGE}}` globally'
    status:
      - type {{.BIN}} > /dev/null

  ionic:
    run: once
    tags:
      - semantic
    cmds:
      - task: install:npm
        vars:
          BIN_NAME: ionic
          PACKAGE: '@ionic/cli'

  jest:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: jest

  leasot:
    run: once
    tags:
      - update
    cmds:
      - task: install:npm
        vars:
          PACKAGE: leasot

  lint-staged:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: lint-staged

  liquidjs:
    run: once
    tags:
      - update
    cmds:
      - task: install:npm
        vars:
          BIN_NAME: hbs
          PACKAGE: hbs-cli
      - task: liquidjs:install

  liquidjs:install:
    tags:
      - update
    cmds:
      - task: install:npm
        vars:
          PACKAGE: liquidjs

  majestic:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: majestic

  markdown-link-check:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: markdown-link-check

  markdown-table-formatter:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: markdown-table-formatter

  modclean:
    run: once
    tags:
      - semantic
    cmds:
      - task: install:npm
        vars:
          BIN_NAME: modclean
          PACKAGE: modclean@2

  ndb:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: ndb

  nest:
    run: once
    tags:
      - semantic
    cmds:
      - task: install:npm
        vars:
          BIN_NAME: nest
          PACKAGE: '@nestjs/cli'

  nodemon:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: nodemon

  npm:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: npm

  ntl:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: ntl

  nx:
    run: once
    tags:
      - semantic
    cmds:
      - task: install:npm
        vars:
          PACKAGE: nx

  only-allow:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: only-allow

  open-cli:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: open-cli

  pac:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: pac

  pkg:
    run: once
    tags:
      - semantic
    cmds:
      - task: install:npm
        vars:
          PACKAGE: pkg

  pnpm:
    run: once
    tags:
      - update
    cmds:
      - task: install:npm
        vars:
          PACKAGE: pnpm
      - task: pnpm:import
    status:
      - type pnpm &> /dev/null

  pnpm-lock-export:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: pnpm-lock-export

  pnpm:import:
    run: once
    log:
      error: Error running `pnpm import`
      start: Running `pnpm import`
      success: '`pnpm import` finished successfully!'
    cmds:
      - pnpm import
    status:
      - '[ ! -f package-lock.json ] && [ ! -f yarn.lock ] && [ ! -f npm-shrinkwrap.json ]'

  prettier:
    run: once
    tags:
      - update
    cmds:
      - task: install:npm
        vars:
          PACKAGE: prettier

  quicktype:
    run: once
    tags:
      - update
    cmds:
      - task: install:npm
        vars:
          PACKAGE: quicktype

  readme:
    run: once
    tags:
      - update
    cmds:
      - task: install:npm
        vars:
          BIN_NAME: readme
          PACKAGE: '@appnest/readme'

  real-favicon:
    run: once
    cmds:
      - task: install:npm
        vars:
          BIN_NAME: real-favicon
          PACKAGE: cli-real-favicon

  remark:
    run: once
    tags:
      - update
    cmds:
      - task: install:npm
        vars:
          BIN_NAME: remark
          PACKAGE: remark-cli

  secretlint:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: secretlint

  semantic-release:
    run: once
    tags:
      - semantic
    cmds:
      - task: install:npm
        vars:
          PACKAGE: semantic-release

  sharp:
    run: once
    cmds:
      - task: install:npm
        vars:
          BIN_NAME: sharp
          PACKAGE: sharp-cli

  shellcheck:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: shellcheck

  snyk:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: snyk

  standard:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: standard

  standard-version:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: standard-version

  stylelint:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: stylelint

  synp:
    run: once
    tags:
      - update
    cmds:
      - task: install:npm
        vars:
          PACKAGE: synp

  tinypng:
    run: once
    cmds:
      - task: install:npm
        vars:
          BIN_NAME: tinypng
          PACKAGE: tinypng-cli

  ts-node:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: ts-node

  typedoc:
    run: once
    tags:
      - semantic
    cmds:
      - task: install:npm
        vars:
          PACKAGE: typedoc

  typescript:
    run: once
    tags:
      - semantic
    cmds:
      - task: install:npm
        vars:
          BIN_NAME: tsc
          PACKAGE: typescript

  typesync:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: typesync

  wrangler:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: wrangler

  yarnhook:
    run: once
    cmds:
      - task: install:npm
        vars:
          PACKAGE: yarnhook
