Skip to content

Instantly share code, notes, and snippets.

@AshCoolman
Created November 6, 2023 11:09
Show Gist options
  • Select an option

  • Save AshCoolman/ec3da0b1df7a30e38c9d4388cacb0436 to your computer and use it in GitHub Desktop.

Select an option

Save AshCoolman/ec3da0b1df7a30e38c9d4388cacb0436 to your computer and use it in GitHub Desktop.

Revisions

  1. AshCoolman created this gist Nov 6, 2023.
    29 changes: 29 additions & 0 deletions yarn-doctor-command-not-found.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    #!/bin/bash

    if [ ! -f "package.json" ]; then
    echo "No package.json. Run this at your project root."
    exit 1
    fi

    echo -n "Command not found: "
    read command

    if [ ! -d "./node_modules/.bin" ]; then
    echo "Missing ./node_modules/.bin. Run 'yarn install'."
    exit 1
    fi

    if [ ! -f "./node_modules/.bin/$command" ]; then
    echo "Missing command $command. Install with 'yarn add <package>'."
    exit 1
    fi

    if [[ ":$PATH:" != *":$(yarn global bin):"* ]]; then
    echo "Yarn's bin not in PATH. Add with 'export PATH=\"$(yarn global bin):\$PATH\"' (probably use \$HOME) in .bashrc or .zshrc."
    fi

    if ! grep -q "\"$command\"" "package.json"; then
    echo "Command $command not in scripts. Add it or run with 'yarn run <command>'."
    fi

    echo "Looks correct. Check package documentation or reinstall with 'yarn add <package>'."