Skip to content

Commit 0c0b5ed

Browse files
authored
Add newRecipe script (#186)
* add -node-watch to makefile * add scripts/newRecipe.sh * update readmes * remove memo recipe * Don't build after copy
1 parent e1deb7d commit 0c0b5ed

File tree

5 files changed

+132
-46
lines changed

5 files changed

+132
-46
lines changed

CONTRIBUTING.md

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,18 @@ Follow these instructions for contributing new recipes. The Goal headers indicat
1414

1515
#### Goal 2: Setup a New Recipe's Boilerplate by Copying a Current Similar One
1616

17-
1. Pick an existing recipe to duplicate as a starting point. The `HelloLog` recipe is the simplest and is set up to work on both Node.js and Browser backends.
18-
- In the examples that follow, we'll assume that you copied the `HelloLog` recipe and wish to use the "Unique Recipe Name" of `MyNewRecipe`
17+
1. Pick an existing recipe to duplicate as a starting point. Here are some suggestions:
18+
- `HelloLog` - If your recipe is compatible with both Node.js and web browser backends. _Note:_ Logging to the console **is** supported by **both** backends.
19+
- `ReadPrintFileContentsNode` - If your recipe is **only** compatible with the `Node.js` backend.
20+
- `DiceCLI` - If your recipe is **only** compatible with the `Node.js` backend **and** requires user interact for testing (e.g. a CLI app). This is to prevent our CI process from blocking while waiting for input during testing.
21+
- `WindowPropertiesJs` - If your recipe is **only** compatible with the web browser backend.
22+
- If your recipe targets a particular web framework:
23+
- `HelloConcur`
24+
- `HelloHalogenHooks`
25+
- `HelloReactHooks`
26+
1. Run the recipe creation script. Substitute `MyNewRecipe` with your recipe name:
1927
```
20-
cd recipes
21-
cp -r HelloLog MyNewRecipe
22-
```
23-
1. Rename the copied folder to the "Unique Recipe Name" assigned in the original issue.
24-
1. Depending on the backend-compatibility of your recipe, follow the instructions below:
25-
1. If your recipe is incompatible with the browser environment, delete the `web` directory.
26-
- If your recipe uses `node-*` libraries, it is incompatible with the browser.
27-
- Logging to the console **is** supported in the browser.
28-
1. If your recipe is incompatible with the Node.js backend, delete the `nodeSupported.md` file.
29-
1. If your recipe is compatible with Node.js, but the resulting program should not be run during CI (e.g. a program that parses command-line arguments), then rename `nodeSupported.md` to `nodeSupportedSkipCI.md`.
30-
1. Replace all usages of the original recipe's name with your new recipe's name. For example:
31-
```
32-
grep -rl 'HelloLog' MyNewRecipe | xargs sed -i 's/HelloLog/MyNewRecipe/g'
28+
./scripts/newRecipe.sh MyNewRecipe HelloLog
3329
```
3430
3531
#### Goal 3: Implement and Submit the Recipe

README.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,48 +36,49 @@ Use "make RecipeName-target" to run a recipe
3636
3737
=== Node Recipes ===
3838
make ReadPrintFileContents-node
39-
make HelloWorld-node
39+
make HelloLog-node
4040
...
4141
4242
=== Web Recipes ===
4343
make WindowProperties-web
44-
make HelloWorld-web
44+
make HelloLog-web
4545
...
4646
```
4747

4848
Then simply copy and paste one of the listed commands. For example:
4949

5050
Running a node-compatible recipe:
5151
```
52-
> make HelloWorld-node
53-
=== Running HelloWorld on the Node.js backend ===
52+
> make HelloLog-node
53+
=== Running HelloLog on the Node.js backend ===
5454
[info] Installation complete.
5555
[info] Build succeeded.
5656
Hello world!
5757
```
5858

5959
Running a web-compatible recipe:
6060
```
61-
> make HelloWorld-web
62-
=== Building HelloWorld ===
61+
> make HelloLog-web
62+
=== Building HelloLog ===
6363
[info] Installation complete.
6464
[info] Build succeeded.
65-
=== Launching HelloWorld in the web browser ===
65+
=== Launching HelloLog in the web browser ===
6666
...
6767
```
6868

6969
## Current Recipe Suffixes
7070

7171
| Recipes ending with ... | ... mean the following approach/library is used |
7272
| - | - |
73-
| `HalogenClassic` | Component-style Halogen |
74-
| `HalogenHooks` | Hooks-style Halogen |
75-
| `ReactClassic` | Component-style React via [react-basic](https://github.com/lumihq/purescript-react-basic) |
76-
| `ReactHooks` | Hooks-style React via [react-basic](https://github.com/lumihq/purescript-react-basic) |
77-
| `Js` | Run plain PureScript on the web without a web framework |
78-
| `Log` | Log content to both the browser's console and the terminal |
79-
| `Node` | Run PureScript on Node.js where no user interaction occurs |
80-
| `CLI` | Run PureScript on Node.js with user interaction |
73+
| `HalogenClassic` | [Component-style Halogen](https://github.com/purescript-halogen/purescript-halogen/) |
74+
| `HalogenHooks` | [Hooks-style Halogen](https://github.com/thomashoneyman/purescript-halogen-hooks/) |
75+
| `ReactClassic` | [Component-style React](https://github.com/lumihq/purescript-react-basic-classic) via [react-basic](https://github.com/lumihq/purescript-react-basic) |
76+
| `ReactHooks` | [Hooks-style React](https://github.com/spicydonuts/purescript-react-basic-hooks/) via [react-basic](https://github.com/lumihq/purescript-react-basic) |
77+
| `Concur` | [Concur](https://github.com/purescript-concur/purescript-concur-react) |
78+
| `Js` | Run plain PureScript **only** on the web (no node.js) without a web framework |
79+
| `Log` | Log content to **both** the browser's dev console and the terminal |
80+
| `Node` | Run PureScript **only** on Node.js where no user interaction occurs |
81+
| `CLI` | Run PureScript **only** on Node.js with user interaction |
8182

8283
## Recipes
8384

makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,18 @@ nodeCompatSkipCI = $(call recipeDir,$1)/nodeSupportedSkipCI.md
139139
> exit 1
140140
> fi
141141

142-
.PHONY: %-node
143142
# Runs recipe as node.js console app
143+
.PHONY: %-node
144144
%-node: $(call recipeDir,%) %-nodeCompatible
145145
> @echo === Running $* on the Node.js backend ===
146146
> spago -x $(call recipeSpago,$*) run --main $(call main,$*)
147147

148+
# Watches for changes and rebuilds and reruns recipe as node.js console app
149+
.PHONY: %-node-watch
150+
%-node-watch: $(call recipeDir,%) %-nodeCompatible
151+
> @echo === Watching to build and run $* on the Node.js backend ===
152+
> spago -x $(call recipeSpago,$*) run --main $(call main,$*) -w
153+
148154
# Functions for browser-comptabile recipes that help generate paths
149155

150156
webDir = $(call recipeDir,$1)/web

scripts/ReadmeContent.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,45 +36,46 @@ Use "make RecipeName-target" to run a recipe
3636
3737
=== Node Recipes ===
3838
make ReadPrintFileContents-node
39-
make HelloWorld-node
39+
make HelloLog-node
4040
...
4141
4242
=== Web Recipes ===
4343
make WindowProperties-web
44-
make HelloWorld-web
44+
make HelloLog-web
4545
...
4646
```
4747

4848
Then simply copy and paste one of the listed commands. For example:
4949

5050
Running a node-compatible recipe:
5151
```
52-
> make HelloWorld-node
53-
=== Running HelloWorld on the Node.js backend ===
52+
> make HelloLog-node
53+
=== Running HelloLog on the Node.js backend ===
5454
[info] Installation complete.
5555
[info] Build succeeded.
5656
Hello world!
5757
```
5858

5959
Running a web-compatible recipe:
6060
```
61-
> make HelloWorld-web
62-
=== Building HelloWorld ===
61+
> make HelloLog-web
62+
=== Building HelloLog ===
6363
[info] Installation complete.
6464
[info] Build succeeded.
65-
=== Launching HelloWorld in the web browser ===
65+
=== Launching HelloLog in the web browser ===
6666
...
6767
```
6868

6969
## Current Recipe Suffixes
7070

7171
| Recipes ending with ... | ... mean the following approach/library is used |
7272
| - | - |
73-
| `HalogenClassic` | Component-style Halogen |
74-
| `HalogenHooks` | Hooks-style Halogen |
75-
| `ReactClassic` | Component-style React via [react-basic](https://github.com/lumihq/purescript-react-basic) |
76-
| `ReactHooks` | Hooks-style React via [react-basic](https://github.com/lumihq/purescript-react-basic) |
77-
| `Js` | Run plain PureScript on the web without a web framework |
78-
| `Log` | Log content to both the browser's console and the terminal |
79-
| `Node` | Run PureScript on Node.js where no user interaction occurs |
80-
| `CLI` | Run PureScript on Node.js with user interaction |
73+
| `HalogenClassic` | [Component-style Halogen](https://github.com/purescript-halogen/purescript-halogen/) |
74+
| `HalogenHooks` | [Hooks-style Halogen](https://github.com/thomashoneyman/purescript-halogen-hooks/) |
75+
| `ReactClassic` | [Component-style React](https://github.com/lumihq/purescript-react-basic-classic) via [react-basic](https://github.com/lumihq/purescript-react-basic) |
76+
| `ReactHooks` | [Hooks-style React](https://github.com/spicydonuts/purescript-react-basic-hooks/) via [react-basic](https://github.com/lumihq/purescript-react-basic) |
77+
| `Concur` | [Concur](https://github.com/purescript-concur/purescript-concur-react) |
78+
| `Js` | Run plain PureScript **only** on the web (no node.js) without a web framework |
79+
| `Log` | Log content to **both** the browser's dev console and the terminal |
80+
| `Node` | Run PureScript **only** on Node.js where no user interaction occurs |
81+
| `CLI` | Run PureScript **only** on Node.js with user interaction |

scripts/newRecipe.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env bash
2+
3+
# Exit on first failure
4+
set -e
5+
6+
print_error() {
7+
cat <<HELP
8+
Error: $1
9+
10+
Usage:
11+
./scripts/newRecipe.sh <new recipe name> <optional recipe to copy>
12+
13+
Examples:
14+
./scripts/newRecipe.sh MyNewRecipe
15+
./scripts/newRecipe.sh MyNewRecipe HelloHalogenHooks
16+
./scripts/newRecipe.sh MyNewRecipe recipes/HelloHalogenHooks/
17+
HELP
18+
exit 1
19+
}
20+
21+
# Valid number of arguments is either 1 or 2
22+
[ $# -eq 0 ] && print_error 'No arguments'
23+
[ $# -gt 2 ] && print_error 'Too many arguments'
24+
25+
# Use a default original recipe if one is not provided.
26+
# Just take basename of recipe path.
27+
orig=$(basename ${2:-HelloLog})
28+
29+
echo "Creating new recipe $1 from $orig"
30+
31+
# Echo all following script commands
32+
set -x
33+
34+
# Copy original recipe to new recipe directory
35+
cp -r recipes/$orig recipes/$1
36+
37+
# Replace all usages of the original recipe's name with the new recipe's name
38+
grep -rl $orig recipes/$1 | xargs sed -i "s/$orig/$1/g"
39+
40+
41+
# ====== Additional instructions =======
42+
43+
# Disable echo of all following script commands
44+
set +x
45+
46+
echo --- Some helpful development commands for this recipe: ---
47+
48+
# Basic node
49+
[ -f recipes/$1/nodeSupported.md ] && cat <<CMD
50+
51+
* Watch for changes and rebuild and re-run in node.js:
52+
make $1-node-watch
53+
CMD
54+
55+
# Node CLI - Watching causes issues with this
56+
[ -f recipes/$1/nodeSupportedSkipCI.md ] && cat <<CMD
57+
58+
* Re-run in node.js:
59+
make $1-node
60+
CMD
61+
62+
# Web
63+
[ -d recipes/$1/web ] && cat <<CMD
64+
65+
* Launch in web browser (will refresh upon rebuild):
66+
make $1-web
67+
68+
* Watch for changes and rebuild (only necessary if editing without purs-ide):
69+
make $1-build-watch
70+
CMD
71+
72+
# Common
73+
cat <<CMD
74+
75+
--------- Common to all recipe types: ---------
76+
77+
* Manual rebuild:
78+
make $1-build
79+
80+
* Regenerate recipe table (run this after editing recipes/$1/README.md):
81+
make readme
82+
CMD

0 commit comments

Comments
 (0)