Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add package-link file to storefront #745

Merged
merged 7 commits into from
Feb 5, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ build
/reports

docker-compose.override.yml

# Yalc
.yalc/
yalc.lock
yalc-packages
82 changes: 82 additions & 0 deletions bin/package-link
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env bash

# Please Use Google Shell Style: https://google.github.io/styleguide/shell.xml

# ---- Start unofficial bash strict mode boilerplate
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -o errexit # always exit on error
set -o errtrace # trap errors in functions as well
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
package_path=$2
yalc_packages_file_name="yalc-packages"
container_id="$(docker-compose ps -q web)"
container_copied_packages_path="/home/node/copied-packages"

if [[ -z "${package_name}" ]]; then
if ! [[ -f "$yalc_packages_file_name" ]]; then
echo "Yalc packages file doesn't exist. Creating..."
cp "${yalc_packages_file_name}.example" ${yalc_packages_file_name}
fi

echo "Reading package list from ${yalc_packages_file_name}"

while IFS== read -r path val; do
package_path="$path"
package_name="$(node -p -e "JSON.parse(process.argv[1]).name" "$(cat ${package_path}/package.json)")"
is_enabled="$val"

if [[ $package_name ]]; then
if [[ $is_enabled == "true" ]]; then
container_destination_path="${container_copied_packages_path}/${package_name}"

echo "Copying `${package_path}` package code into container to ${container_destination_path}..."
docker exec ${container_id} sh -c "mkdir -p ${container_destination_path}"
docker cp "${package_path}/." "${container_id}:${container_destination_path}"

# Then yalc link into this project
echo "Linking package ${package_name} into Example Storefront..."
docker exec ${container_id} sh -c "cd ${container_destination_path} && yalc push"
docker exec ${container_id} sh -c "cd /usr/local/src/app && yalc link ${package_name}"
else
echo "Unlinking package ${package_name} from Example Storefront..."
docker exec ${container_id} sh -c "cd /usr/local/src/app && yalc remove ${package_name}"
docker exec ${container_id} sh -c "rm -rf /usr/local/src/app/node_modules/${package_name}"
fi
fi
done < "$yalc_packages_file_name"

echo "Updating packages..."
docker exec ${container_id} sh -c "cd /usr/local/src/app && npm i"
docker exec ${container_id} sh -c "cd /usr/local/src/app && yalc update"
else
container_destination_path="${container_copied_packages_path}/${package_name}"

if [[ -z "${package_path}" ]]; then
package_name_without_org="${package_name/#@reactioncommerce\/}"
package_path="../dev-plugins/${package_name_without_org}"
full_package_path="$(cd ${package_path} && pwd)"
echo "\nUsing local package path ${full_package_path}"
echo "If this is not correct, specify the correct path as the second argument.\n"
fi

echo "Copying `${package_path}` package code into container..."
docker-compose exec web sh -c "mkdir -p ${container_destination_path}"
docker cp "${package_path}/." "${container_id}:${container_destination_path}"

# Then yalc link into this project
echo "Linking package into Example Storefront..."
docker-compose exec web sh -c "cd ${container_destination_path} && yalc push"
docker-compose exec web sh -c "cd /usr/local/src/app && yalc link ${package_name}"
fi

# Fool nodemon into thinking something has changed so that it restarts.
# Touch first file found in /pages with .js extension
echo "Restarting Example Storefront..."
docker-compose exec web sh -c "touch -c $(ls ./pages/*.js | head -n1)"
27 changes: 27 additions & 0 deletions bin/package-unlink
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

# Please Use Google Shell Style: https://google.github.io/styleguide/shell.xml

# ---- Start unofficial bash strict mode boilerplate
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -o errexit # always exit on error
set -o errtrace # trap errors in functions as well
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

# Unlink the yalc dependency, remove the package drectory and npm install
echo "Unlinking package from Example Storefront..."
docker-compose exec web sh -c "cd /usr/local/src/app && yalc remove ${package_name}"
docker-compose exec web sh -c "rm -rf /usr/local/src/app/node_modules/${package_name} && npm i"
docker-compose exec web sh -c "cd /usr/local/src/app && yalc update"

# Fool nodemon into thinking something has changed so that it restarts.
# Touch first file found in /pages with .js extension
echo "Restarting Example Storefront..."
docker-compose exec web sh -c "touch -c $(ls ./pages/*.js | head -n1)"
23 changes: 23 additions & 0 deletions bin/package-update
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
Copy link
Member

@mikemurray mikemurray Jan 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I this file needs execute permissions.


# Please Use Google Shell Style: https://google.github.io/styleguide/shell.xml

# ---- Start unofficial bash strict mode boilerplate
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -o errexit # always exit on error
set -o errtrace # trap errors in functions as well
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

# Unlink the yalc dependency, remove the package drectory and npm install
echo "Updating package from Example Storefront..."
docker-compose exec web sh -c "cd /usr/local/src/app && yalc update"

# Fool nodemon into thinking something has changed so that it restarts.
# Touch first file found in /src with .js extension
echo "Restarting Example Storefront..."
docker-compose exec web sh -c "touch -c $(ls ./src/*.js | head -n1)"
2 changes: 1 addition & 1 deletion docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ version: '3.4'

services:
web:
image: reactioncommerce/node-dev:12.14.1-v1
image: reactioncommerce/node-dev:12.14.1-v3
command: "./bin/start"
volumes:
- .:/usr/local/src/app
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5779,9 +5779,9 @@ inherits@2.0.3:
integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=

ini@^1.3.0, ini@^1.3.4, ini@~1.3.0:
version "1.3.5"
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927"
integrity sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==
version "1.3.7"
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.7.tgz#a09363e1911972ea16d7a8851005d84cf09a9a84"
integrity sha512-iKpRpXP+CrP2jyrxvg1kMUpXDyRUFDWurxbnVT1vQPx+Wz9uCYsMIqYuSBLV+PAaZG/d7kRLKRFc9oDMsH+mFQ==

inquirer@^3.0.0, inquirer@^3.0.6:
version "3.3.0"
Expand Down