Skip to content

Commit 427f698

Browse files
softmothmilesfrain
andauthored
scripts: merge removeAnchors.sh and resetSolutions.sh (#457)
* 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 <miles.frain@colorado.edu>
1 parent 4edad29 commit 427f698

File tree

5 files changed

+32
-56
lines changed

5 files changed

+32
-56
lines changed

.github/workflows/tests.yml

+2-8
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,8 @@ jobs:
4949
- name: Run tests
5050
run: ./scripts/testAll.sh
5151

52-
- name: Remove anchors
53-
run: ./scripts/removeAnchors.sh
54-
55-
- name: Run tests again
56-
run: ./scripts/testAll.sh
57-
58-
- name: Reset solutions
59-
run: ./scripts/resetSolutions.sh
52+
- name: Prepare exercises
53+
run: ./scripts/prepareExercises.sh
6054

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

scripts/prepareExercises.sh

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
3+
# This script removes meta information that is not intended for readers of the book
4+
5+
# Echo commands to shell
6+
set -x
7+
# Exit on first failure
8+
set -e
9+
10+
# For all chapters
11+
for d in exercises/chapter*; do
12+
# All .purs & .js files of chapter exercises
13+
FILES=$(find $d/src $d/test -name '*.purs' -o -name '*.js')
14+
15+
for f in $FILES; do
16+
# Delete lines starting with an 'ANCHOR' comment
17+
perl -ni -e 'print if !/^\s*(--|\/\/) ANCHOR/' $f
18+
19+
# Delete lines with a note to delete them
20+
perl -ni -e 'print if !/This line should have been automatically deleted/' $f
21+
done
22+
23+
# If there's a no-peeking directory
24+
if [ -d $d/test/no-peeking ]; then
25+
# Move 'no-peeking' sources out of the compilation path
26+
mv $d/test/no-peeking $d
27+
fi
28+
done

scripts/removeAnchors.sh

-23
This file was deleted.

scripts/resetSolutions.sh

-22
This file was deleted.

text/chapter2.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ Now that you've installed the necessary development tools, clone this book's rep
2424
git clone https://github.com/purescript-contrib/purescript-book.git
2525
```
2626

27-
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):
27+
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:
2828

2929
```sh
3030
cd purescript-book
31-
./scripts/resetSolutions.sh
32-
./scripts/removeAnchors.sh
31+
./scripts/prepareExercises.sh
3332
git add .
3433
git commit --all --message "Exercises ready to be solved"
3534
```

0 commit comments

Comments
 (0)