Skip to content

Commit

Permalink
fix: validating arguments
Browse files Browse the repository at this point in the history
Signed-off-by: Mohan Narayana <[email protected]>
  • Loading branch information
MohanNarayana committed Oct 14, 2021
1 parent ee176d3 commit 05bc9c3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
22 changes: 17 additions & 5 deletions bin/package-link
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ set -o pipefail # don't ignore exit codes when piping output
set -o posix # more strict failures in subshells
# set -x # enable debugging

IFS="$(printf "\n\t")"
# ---- End unofficial bash strict mode boilerplate

package_name=$1
Expand All @@ -19,12 +18,26 @@ yalc_packages_file_name="yalc-packages"
container_id="$(docker-compose ps -q api)"
container_copied_packages_path="/home/node/copied-packages"

org_name='@reactioncommerce'
if [[ $package_name != $org_name* ]]; then
echo "ERROR: The organization name does not match. Make sure the first argument is of the format '@reactioncommerce/<api-plugin-name>'"
# validate input
IFS='/'
read -a pkgarr <<< "$1"
org_name=${pkgarr[0]}
package_name_without_org=${pkgarr[1]}
if [ -z "$package_name_without_org" ] || [ -z "$org_name" ]; then
echo "ERROR: Incorrect input. Please check the format of the first argument. '@<org-name>/<api-plugin-name>'"
exit 0
fi

#check if the package is valid by cross referencing with node_modules
is_package=$(find node_modules/$org_name -type d -name $package_name_without_org)
if [ -z "$is_package" ]; then
echo "$package_name does not exist"
exit 0
fi


IFS="$(printf "\n\t")"

if [[ -z "${package_name}" ]]; then
if ! [[ -f "$yalc_packages_file_name" ]]; then
echo "Yalc packages file doesn't exist. Creating..."
Expand Down Expand Up @@ -65,7 +78,6 @@ else
container_destination_path="${container_copied_packages_path}/${package_name}"

if [[ -z "${package_path}" ]]; then
package_name_without_org="${package_name/#@reactioncommerce\/}"
package_path="../api-plugins/${package_name_without_org}"
full_package_path="$(cd ${package_path} && pwd)"
echo "\nUsing local package path ${full_package_path}"
Expand Down
21 changes: 17 additions & 4 deletions bin/package-unlink
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,30 @@ set -o pipefail # don't ignore exit codes when piping output
set -o posix # more strict failures in subshells
# set -x # enable debugging

IFS="$(printf "\n\t")"
# ---- End unofficial bash strict mode boilerplate

package_name=$1

org_name='@reactioncommerce'
if [[ $package_name != $org_name* ]]; then
echo "ERROR: The organization name does not match. Make sure the argument is of the format '@reactioncommerce/<api-plugin-name>'"
# validate input
IFS='/'
read -a pkgarr <<< "$1"
org_name=${pkgarr[0]}
package_name_without_org=${pkgarr[1]}
if [ -z "$package_name_without_org" ] || [ -z "$org_name" ]; then
echo "ERROR: Incorrect input. Please check the format of the first argument. '@<org-name>/<api-plugin-name>'"
exit 0
fi

#check if the package is valid by cross referencing with node_modules
is_package=$(find node_modules/$org_name -type d -name $package_name_without_org)
if [ -z "$is_package" ]; then
echo "$package_name does not exist"
exit 0
fi


IFS="$(printf "\n\t")"

# Unlink the yalc dependency, remove the package drectory and npm install
echo "Unlinking package from API..."
docker-compose exec api sh -c "cd /usr/local/src/app && yalc remove ${package_name}"
Expand Down

0 comments on commit 05bc9c3

Please sign in to comment.