Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dylanirlbeck/hello-ppx-bucklescript
Reason PPX starter project using bsb-native.
https://github.com/dylanirlbeck/hello-ppx-bucklescript
Last synced: 2 days ago
JSON representation
Reason PPX starter project using bsb-native.
- Host: GitHub
- URL: https://github.com/dylanirlbeck/hello-ppx-bucklescript
- Owner: dylanirlbeck
- License: mit
- Created: 2019-12-10T15:54:46.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-05-05T17:00:39.000Z (over 4 years ago)
- Last Synced: 2024-11-14T08:46:31.411Z (2 months ago)
- Language: Reason
- Homepage:
- Size: 1.8 MB
- Stars: 12
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hello-ppx-bucklescript
> I recommend checking out [my article](https://dev.to/dylanirlbeck/intro-to-ppxs-for-reason-newcomers-2829) about the basics of Reason PPXs and `hello-ppx-bucklescript`!
A project that includes the minimum configuration for a ppx called `hello`, using Reason and BuckleScript. Inspired by [hello-ppx-esy](https://github.com/jchavarri/hello-ppx-esy/).
`hello-ppx-bucklescript` implements a very basic ppx that transforms the `[%hello]` extension into the number literal `42`.
So, the code:```reason
let fourtyTwo = string_of_int([%hello])
```is transformed into:
```reason
let fourtyTwo = string_of_int(42)
```at compile time.
## Project structure
`src/` - contains the source code for the ppx. Check out [this blog post](https://blog.hackages.io/reasonml-ppx-8ecd663d5640) for more information on the implementation of `[%hello]`.
`tests/` - contains a single file, `Tests.re`, that prints out the value of the `[%hello]` ppx. You can verify that the output is correct by running `yarn test`.
`publish/` - the folder you publish to NPM which contains the ppx executable.
## Publishing your ppx
It's likely you'll want to share your ppx with the Reason community. That's great! The `publish/` directory contains boilerplate for publishing your project (ppx) to the NPM registry so that others can install it by doing
`npm i hello_ppx`
and adding the ppx flag to their bsconfig.json
`"ppx-flags": ["hello-ppx-bucklescript/ppx"]`
As the documentation of bsconfig.json says, ppx flags are specified by package_name/binary, which allows BuckleScript to find each ppx in in your node_modules (this also explains why we `npm i` each ppx). Thus, the most important part of this process is the generated binary for the ppx that is consumed by other developers. In our case, this binary is located at `publish/ppx`.
If you've never published on NPM before, I'd highly recommend checking out [this tutorial](https://eladnava.com/publishing-your-first-package-to-npm/).