-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #171 from Astrocoders/feat/update-setup
Enhancing contributor DX
- Loading branch information
Showing
76 changed files
with
5,900 additions
and
10,825 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,7 +61,13 @@ typings/ | |
.merlin | ||
lib/ | ||
*.bs.js | ||
.bsb.lock | ||
|
||
# Tooling | ||
_esy | ||
.vscode | ||
|
||
# Docusaurus | ||
build | ||
.bsb.lock | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Inspired from https://github.com/fhammerschmidt/bucklescript-monorepo/blob/master/Makefile | ||
|
||
ifeq ($(OS), Windows_NT) | ||
detected_OS := Windows | ||
else | ||
detected_OS := $(shell sh -c 'uname 2>/dev/null || echo Unknown') | ||
endif | ||
|
||
ifeq ($(detected_OS), Windows) | ||
BSB := ./node_modules/bs-platform/win32/bsb.exe | ||
endif | ||
ifeq ($(detected_OS), Linux) | ||
BSB := ./node_modules/bs-platform/linux/bsb.exe | ||
endif | ||
ifeq ($(detected_OS), Darwin) | ||
BSB := ./node_modules/bs-platform/darwin/bsb.exe | ||
endif | ||
|
||
BSEXTENSIONS := "ml,mli,re,rei" | ||
BSB_ARGS := -make-world | ||
SOURCE_DIRS_JSON := lib/bs/.sourcedirs.json | ||
BSDIRS = "$(shell jq -r 'include "./dirs"; dirs' $(SOURCE_DIRS_JSON))" | ||
|
||
all: serve | ||
|
||
serve: | ||
trap 'kill %1' INT TERM | ||
# BuckleScript doesn't like being run first. | ||
yarn workspace demo server & $(MAKE) watch | ||
|
||
$(SOURCE_DIRS_JSON): bsconfig.json | ||
$(BSB) -install | ||
|
||
bs: | ||
$(BSB) $(BSB_ARGS) 2>/dev/null || echo Hang | ||
|
||
watch: bs | ||
./node_modules/.bin/redemon --paths=$(BSDIRS) --verbose -e re $(MAKE) bs | ||
|
||
print-%: ; @echo $*=$($*) | ||
|
||
clean: | ||
$(BSB) -clean-world | ||
|
||
.PHONY: bs bsdirs all clean watch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,9 @@ Even the schemas we use are nothing more than constructors built-in in the langu | |
|
||
## Basic usage | ||
|
||
<details> | ||
<summary>Click for spoiler!</summary> | ||
|
||
Checkout https://github.com/Astrocoders/reform/blob/master/packages/demo/src/PostAddNext.re for a more complete demo | ||
|
||
```reason | ||
|
@@ -102,16 +105,16 @@ let make = () => { | |
PostAddForm.use( | ||
~validationStrategy=OnDemand, | ||
~schema={ | ||
PostAddForm.Validation.Schema([| | ||
StringMin(Title, 20), | ||
StringNonEmpty(Description), | ||
Custom( | ||
AcceptTerms, | ||
PostAddForm.Validation.(Schema( | ||
string(~min=20, ~minError="Title needs to be greater than 20", Title) | ||
+ nonEmpty(Description), | ||
+ custom( | ||
values => | ||
values.acceptTerms == false | ||
? Error("You must accept all the terms") : Valid, | ||
AcceptTerms, | ||
) | ||
|]); | ||
|])); | ||
}, | ||
~onSubmit= | ||
({state}) => { | ||
|
@@ -158,9 +161,83 @@ let make = () => { | |
}; | ||
``` | ||
|
||
</details> | ||
|
||
## Installation | ||
|
||
``` | ||
yarn add bs-reform reschema | ||
``` | ||
|
||
Then add it to bsconfig.json | ||
|
||
``` | ||
"bs-dependencies": [ | ||
"bs-reform", | ||
"reschema" | ||
] | ||
``` | ||
|
||
Then add lenses-ppx | ||
|
||
``` | ||
yarn add [email protected] -D | ||
``` | ||
|
||
And update your bsconfig.json with `ppx-flags` | ||
|
||
``` | ||
"ppx-flags": [ | ||
"lenses-ppx/ppx" | ||
] | ||
``` | ||
|
||
## Features | ||
|
||
- Hook API | ||
- Schema API | ||
- Type safe, `handleChange` properly infers the value of the field it is handling | ||
- Context Provider | ||
- Field component | ||
- Validation strategy, OnDemand and OnChange | ||
|
||
## What this is and why | ||
|
||
Code that deals with strongly typed forms can quickly become walls of repeated text. | ||
We created ReForm to be both deadly simple and to make forms sound good leveraging ReasonML's powerful typesytem. | ||
Even the schemas we use are nothing more than constructors built-in in the language itself with a small size footprint. | ||
|
||
#### Contributing | ||
|
||
Requisites: | ||
|
||
- jq | ||
- node | ||
- esy | ||
|
||
Setup your env with: | ||
|
||
``` | ||
$ esy | ||
``` | ||
|
||
Then: | ||
|
||
``` | ||
yarn install | ||
``` | ||
|
||
##### Running | ||
|
||
Run everything in watch mode and serve the `demo` app with: | ||
|
||
``` | ||
make serve | ||
``` | ||
|
||
#### Alternatives | ||
|
||
- The great https://github.com/alexfedoseev/re-formality | ||
- [Formality](https://github.com/alexfedoseev/re-formality) | ||
|
||
#### Publishing | ||
|
||
|
@@ -212,6 +289,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d | |
|
||
<!-- markdownlint-enable --> | ||
<!-- prettier-ignore-end --> | ||
|
||
<!-- ALL-CONTRIBUTORS-LIST:END --> | ||
|
||
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "root-reform", | ||
"version": "0.1.0", | ||
"sources": { | ||
"dir": "packages/demo/src", | ||
"subdirs": true | ||
}, | ||
"package-specs": { | ||
"module": "commonjs", | ||
"in-source": true | ||
}, | ||
"suffix": ".bs.js", | ||
"bs-dependencies": [ | ||
"bs-reform", | ||
"reschema", | ||
"reason-react", | ||
"reason-async-hook", | ||
"reason-promise" | ||
], | ||
"ppx-flags": ["lenses-ppx/ppx"], | ||
"reason": { | ||
"react-jsx": 3 | ||
}, | ||
"warnings": { | ||
"error": "+101" | ||
}, | ||
"refmt": 3 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module { | ||
"name": "bs-sourcedirs", | ||
"description": "Produce a comma-separated string list of the directories `bsb.exe` is aware of. Run with, e.g. `jq -r 'include \"./dirs\"; dirs' ./lib/bs/.sourcedirs.json`" | ||
}; | ||
|
||
def dirs: | ||
[.dirs, [.pkgs[][1]]] | flatten | join(","); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"dependencies": { | ||
"@opam/ocaml-lsp-server": "ocaml/ocaml-lsp:ocaml-lsp-server.opam", | ||
"@opam/reason": "*", | ||
"ocaml": "4.6.x" | ||
}, | ||
"resolutions": { | ||
"@opam/dune": "2.5.1" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.