Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Commit

Permalink
chore(scripts): foreach.sh --up (aws#5648)
Browse files Browse the repository at this point in the history
Add support for `--up` in `foreach.sh` which will execute the command for the current module and all its dependencies (instead of the entire repo).

Use this new feature in `buildup` so from now, `buildup` is resumable. Restart can be done through `./buildup --restart`.

Update CONTRIBUTING guide.
  • Loading branch information
Elad Ben-Israel authored Jan 6, 2020
1 parent 9472e09 commit 3b5959f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 15 deletions.
13 changes: 11 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,17 @@ if a task fails, it will stop, and then to resume, simply run `foreach.sh` again
To reset the session (either when all tasks finished or if you wish to run a different session), run:

```console
$ rm -f ~/.foreach.*
$ scripts/foreach.sh --reset
```

This will effectively delete the state files.
If you wish to run a command only against a module's dependency closure, use:

```console
$ cd packages/my-module
$ ../scripts/foreach.sh --up COMMAND
```

This will execute `COMMAND` against `my-module` and all it's deps (in a topological order of course).

### Jetbrains support (WebStorm/IntelliJ)

Expand Down Expand Up @@ -375,6 +382,8 @@ $ cd packages/@aws-cdk/aws-ec2
$ ../../../scripts/buildup
```

Note that `buildup` uses `foreach.sh`, which means it's resumable. If your build fails and you wish to resume, just run `buildup` again. If you wish to restart, run `buildup --restart`.

### Quick Iteration

After you've built the modules you want to work on once, use `lr watch` for each module that you are modifying.
Expand Down
25 changes: 17 additions & 8 deletions scripts/buildup
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
#!/bin/bash
set -euo pipefail
scriptdir=$(cd $(dirname $0) && pwd)

echo "************************************************************"
echo " buildup usage:"
echo " - execute 'buildup' again to resume after failure"
echo " - execute 'buildup --restart' to restart"
echo ""
echo " for advanced usage, see ${scriptdir}/foreach.sh"
echo "************************************************************"

if ! [ -x "$(command -v yarn)" ]; then
echo "yarn is not installed. Install it from here- https://yarnpkg.com/en/docs/install."
exit 1
if [ "${1:-}" == "--restart" ] || [ "${1:-}" == "--reset" ]; then
${scriptdir}/foreach.sh --reset
fi

export NODE_OPTIONS="--max-old-space-size=4096 ${NODE_OPTIONS:-}"

scriptdir=$(cd $(dirname $0) && pwd)
export PATH=$(cd $scriptdir && npm bin):$PATH
scope=$(${scriptdir}/current-scope)
exec lerna run build --scope ${scope} --include-dependencies
${scriptdir}/foreach.sh --up yarn build
${scriptdir}/foreach.sh --reset

echo "************************************************************"
echo "buildup done"
echo "************************************************************"
25 changes: 20 additions & 5 deletions scripts/foreach.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
# if a task fails, it will stop, and then to resume, simply run `foreach.sh` again (with or without the same command).
#
# to reset the session (either when all tasks finished or if you wish to run a different session), run:
# rm -f ~/.foreach.*
# foreach.sh --reset
#
# this will effectively delete the state files.
# to run the command only against the current module and its dependencies:
# foreach.sh --up COMMAND
#
# --------------------------------------------------------------------------------------------------
set -euo pipefail
scriptdir=$(cd $(dirname $0) && pwd)
statedir="${scriptdir}"
statefile="${statedir}/.foreach.state"
commandfile="${statedir}/.foreach.command"
command_arg="${@:-}"
base=$PWD

function heading {
Expand All @@ -44,6 +44,21 @@ if [[ "${1:-}" == "--reset" ]]; then
exit 0
fi

up=""
up_desc=""
if [[ "${1:-}" == "--up" ]]; then
if [ ! -f package.json ]; then
echo "--up can only be executed from within a module directory (looking for package.json)"
exit 1
fi

scope=$(node -p "require('./package.json').name")
up=" --scope ${scope} --include-dependencies"
up_desc="('${scope}' and its dependencies)"
shift
fi

command_arg="${@:-}"

if [ -f "${statefile}" ] && [ -f "${commandfile}" ]; then
command="$(cat ${commandfile})"
Expand All @@ -57,8 +72,8 @@ fi
if [ ! -f "${statefile}" ] && [ ! -f "${commandfile}" ]; then
if [ ! -z "${command_arg}" ]; then
command="${command_arg}"
success "starting new session"
node_modules/.bin/lerna ls --all --toposort -p > ${statefile}
success "starting new session ${up_desc}"
${scriptdir}/../node_modules/.bin/lerna ls --all ${up} --toposort -p > ${statefile}
echo "${command}" > ${commandfile}
else
error "no active session, use \"$(basename $0) COMMAND\" to start a new session"
Expand Down

0 comments on commit 3b5959f

Please sign in to comment.