All Projects β†’ nickzuber β†’ Add Reason

nickzuber / Add Reason

Licence: mit
✨🐒 Dead simple tool for seamlessly integrating ReasonML into existing JavaScript projects.

Programming Languages

javascript
184084 projects - #8 most used programming language
ocaml
1615 projects
reason
219 projects
bucklescript
41 projects

Projects that are alternatives of or similar to Add Reason

Ocamlverse.github.io
Documentation of everything relevant in the OCaml world
Stars: ✭ 117 (-30.36%)
Mutual labels:  reasonml
Interopdotnet
Cross-platform AnyCPU P/Invoke for .NET
Stars: ✭ 131 (-22.02%)
Mutual labels:  interop
Bs Loader
πŸ“» Bucklescript loader for Webpack and Jest
Stars: ✭ 146 (-13.1%)
Mutual labels:  reasonml
Reroute
a fast, declarative microrouter for reason-react
Stars: ✭ 120 (-28.57%)
Mutual labels:  reasonml
Colore
A powerful C# library for Razer Chroma's SDK
Stars: ✭ 121 (-27.98%)
Mutual labels:  interop
Pure
React in pure Reason that targets native platforms.
Stars: ✭ 135 (-19.64%)
Mutual labels:  reasonml
Wonder Editor
Functional 3D Webgl Editor
Stars: ✭ 113 (-32.74%)
Mutual labels:  reasonml
Rebolt
Framework for developing apps in ReasonML
Stars: ✭ 161 (-4.17%)
Mutual labels:  reasonml
Brisk Reconciler
React.js-like reconciler implemented in OCaml/Reason
Stars: ✭ 124 (-26.19%)
Mutual labels:  reasonml
Reason Expo
ReasonML bindings for Expo
Stars: ✭ 140 (-16.67%)
Mutual labels:  reasonml
Braid
A functional language with Reason-like syntax that compiles to Go.
Stars: ✭ 121 (-27.98%)
Mutual labels:  reasonml
Reactivetradercloud
Real-time FX trading showcase by Adaptive.
Stars: ✭ 1,664 (+890.48%)
Mutual labels:  interop
Reason Graphql
GraphQL server in pure Reason (Bucklescript)
Stars: ✭ 137 (-18.45%)
Mutual labels:  reasonml
Re Tailwind
Brings TailwindCSS https://tailwindcss.com to ReasonML
Stars: ✭ 118 (-29.76%)
Mutual labels:  reasonml
Bs Blabla
BuckleScript `[@bs.blabla]` attributes explained with examples
Stars: ✭ 151 (-10.12%)
Mutual labels:  reasonml
Rescript Recoil
Zero-cost bindings to Facebook's Recoil library
Stars: ✭ 115 (-31.55%)
Mutual labels:  reasonml
Pesy
Project configuration for esy
Stars: ✭ 132 (-21.43%)
Mutual labels:  reasonml
Fullstack Reason
A demo project that shows a fullstack ReasonML/OCaml app–native binary + webapp
Stars: ✭ 164 (-2.38%)
Mutual labels:  reasonml
Sharpbgfx
C# bindings for the bgfx graphics library
Stars: ✭ 154 (-8.33%)
Mutual labels:  interop
Reason Apollo Hooks
Deprecated in favor of https://github.com/reasonml-community/graphql-ppx
Stars: ✭ 140 (-16.67%)
Mutual labels:  reasonml
add-reason

Simple tool for seamlessly integrating ReasonML into your existing JavaScript projects.

This is an easy to use cli tool that helps you seamlessly interop ReasonML code with an existing JavaScript project. You tell us where your ReasonML code is, and we'll handle the rest!

Installation

$ npm install -g add-reason

or

$ yarn global add add-reason

Usage

The most basic use case would be to simply add an interop between your JavaScript and ReasonML code. In this case, you'd probably want to go with the setup command and specify the location of your ReasonML code and optionally include the name of a package you'd want to give it.

Let's assume you had file structure like this, where all your ReasonML code is located in a single directory called reasonCode or something:

