Skip to content

Commit

Permalink
Merge pull request #171 from Astrocoders/feat/update-setup
Browse files Browse the repository at this point in the history
Enhancing contributor DX
  • Loading branch information
fakenickels committed Jul 30, 2020
2 parents 6121ecc + 56532f7 commit 296c507
Show file tree
Hide file tree
Showing 76 changed files with 5,900 additions and 10,825 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ typings/
.merlin
lib/
*.bs.js
.bsb.lock

# Tooling
_esy
.vscode

# Docusaurus
build
.bsb.lock


45 changes: 45 additions & 0 deletions Makefile
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
92 changes: 85 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}) => {
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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!
28 changes: 28 additions & 0 deletions bsconfig.json
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
}
7 changes: 7 additions & 0 deletions dirs.jq
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(",");
10 changes: 10 additions & 0 deletions esy.json
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"
}
}
3 changes: 3 additions & 0 deletions esy.lock/.gitattributes

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions esy.lock/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 296c507

Please sign in to comment.