Last active
July 4, 2024 20:57
-
-
Save mearleycf/5454ae2216235694cfdfe33676630e68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env fish | |
# description: Add a package to a project using yarn, with optional flags for using an astro installer or adding as a dev dependency | |
# ~/.config/fish/functions/ya.fish | |
function ya | |
# source the colors.fish file | |
source ~/.config/fish/functions/colors.fish | |
set_colors #run the set_colors function | |
# debug | |
source ~/.config/fish/functions/checkpoint.fish | |
function usage --argument-names exitcode | |
echo "$color_brightred Usage: ya [options] <package_name>" | |
echo "$color_brightred Options:" | |
echo "$color_brightred -a, --astro Add astro package" | |
echo "$color_brightred -d, --dev Add package as dev dependency" | |
echo "$color_brightred -h, --help Display this help message $color_reset" | |
test -z $exitcode || exit $exitcode | |
end | |
# Parse arguments | |
argparse --name=yarn_add --min-args=1 'a/astro' 'd/dev' -- $argv | |
or usage 1 | |
# Check if no package name is provided | |
if not set -q argv[1] | |
usage 1 | |
end | |
# We detail the arguments | |
if set -q _flag_astro | |
set -e argv[1] # remove 'astro' from the arguments | |
if count $argv -eq 0 | |
usage 1 | |
end | |
echo "$color_brightpurple running yarn add $color_brightgreen astro $color_cyan $argv $color_reset" | |
yarn add astro $argv | |
if test $status -eq 0 | |
echo "$color_brightpurple yarn add $color_brightgreen astro $color_cyan $argv was a success! $color_reset" | |
end | |
return 0 | |
end | |
if set -q _flag_dev | |
set -e argv[1] # remove the dev flag from the arguments | |
if count $argv -eq 0 | |
usage 1 | |
end | |
echo "$color_brightpurple running yarn add $color_brightgreen --dev $color_cyan $argv $color_reset" | |
yarn add --dev $argv | |
if test $status -eq 0 | |
echo "$color_brightpurple yarn add $color_brightgreen --dev $color_cyan $argv was a success! $color_reset" | |
end | |
return 0 | |
end | |
# If no flags are passed, just run yarn add | |
if test (count $argv) -eq 0 | |
usage 1 | |
end | |
echo "$color_brightpurple running yarn add $color_cyan $argv $color_reset" | |
yarn add $argv | |
if test $status -eq 0 | |
echo "$color_brightpurple yarn add $color_cyan $argv was a success! $color_reset" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment