Skip to content

Commit 4161aa5

Browse files
authored
local-install.sh script for development purposes (#111)
* local-install.sh script for development purposes * code review changes
1 parent 3aef357 commit 4161aa5

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

scripts/local-install.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env bash
2+
set -eo pipefail
3+
4+
## usage: local-install.sh <package-to-install-dir> <consuming-app-dir>'
5+
##
6+
## examples:
7+
##
8+
## Install js-client-sdk-common changes into js-client-sdk:
9+
## ./scripts/local-install.sh . ../js-client-sdk
10+
##
11+
## Install js-client-sdk changes into a test app
12+
## ./scripts/local-install.sh ../js-client-sdk ../test-apps/my-react-app
13+
##
14+
## Install js-client-sdk-common changes into a test app
15+
## ./scripts/local-install.sh . ../js-client-sdk && ./scripts/local-install.sh ../js-client-sdk ../test-apps/my-react-app
16+
17+
if ! command -v jq &> /dev/null; then
18+
echo "jq must be installed before using this script"
19+
exit 1
20+
fi
21+
22+
if [[ "$1" = "" || "$2" = "" ]]; then
23+
echo 'usage: local-install.sh <package-to-install-dir> <consuming-app-dir>'
24+
exit 1
25+
fi
26+
27+
if [ ! -d "$1" ]; then
28+
echo "$1 is not a directory"
29+
exit 1
30+
fi
31+
32+
if [ ! -f "$1/package.json" ]; then
33+
echo "$1 is not an npm package"
34+
exit 1
35+
fi
36+
37+
if [ ! -d "$2" ]; then
38+
echo "$2 is not a directory"
39+
exit 1
40+
fi
41+
42+
if [ ! -f "$2/package.json" ]; then
43+
echo "$2 is not an npm package"
44+
exit 1
45+
fi
46+
47+
### Create local package via "npm pack"
48+
pushd "$1" > /dev/null
49+
mkdir -p /tmp/packages
50+
PACKAGE_DIR=/tmp/packages/"$(basename "$(pwd)")"
51+
rm -rf "${PACKAGE_DIR}" /tmp/pack.out && npm pack > /tmp/pack.out
52+
COMPRESSED_PACKAGE="$(tail -1 /tmp/pack.out)"
53+
tar -xzf "${COMPRESSED_PACKAGE}"
54+
rm "${COMPRESSED_PACKAGE}"
55+
mv package "${PACKAGE_DIR}"
56+
PACKAGE_NAME=$(cat ./package.json | jq -r '.name')
57+
popd > /dev/null
58+
59+
### Install local package to target package
60+
pushd "$2" > /dev/null
61+
TARGET_DIR="$(pwd)"
62+
rm -rf node_modules/.cache
63+
yarn remove "${PACKAGE_NAME}"
64+
yarn add "${PACKAGE_DIR}" --exact
65+
popd > /dev/null
66+
67+
echo "$PACKAGE_DIR installed in $TARGET_DIR"

0 commit comments

Comments
 (0)