Skip to content

Commit

Permalink
feat(build): added support for building a subset of the packages
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastien Dubois <[email protected]>
  • Loading branch information
dsebastien committed Mar 14, 2018
1 parent 51be4f6 commit 55ec4c1
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ If you want to test/validate your changes against the starter, then you can use
* update the starter: `npm run update-starter`
* run the starter: `npm run starter`

If you only want to build a subset of stark then you can
* execute one of the `build:stark-<name>` npm scripts; for example: `npm run build:stark-core` or `npm run build:stark-build`
* execute the `build` script through npm with the list of packages to build: `npm run build -- --packages=stark-core`
* execute the build script from the command line: `bash ./build.sh --packages=stark-core`


## Releasing a version
* commit all changes to include in the release
Expand Down
6 changes: 6 additions & 0 deletions build-functions.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/usr/bin/env bash

# Three-Fingered Claw technique :)
# Reference: https://stackoverflow.com/questions/1378274/in-a-bash-script-how-can-i-exit-the-entire-script-if-a-certain-condition-occurs
yell() { echo "$0: $*" >&2; }
die() { yell "$*"; exit 111; }
try() { "$@" || die "cannot $*"; }

#######################################
# Echo the passed message if verbose mode is enabled
# Arguments:
Expand Down
61 changes: 60 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,60 @@ for ARG in "$@"; do
TYPECHECK_ALL=false
;;
--packages=*)
# asked to build a subset of the packages
BUILD_ALL=false

# parse to identify the packages to build
PACKAGES_STR=${ARG#--packages=}
PACKAGES_STR=${ARG#--packages=}
PACKAGES=( ${PACKAGES_STR//,/ } )
PACKAGES_STR="${PACKAGES_STR//,/ }" # replace , by ' '
PACKAGES_STR="${PACKAGES_STR//;/ }" # replace ; by ' '
PACKAGES_STR="${PACKAGES_STR// /_}" # replace all spaces by '_'
PACKAGES_STR=`eval echo ${PACKAGES_STR} | sed -r 's/[_]+/_/g'` # replace all '_' by ''
PACKAGES_STR=`eval echo ${PACKAGES_STR} | sed -r 's/_$//g'` # replace last '_' if still there
# at this point PACKAGES_STR is (finally) clean :)
# it only contains '_' as delimiter

# Convert the string to an array
PACKAGES_TO_BUILD=()

OLD_IFS=$IFS # save old IFS value
IFS='_ ' # use '_' as character to split
read -r -a PACKAGES_TO_BUILD <<< ${PACKAGES_STR}
IFS=$OLD_IFS # restore IFS

unset PACKAGES_STR # not needed anymore
#echo "Packages to build: ${PACKAGES_TO_BUILD[*]}"

# Filtering package lists to only keep those that need to be built
FILTERED_PACKAGES=()
FILTERED_TSC_PACKAGES=()
FILTERED_NODE_PACKAGES=()
FILTERED_ALL_PACKAGES=()

for target in "${PACKAGES_TO_BUILD[@]}"; do
if containsElement "${target}" "${PACKAGES[@]}"; then
FILTERED_PACKAGES+=(${target})
fi
if containsElement "${target}" "${TSC_PACKAGES[@]}"; then
FILTERED_TSC_PACKAGES+=(${target})
fi
if containsElement "${target}" "${NODE_PACKAGES[@]}"; then
FILTERED_NODE_PACKAGES+=(${target})
fi
if containsElement "${target}" "${ALL_PACKAGES[@]}"; then
FILTERED_ALL_PACKAGES+=(${target})
fi
done
PACKAGES=("${FILTERED_PACKAGES[@]}")
TSC_PACKAGES=("${FILTERED_TSC_PACKAGES[@]}")
NODE_PACKAGES=("${FILTERED_NODE_PACKAGES[@]}")
ALL_PACKAGES=("${FILTERED_ALL_PACKAGES[@]}")

# if ALL_PACKAGES is empty then the input was incorrect
if [ ${#ALL_PACKAGES[@]} -eq 0 ]; then
die "No matching packages. Can't build anything :("
fi
;;
--bundle=*)
BUNDLE=( "${ARG#--bundle=}" )
Expand Down Expand Up @@ -91,6 +143,13 @@ logInfo "============================================="
logInfo "Building Stark version ${VERSION}"
logInfo "============================================="

if [[ ${BUILD_ALL} == true ]]; then
logInfo "> FULL build: ${ALL_PACKAGES[*]}"
else
logInfo "> PARTIAL build: ${PACKAGES_TO_BUILD[*]}"
fi
logInfo "============================================="

TSC=`pwd`/node_modules/.bin/tsc
logTrace "TSC Path: $TSC"
NGC="node --max-old-space-size=3000 `pwd`/node_modules/@angular/compiler-cli/src/main"
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
"postinstall:core": "cd packages/stark-core && npm install && cd ../..",
"postinstall:starter": "cd starter && npm install && cd ..",
"build": "sh ./build.sh",
"build:stark-build": "sh ./build.sh --packages=stark-build",
"build:stark-core": "sh ./build.sh --packages=stark-core",
"update-starter": "cd starter && npm install && cd ..",
"starter": "cd starter && npm start && cd .."
},
Expand Down

0 comments on commit 55ec4c1

Please sign in to comment.