myCoolProject/
β”œβ”€β”€ reasonCode/
β”‚   β”œβ”€β”€ index.re
β”‚   β”œβ”€β”€ file1.re
β”‚   β”œβ”€β”€ file2.re
β”‚   └── utils/
β”‚       β”œβ”€β”€ fs.re
β”‚       └── path.re
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ index.js
β”‚   β”œβ”€β”€ main.js
β”‚   β”œβ”€β”€ example1.js
β”‚   β”œβ”€β”€ example2.js
β”‚   └── example3.js
└── etc/

You'd simply go to your project root and type:

$ add-reason setup ./reasonCode

or, since setup is the default command, you can even write

$ add-reason ./reasonCode

and that's it! Now you can compile you ReasonML code with

$ npm run build-reason
# or
$ bsb -make-world

and then import your compiled ReasonML code with

const reasonCode = require('reasonCode');
// ...

If you don't specify a package name you want to give your code, we just use the directory name. You can choose any name you want though, so long as it doesn't collide with the name of a package you already have in your node_modules/!

$ add-reason setup ./reasonCode my-cool-code
const myCoolCode = require('my-cool-code');
// ...

You can do a variety of other things too, the more basic usage is:

Usage: add-reason [command] [options]

  Commands:

    setup <directory> [package-name]  set up Reason directory, config files, and symlink
    link <directory> [package-name]   create a symlink with the given package name
    linter <directory>                create a merlin file for linting your ReasonML code
    config <directory>                create a bsconfig file for building your ReasonML code

  Options:

    -h, --help     output usage information
    -V, --version  output the version number
    --no-linking   don't create the symlink to your compiled ReasonML code
    --in-source    change target to in-source rather than a compiled directory

How It Works

This is a very simple tool. All it does is make sure you have the typical basic config related files for writing ReasonML and creates a symlink in your node_modules/ targeting your compiled ReasonML code so you can easily import and use it within your JavaScript.

There are a few steps that happen when you call setup:

  1. Prepare target directory
  2. Make sure we have a config file
  3. Make sure we have a linting file
  4. Create symlink
  5. Create build command
  6. Create postinstall
  7. Check for bs-platform

Preparing the target directory just makes sure that the path ./lib/js/[your ReasonML directory name] exists. This is where BuckleScript will put your compiled ReasonML/OCaml code, so this is the spot where we want to create a symlink later to down the line.

Next we just want to make sure you're all set up with at least the most basic of configurations. We check to see if you have a .merlin file for linting and a bsconfig.json for ReasonML configuration. If you don't, no worries! We will just create a basic file for each one that you don't have and set you up with it.

Then we just create that symlink that hooks in your compiled ReasonML code to your node_modules/ for easy access. We also create a postinstall script that will add this symlink every time someone installs your project, given that the link doesn't already exist. You always have the option to skip this symlinking step with the --no-linking flag too if you want.

We also add a script to your package.json called build-reason that simply uses Bucklescript to compile your code. So you can then call npm run build-reason after calling setup to have your ReasonML code compiled and ready to use!

The last thing that we do is check to make sure that you have bs-platform integrated into your project. If you don't have it globally installed and linked to your current project, you're prompted to install and link it with

$ npm install -g bs-platform
$ npm link bs-platform

FAQ

I ran setup and everything worked fine, but when I try to import my code I get Error: Cannot find module

This is almost always because your ReasonML directory doesn't have an index.re file. Normally, this isn't a necessary thing, but if you want to be able to write

const reasonCode = require('reasonCode');
// ...

your directory needs to have the index file for node to grab! You don't need to have an index.re file though, instead you can just access the files you want directly.

const reasonCode = require('reasonCode/file1.js');
// ...

I ran setup but my code isn't compiled!

Don't forget to compile your code using bs-platform! You can use the build-reason command that should have been added to your package.json after using the setup command.

$ npm run build-reason

Remember that add-reason doesn't actually compile your code or deal with that bit. Alternatively, you can compile your code yourself manually with BuckleScript something like

$ bsb -make-world

License

This software is free to use under the MIT License. See this reference for license text and copyright information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].