{"id":15766924,"url":"https://github.com/nickzuber/add-reason","last_synced_at":"2025-10-13T19:19:08.166Z","repository":{"id":57173221,"uuid":"114490964","full_name":"nickzuber/add-reason","owner":"nickzuber","description":":sparkles::turtle: Dead simple tool for seamlessly integrating ReasonML into existing JavaScript projects.","archived":false,"fork":false,"pushed_at":"2018-10-10T21:10:57.000Z","size":843,"stargazers_count":164,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-11T13:37:44.337Z","etag":null,"topics":["bucklescript","interop","javascript","ocaml","reason","reasonml"],"latest_commit_sha":null,"homepage":"","language":"OCaml","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nickzuber.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-16T21:22:20.000Z","updated_at":"2023-09-08T17:34:02.000Z","dependencies_parsed_at":"2022-08-24T13:31:09.135Z","dependency_job_id":null,"html_url":"https://github.com/nickzuber/add-reason","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nickzuber%2Fadd-reason","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nickzuber%2Fadd-reason/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nickzuber%2Fadd-reason/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nickzuber%2Fadd-reason/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nickzuber","download_url":"https://codeload.github.com/nickzuber/add-reason/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230523761,"owners_count":18239445,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bucklescript","interop","javascript","ocaml","reason","reasonml"],"created_at":"2024-10-04T13:03:42.025Z","updated_at":"2025-10-13T19:19:03.129Z","avatar_url":"https://github.com/nickzuber.png","language":"OCaml","readme":"\n\u003cimg width=\"392\" src=\"public/logo.png\" alt=\"add-reason\" /\u003e\n\n\u003e Simple tool for seamlessly integrating ReasonML into your existing JavaScript projects.\n\n\u003ca href=\"#\"\u003e\u003cimg src=\"https://travis-ci.org/nickzuber/add-reason.svg?branch=master\" /\u003e\u003c/a\u003e \u003ca href=\"#\"\u003e\u003cimg src=\"https://img.shields.io/badge/project-active-brightgreen.svg\" /\u003e\u003c/a\u003e \u003ca href=\"#\"\u003e\u003cimg src=\"https://img.shields.io/badge/released-yes-green.svg\" /\u003e\u003c/a\u003e \u003ca href=\"#\"\u003e\u003cimg src=\"https://img.shields.io/badge/license-MIT%20Licence-blue.svg\" /\u003e\u003c/a\u003e\n\nThis is an easy to use [cli tool](https://en.wikipedia.org/wiki/Command-line_interface) that helps you seamlessly interop [ReasonML](https://reasonml.github.io/) code with an existing JavaScript project. You tell us where your ReasonML code is, and we'll handle the rest!\n\n## Installation\n\n```\n$ npm install -g add-reason\n```\nor\n```\n$ yarn global add add-reason\n```\n\n## Usage\n\nThe 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.\n\nLet's assume you had file structure like this, where all your ReasonML code is located in a single directory called `reasonCode` or something:\n\n```\nmyCoolProject/\n├── reasonCode/\n│   ├── index.re\n│   ├── file1.re\n│   ├── file2.re\n│   └── utils/\n│       ├── fs.re\n│       └── path.re\n├── src/\n│   ├── index.js\n│   ├── main.js\n│   ├── example1.js\n│   ├── example2.js\n│   └── example3.js\n└── etc/\n```\n\nYou'd simply go to your project root and type:\n\n```\n$ add-reason setup ./reasonCode\n```\n\nor, since `setup` is the default command, you can even write\n\n```\n$ add-reason ./reasonCode\n```\n\nand that's it! Now you can compile you ReasonML code with\n\n```\n$ npm run build-reason\n# or\n$ bsb -make-world\n```\n\nand then import your compiled ReasonML code with\n\n```js\nconst reasonCode = require('reasonCode');\n// ...\n```\n\nIf 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/`!\n\n```\n$ add-reason setup ./reasonCode my-cool-code\n```\n\n```js\nconst myCoolCode = require('my-cool-code');\n// ...\n```\n\nYou can do a variety of other things too, the more basic usage is:\n\n```\nUsage: add-reason [command] [options]\n\n  Commands:\n\n    setup \u003cdirectory\u003e [package-name]  set up Reason directory, config files, and symlink\n    link \u003cdirectory\u003e [package-name]   create a symlink with the given package name\n    linter \u003cdirectory\u003e                create a merlin file for linting your ReasonML code\n    config \u003cdirectory\u003e                create a bsconfig file for building your ReasonML code\n\n  Options:\n\n    -h, --help     output usage information\n    -V, --version  output the version number\n    --no-linking   don't create the symlink to your compiled ReasonML code\n    --in-source    change target to in-source rather than a compiled directory\n```\n\n## How It Works\n\nThis 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.\n\nThere are a few steps that happen when you call `setup`:\n\n 1. Prepare target directory\n 2. Make sure we have a config file\n 3. Make sure we have a linting file\n 4. Create symlink\n 5. Create build command\n 6. Create postinstall\n 7. Check for `bs-platform`\n\nPreparing 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.\n\nNext 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.\n\nThen 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.\n\nWe 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!\n\nThe last thing that we do is check to make sure that you have [`bs-platform`](https://bucklescript.github.io/) 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\n\n```\n$ npm install -g bs-platform\n$ npm link bs-platform\n```\n\n## FAQ\n\n\u003e I ran `setup` and everything worked fine, but when I try to import my code I get `Error: Cannot find module`\n\nThis 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\n\n```js\nconst reasonCode = require('reasonCode');\n// ...\n```\n\nyour 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.\n\n```js\nconst reasonCode = require('reasonCode/file1.js');\n// ...\n```\n\n\u003e I ran `setup` but my code isn't compiled!\n\nDon'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.\n\n```\n$ npm run build-reason\n```\n\nRemember 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\n\n```\n$ bsb -make-world\n```\n\n## License\n\nThis software is free to use under the MIT License. See [this reference](https://opensource.org/licenses/MIT) for license text and copyright information.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnickzuber%2Fadd-reason","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnickzuber%2Fadd-reason","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnickzuber%2Fadd-reason/lists"}