|
| 1 | +# ExampleProject |
| 2 | + |
| 3 | +[](https://travis-ci.org/reasonml/ExampleProject) |
| 4 | + |
| 5 | +> Note: Usage via Yarn may not work completely yet. |
| 6 | +
|
| 7 | +# Reason via `yarn` |
| 8 | + |
| 9 | +Example project using Reason as an `yarn` dependency. |
| 10 | + |
| 11 | +(For instructions with npm, see [Reason via npm](https://github.com/reasonml/ExampleProject/blob/master/README-NPM.md)) |
| 12 | + |
| 13 | +## Install yarn: |
| 14 | + |
| 15 | +[yarn](https://yarnpkg.com/) is a fast, reliable, and secure dependency management tool. You can now use yarn to install reason and manage its dependencies. |
| 16 | + |
| 17 | +``` |
| 18 | +npm install -g yarn |
| 19 | +``` |
| 20 | + |
| 21 | +## Get started: |
| 22 | +```sh |
| 23 | +git clone https://github.com/reasonml/ExampleProject.git |
| 24 | +cd ExampleProject |
| 25 | +yarn cache clean # need to clean every time before installation, see https://github.com/yarnpkg/yarn/issues/480 |
| 26 | +yarn install |
| 27 | +yarn reasonbuild |
| 28 | +yarn start |
| 29 | +``` |
| 30 | + |
| 31 | +## Included Top Level |
| 32 | + |
| 33 | +The top level `rtop` is built in to the sandbox: |
| 34 | + |
| 35 | +```sh |
| 36 | +# Opens `rtop` from the sandbox. |
| 37 | +yarn top |
| 38 | + |
| 39 | +``` |
| 40 | + |
| 41 | +# Editor Support |
| 42 | + |
| 43 | +All of the IDE support, including error highlighting, autocomplete, and |
| 44 | +syntax is included inside of the sandbox. |
| 45 | + |
| 46 | +```sh |
| 47 | +# Opens your `$EDITOR` with all the right tools in your `$PATH` |
| 48 | +yarn editor |
| 49 | +``` |
| 50 | +or |
| 51 | +```sh |
| 52 | +# Opens your `$EDITOR` with all the right tools in your `$PATH` |
| 53 | +npm run editor |
| 54 | +``` |
| 55 | + |
| 56 | +To make your editor load the IDE support from the sandbox: |
| 57 | + |
| 58 | +- Make sure your `$EDITOR` variable is set if not already. |
| 59 | + - `export EDITOR=vim`, or `export EDITOR=atom` |
| 60 | +- Configure your `EDITOR` to load the `Reason` plugins. See the instructions |
| 61 | + for [Atom](http://facebook.github.io/reason/tools.html#merlin-atom) and |
| 62 | + [Vim](https://github.com/facebook/reason/tree/master/editorSupport/VimReason). |
| 63 | + |
| 64 | +> Note: If you use `atom`, and already have `opam` installed, then there's a |
| 65 | +known issue where `atom` has problems loading, but you can fix it easily |
| 66 | +by commenting out any part in your `bashrc` that sources opam environments. |
| 67 | +We will come up with a long term solution at some point. |
| 68 | + |
| 69 | + |
| 70 | +### What's happening |
| 71 | +- `npm install` / `yarn install` will download and install all your dependencies, and run the |
| 72 | + `postinstall` steps for all of those dependencies, and then finally the |
| 73 | + `postinstall` script step of this project. |
| 74 | +- `npm start` / `yarn start` will run the script located in the `start` field of the |
| 75 | + `scripts` section of the `package.json` file here. The `start` script simply |
| 76 | + runs the binary that was built in the `postinstall` step. |
| 77 | +- No, really - all you need is `npm` (> `3.0`) or yarn. All of the compiler infrastructure |
| 78 | + has been organized into `npm` packages, and will be compiled on your host |
| 79 | + inside of the `./node_modules` directory. No `PATH`s are poluted. No global |
| 80 | + environment variables destroyed. No trace is left on your system. If you |
| 81 | + delete the `./node_modules` directory, you're back to exactly where you |
| 82 | + started. |
| 83 | + |
| 84 | + |
| 85 | +### How to customize |
| 86 | +- `npm` / `yarn` allows `scripts` to be specified in your project's `package.json`. |
| 87 | + These `scripts` are a named set of commands. |
| 88 | +- A few scripts have special meaning, such as the `postinstall` script. The |
| 89 | + `postinstall` script is how your project compiles itself. It is guaranteed |
| 90 | + that the `postinstall` script executes any time you run `npm install` / `yarn install` in this |
| 91 | + package, or any time another package installs you as a dependency. You're |
| 92 | + also guaranteed that your `postinstall` script is executed *after* all of |
| 93 | + your dependencies' `postinstall` scripts. |
| 94 | +- You can add new named scripts in the `package.json` `scripts` field. Once |
| 95 | + added, you can then run them via `npm run scriptName` from within the project |
| 96 | + root. |
| 97 | +- `. dependencyEnv` is commonly used in these `scripts`. The dot `.` sources |
| 98 | + `dependencyEnv` which manages the environment, and ensure that important |
| 99 | + binaries (such as `refmt`) are in the `PATH`. `dependencyEnv` ensures that |
| 100 | + the environment is augmented only for the duration of that `script` running, |
| 101 | + and only in ways that you or your immediate dependencies decide. When |
| 102 | + the entire purpose of developer tools is to generate a binary (such as a |
| 103 | + compiler) to be included in your `PATH`, or produce a library whose path |
| 104 | + should be specified in an special environment variable, it's almost like the |
| 105 | + environment variable is the public API of that package. `dependencyEnv` |
| 106 | + allows your script to see the environment variables that your immediate |
| 107 | + dependencies wanted to publish as their public API. You can learn how |
| 108 | + packages can publish environment variables in the [dependency-env |
| 109 | + repo](https://github.com/npm-ml/dependency-env). |
| 110 | + |
| 111 | +### Recompiling |
| 112 | +- To recompile this package (but not your dependencies), remove the local build |
| 113 | + artifacts for this package (usually just the `_build` directory) and then run |
| 114 | + `yarn postinstall` or `npm run postinstall`. |
| 115 | + |
| 116 | +### How to turn this project into a library |
| 117 | + |
| 118 | +- To turn this example project into a library that other people can depend on |
| 119 | + via `npm`... (coming soon). |
| 120 | + |
| 121 | +### Troubleshooting: |
| 122 | +- Check to make sure everything is installed correctly. There's a `script` |
| 123 | + already setup that will help you test the location of where `Reason` has been |
| 124 | + compiled into. |
| 125 | + |
| 126 | +``` |
| 127 | +npm run whereisreason |
| 128 | +``` |
| 129 | + |
| 130 | + |
| 131 | +- If something goes wrong, try deleting the local `node_modules` directory that |
| 132 | + was installed, and then try reinstalling using `npm install -f`. |
| 133 | + |
| 134 | +- For yarn, also delete `~/.yarn` and `./yarn.lock` to remove build cache. |
| 135 | + |
| 136 | +### TODO: |
| 137 | + |
| 138 | +- This also installs sandboxed IDE support for Vim/Atom/Emacs. We need to |
| 139 | + upgrade all of the plugins to automatically search for IDE plugins inside of |
| 140 | + the `./node_modules` directory. |
0 commit comments