Skip to content

Commit

Permalink
scripts: merge removeAnchors.sh and resetSolutions.sh (#457)
Browse files Browse the repository at this point in the history
* scripts: merge removeAnchors.sh and resetSolutions.sh

Keeping it all in a single `scripts/prepareExercises.sh` avoids
duplication.

Also remove the complex file finding; simply getting all source
files within the `exercises` directory is a perfect fit for what is
needed. This fixes Issue #430.

* Simplify scripts/prepareExercises.sh

* Add prepareExercises.sh to CI

---------

Co-authored-by: Miles Frain <[email protected]>
  • Loading branch information
softmoth and milesfrain authored Sep 6, 2023
1 parent 4edad29 commit 427f698
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 56 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,8 @@ jobs:
- name: Run tests
run: ./scripts/testAll.sh

- name: Remove anchors
run: ./scripts/removeAnchors.sh

- name: Run tests again
run: ./scripts/testAll.sh

- name: Reset solutions
run: ./scripts/resetSolutions.sh
- name: Prepare exercises
run: ./scripts/prepareExercises.sh

- name: Run tests again
run: ./scripts/testAll.sh
Expand Down
28 changes: 28 additions & 0 deletions scripts/prepareExercises.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

# This script removes meta information that is not intended for readers of the book

# Echo commands to shell
set -x
# Exit on first failure
set -e

# For all chapters
for d in exercises/chapter*; do
# All .purs & .js files of chapter exercises
FILES=$(find $d/src $d/test -name '*.purs' -o -name '*.js')

for f in $FILES; do
# Delete lines starting with an 'ANCHOR' comment
perl -ni -e 'print if !/^\s*(--|\/\/) ANCHOR/' $f

# Delete lines with a note to delete them
perl -ni -e 'print if !/This line should have been automatically deleted/' $f
done

# If there's a no-peeking directory
if [ -d $d/test/no-peeking ]; then
# Move 'no-peeking' sources out of the compilation path
mv $d/test/no-peeking $d
fi
done
23 changes: 0 additions & 23 deletions scripts/removeAnchors.sh

This file was deleted.

22 changes: 0 additions & 22 deletions scripts/resetSolutions.sh

This file was deleted.

5 changes: 2 additions & 3 deletions text/chapter2.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ Now that you've installed the necessary development tools, clone this book's rep
git clone https://github.com/purescript-contrib/purescript-book.git
```

The book repo contains PureScript example code and unit tests for the exercises that accompany each chapter. There's some initial setup required to reset the exercise solutions so they are ready to be solved by you. Use the `resetSolutions.sh` script to simplify this process. While at it, you should also strip out all the anchor comments with the `removeAnchors.sh` script (these anchors are used for copying code snippets into the book's rendered markdown, and you probably don't need this clutter in your local repo):
The book repo contains PureScript example code and unit tests for the exercises that accompany each chapter. There's some initial setup required to reset the exercise solutions so they are ready to be solved by you. Use the `prepareExercises.sh` script to simplify this process:

```sh
cd purescript-book
./scripts/resetSolutions.sh
./scripts/removeAnchors.sh
./scripts/prepareExercises.sh
git add .
git commit --all --message "Exercises ready to be solved"
```
Expand Down

0 comments on commit 427f698

Please sign in to comment.