-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gabe Dunn
committed
Jul 8, 2021
0 parents
commit 3cecedc
Showing
4 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
The MIT License (MIT) | ||
Copyright (c) Gabe Dunn 2021 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#!/usr/bin/env zsh | ||
|
||
yup () { | ||
# check if a package manager is installed | ||
if (( $+commands[yarn] )); then | ||
local pm_cmd="yarn add" | ||
elif (( $+commands[npm] )); then | ||
local pm_cmd="npm install" | ||
else | ||
echo "yarn or npm not found, exiting..." | ||
return 1 | ||
fi | ||
|
||
# make sure jq is installed | ||
if (( ! $+commands[jq] )); then | ||
echo "jq not found, exiting..." | ||
return 1 | ||
fi | ||
|
||
# make sure there's a package.json in the current directory | ||
if ! test -f "./package.json"; then | ||
echo "no package.json file in current directory, exiting..." | ||
return 1 | ||
fi | ||
|
||
# set default dependency scope | ||
local scope="dependencies" | ||
local both=false | ||
|
||
# check for args | ||
for arg in "$@"; do | ||
# help/usage command | ||
if test "$arg" = "-h" -o "$arg" = "--help"; then | ||
cat << 'eof' | ||
Usage: yup [-h/--help] [-d/--dev] [-D/--both] [-n/--npm] | ||
Options: | ||
-h, --help show this help message | ||
-d, --dev update the devDependencies | ||
-b, --both update both dependencies and devDependencies | ||
-n, --npm update the dependencies using npm instead of yarn | ||
eof | ||
return 0; | ||
fi | ||
|
||
# set the command to use npm if the arg is passed | ||
if test "$arg" = "-n" -o "$arg" = "--npm"; then | ||
pm_cmd="npm install" | ||
fi | ||
|
||
# set scope to devDependencies if the arg is passed | ||
if test "$arg" = "-d" -o "$arg" = "--dev"; then | ||
scope="devDependencies" | ||
pm_cmd="$pm_cmd --save-dev" | ||
elif test "$arg" = "-b" -o "$arg" = "--both"; then | ||
both=true | ||
fi | ||
done | ||
|
||
# grab deps from package.json | ||
# start with empty object and add the deps | ||
local deps="$(jq "{}+.$scope|keys|map(.+\" \")+[\"\"]|add" ./package.json | sed -E 's/^\"//; s/( )?\"$//')" | ||
|
||
# if there aren't any dependencies, exit the function | ||
if test -z "$deps"; then | ||
echo "no $scope in package.json" | ||
return 0 | ||
fi | ||
|
||
# set the command to run | ||
local cmd_to_run="$pm_cmd $deps" | ||
|
||
# run the command | ||
echo "Updating $scope..." | ||
eval "$cmd_to_run" | ||
|
||
# if the both arg was passed, run the command again, but for devDependencies | ||
if $both; then | ||
# change the scope to devDependencies | ||
pm_cmd="$pm_cmd --save-dev" | ||
scope="devDependencies" | ||
|
||
# grab the deps again | ||
deps="$(jq "{}+.$scope|keys|map(.+\" \")+[\"\"]|add" ./package.json | sed -E 's/^\"//; s/( )?\"$//')" | ||
|
||
# if there aren't any dependencies, exit the function | ||
if test -z "$deps"; then | ||
echo "no $scope in package.json" | ||
return 0 | ||
fi | ||
|
||
# set the command to run | ||
cmd_to_run="$pm_cmd $deps" | ||
|
||
# run the command | ||
echo "Updating $scope..." | ||
eval "$cmd_to_run" | ||
fi | ||
|
||
# end the function | ||
echo "Upgrades finished!" | ||
return 0 | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# yup | ||
> yup is a zsh plugin that provides a function upgrades all dependencies in a | ||
> yarn/npm project. | ||
## Installing | ||
|
||
### zinit | ||
Add this to your zinit config (.zshrc): | ||
```zsh | ||
zinit light redxtech/zsh-yup | ||
|
||
# it also works with turbo mode: | ||
zinit ice wait lucid | ||
zinit load redxtech/zsh-yup | ||
``` | ||
|
||
### oh-my-zsh | ||
Install it with your favourite zsh package manager, or clone it directly to your | ||
`$ZSH_CUSTOM/plugins` directory with git, and add `zsh-yup` to the plugins | ||
array in your `.zshrc` file: | ||
|
||
```zsh | ||
plugins=(... zsh-yup) | ||
``` | ||
|
||
## Usage | ||
`yup` is very easy to use, simply run the command: | ||
|
||
```zsh | ||
yup | ||
``` | ||
|
||
There are some options to pass to the command: | ||
```zsh | ||
Usage: yup [-h/--help] [-d/--dev] [-D/--both] [-n/--npm] | ||
Options: | ||
-h, --help show this help message | ||
-d, --dev update the devDependencies | ||
-b, --both update both dependencies and devDependencies | ||
-n, --npm update the dependencies using npm | ||
``` | ||
|
||
## Author | ||
**yup** © [Gabe Dunn](https://github.com/redxtech), Released under the [MIT](./license.md) License. | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env zsh | ||
|
||
# zsh plugin to update all dependencies of a yarn/npm project | ||
|
||
# add the functions to the function path & autoload them | ||
fpath+=("$(dirname ${0})/functions") | ||
autoload -Uz yup | ||
|