2 # Author: Bill Erickson <berickxx@gmail.com>
4 # Script to rebuild the set of Angular dependencies.
5 # 1. Remove node_modules
6 # 2. Remove dependencies and devDependencies from package.json
7 # 3. Install @angular/core using the requested version of angular.
8 # 4. Reinstall dependencies and devDependencies
10 # Building in this fashion, where we start with a single Angular package
11 # allows the other packages to better determine the version to use.
13 # Script requires 'jq' program (sudo apt-get install jq) for
14 # parsing and manipulating JSON.
15 # ----------------------------------------------------------------------------
17 ANGULAR_VERSION="" # Example ^8.0.0
28 -v Angular version string
34 while getopts "v:h" opt; do
36 v) ANGULAR_VERSION="$OPTARG";;
41 if [ -z "$ANGULAR_VERSION" ]; then
42 echo "Angular version required"
46 echo "Removing node_modules"
49 echo "Removing package-lock.json"
50 rm -f package-lock.json
52 # Exctract the dependencies from package.json
53 DEPS=$(jq '.dependencies | keys' package.json | tr '[],"' ' ' | xargs);
54 DEV_DEPS=$(jq '.devDependencies | keys' package.json | tr '[],"' ' ' | xargs);
56 # Remove deps from package.json
57 jq '.devDependencies={} | .dependencies={}' package.json > package.wip.json
58 mv package.wip.json package.json
60 # Start by installing the version of Angular we want to use
61 npm install @angular/cli@$ANGULAR_VERSION @angular/core@$ANGULAR_VERSION
63 # Then let NPM figure out the versioning for the rest.
65 npm install --save $DEPS
66 npm install --save-dev $DEV_DEPS