---
version: '3'

tasks:
  autocannon:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: autocannon

  clinic:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: clinic

  codecov:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: codecov

  commitizen:
    run: once
    cmds:
      - task: global
        vars:
          FORCE_INSTALL: true
          NPM_PACKAGE: commitizen
          NPM_PACKAGE_BIN: git-cz

  commitlint:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: '@commitlint/cli'
          NPM_PACKAGE_BIN: commitlint

  cspell:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: cspell

  cz-emoji:
    run: once
    cmds:
      - task: global:library
        vars:
          NPM_PACKAGE: cz-emoji

  depcheck:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: depcheck

  esbuild:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: esbuild

  eslint:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: eslint

  esprint:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: esprint

  fuite:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: fuite

  git-notify:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: git-notify

  global:
    deps:
      - global:package-manager
    vars:
      PACKAGE_BIN: '{{if index . "NPM_PACKAGE_BIN"}}{{.NPM_PACKAGE_BIN}}{{else}}{{.NPM_PACKAGE}}{{end}}'
    run: when_changed
    log:
      error: Failed to install NPM package `{{.NPM_PACKAGE}}` globally
      start: Installing NPM package `{{.NPM_PACKAGE}}` globally
      success: Installed NPM package `{{.NPM_PACKAGE}}` globally
    cmds:
      - '{{.NPM_PROGRAM}} install -g {{.NPM_PACKAGE}}'
    status:
      - type {{.PACKAGE_BIN}} > /dev/null

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

  global:package-manager:
    run: once
    log:
      error: Failed to install `{{.NPM_PROGRAM}}`
      start: Installing `{{.NPM_PROGRAM}}`
      success: Successfully installed `{{.NPM_PROGRAM}}`
    cmds:
      - task: :install:software:node
      - npm install -g {{.NPM_PROGRAM}}
    status:
      - type {{.NPM_PROGRAM}} > /dev/null

  husky:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: husky

  ionic:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: '@ionic/cli'
          NPM_PACKAGE_BIN: ionic

  jest:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: jest

  leasot:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: leasot

  lint-staged:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: lint-staged

  liquidjs:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: hbs-cli
          NPM_PACKAGE_BIN: hbs
      - task: global
        vars:
          NPM_PACKAGE: liquidjs

  majestic:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: majestic

  markdown-link-check:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: markdown-link-check

  ndb:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: ndb

  nest:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: '@nestjs/cli'
          NPM_PACKAGE_BIN: nest

  nodemon:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: nodemon

  npm:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: npm

  ntl:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: ntl

  nx:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: nx

  only-allow:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: only-allow

  open-cli:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: open-cli

  pkg:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: pkg

  pnpm:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: pnpm
      - task: pnpm:import
    status:
      - type pnpm &> /dev/null

  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
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: prettier

  readme:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: '@appnest/readme'
          NPM_PACKAGE_BIN: readme

  remark:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: remark-cli
          NPM_PACKAGE_BIN: remark

  semantic-release:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: semantic-release

  sharp:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: sharp-cli
          NPM_PACKAGE_BIN: sharp

  shellcheck:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: shellcheck

  snyk:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: snyk

  standard:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: standard

  standard-version:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: standard-version

  tinypng:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: tinypng-cli
          NPM_PACKAGE_BIN: tinypng

  ts-node:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: ts-node

  typedoc:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: typedoc

  typescript:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: typescript
          NPM_PACKAGE_BIN: tsc

  typesync:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: typesync

  yarnhook:
    run: once
    cmds:
      - task: global
        vars:
          NPM_PACKAGE: yarnhook
