Skip to content

Commit f43eb43

Browse files
authored
Rename to ReasonProject, fix the doc
1 parent 64418d0 commit f43eb43

1 file changed

Lines changed: 117 additions & 47 deletions

File tree

README.md

Lines changed: 117 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,149 @@
1-
# ExampleProject
1+
# ReasonProject
22

3-
[![Build Status](https://travis-ci.org/reasonml/ExampleProject.svg?branch=master)](https://travis-ci.org/reasonml/ExampleProject)
3+
Reason project environment via `npm`.
44

5-
## Reason via `npm`
5+
- Local sandboxed `Reason` projects.
6+
- Installation of `Reason` tools globally.
67

7-
Example project using Reason as an `npm` dependency. Use this as a template to
8-
quickly start a new project, or just try out `Reason`.
8+
Those two features may sound completely different, but the truth is that they
9+
are very similar, and therefore it makes sense to have `ReasonProject` handle
10+
both.
11+
12+
> A sandboxed environment models dependencies and builds them into a local
13+
> directory so that it works reliably for anyone. Installing tools into your
14+
> global environment is simply a matter of sourcing the sandboxed environment
15+
> in your `.bashrc`. It's easy to make sandboxed local environments global, and
16+
> very hard to do the reverse, so `ReasonProject` starts with local
17+
> environments.
18+
19+
20+
[![Build Status](https://travis-ci.org/reasonml/ReasonProject.svg?branch=master)](https://travis-ci.org/reasonml/ReasonProject)
921

1022
## Get Started:
1123

24+
Install by cloning the repo and running `npm install`. This installs all
25+
dependencies locally into the `ReasonProject` directory.
26+
1227
```sh
13-
git clone https://github.com/reasonml/ExampleProject.git
14-
cd ExampleProject
28+
git clone https://github.com/reasonml/ReasonProject.git
29+
cd ReasonProject
1530
npm install
16-
npm start
1731
```
1832

19-
## Make Changes And Rebuild :
33+
### Run, Change, Rebuild
34+
35+
There are a couple of built in commands declared in `package.json` that you can
36+
execute via `npm run`. For example: `"npm run start"`, `"npm run reasonBuild"`
37+
and `"npm run clean"`. You can also [add your
38+
own](#reasonproject-get-started-add-your-own-scripts) commands.
39+
40+
2041
```sh
21-
npm run reasonBuild
22-
npm run clean # Clean if you need to!
42+
npm run start # Runs the compiled app
43+
npm run reasonBuild # Rebuilds after changing
44+
npm run clean # Clean if you need to!
2345
```
2446

25-
If you are running as `root` already (you probably aren't) then invoke `npm
26-
install --unsafe-perm` instead.
2747

28-
## Included Top Level
48+
### REPL
2949

30-
The top level `rtop` is built in to the sandbox:
50+
The `rtop` REPL is built into the sandbox, and the command `npm run top` which
51+
starts the REPL is predefined in `package.json`.
3152

3253
```sh
3354
# Opens `rtop` from the sandbox.
3455
npm run top
3556
```
3657

37-
## Editor Support
58+
### Environment Commands
3859

39-
All of the IDE support, including error highlighting, autocomplete, and
40-
syntax is included inside of the sandbox.
60+
Once built, `ReasonProject` generates an environment that you can temporarily
61+
load to execute commands within. The environment contains an enhanced `PATH`
62+
that contains binaries built by your dependencies, but this environment isn't
63+
loaded automatically. To temporarily load this environment, execute the
64+
predefined `npm run env --` command. You should pass the *actual* command you
65+
want to run after `--`.
4166

4267
```sh
43-
# Opens your `$EDITOR` with all the right tools in your `$PATH`
44-
npm run editor
68+
69+
npm run env -- which refmt
70+
71+
> ReasonProject/node_modules/reason/_build/ocamlfind/bin/refmt
72+
4573
```
4674

47-
To make your editor load the IDE support from the sandbox:
75+
The previous command would likely fail if not prefixed with `npm run env --`
76+
because the dependencies are the ones that built `refmt` in this case. `npm
77+
run env` makes all the things from our dependencies available.
78+
79+
### Editor Support
80+
81+
#### Prepare Your Editor
82+
83+
All of the IDE plugins, including integration with error highlighting,
84+
autocomplete, and syntax highlighting are included inside of the built project.
85+
86+
Configure your `EDITOR` to load the `Reason` plugins from your instance of
87+
`ReasonProject`. See the instructions for
88+
[Atom](http://facebook.github.io/reason/tools.html#merlin-atom) and
89+
[Vim](https://github.com/facebook/reason/tree/master/editorSupport/VimReason).
90+
91+
#### IDE support included.
4892

49-
- Make sure your `$EDITOR` variable is set if not already.
50-
- `export EDITOR=vim`, or `export EDITOR=atom`
51-
- Configure your `EDITOR` to load the `Reason` plugins. See the instructions
52-
for [Atom](http://facebook.github.io/reason/tools.html#merlin-atom) and
53-
[Vim](https://github.com/facebook/reason/tree/master/editorSupport/VimReason).
93+
The editor config above mostly exists to load the *actual* editor support, from
94+
the `ReasonProject` build. The only thing we need is to make sure the `PATH`
95+
contains all the important stuff from `ReasonProject`'s build. There are two
96+
approaches: one continues to avoid global variables (as we've done so far), and
97+
the other doesn't.
98+
99+
##### Avoiding Global Paths
100+
101+
You can continue to develop entirely in the isolated sandbox without polluting
102+
global environment variables, by opening your editor within the sandbox
103+
environment:
104+
105+
```sh
106+
npm run env -- vim
107+
npm run env -- atom
108+
npm run env -- mvim
109+
```
110+
111+
Because you've [prepared your
112+
editor](#reasonproject-get-started-editor-support)
113+
to load editor support from the environment, `npm run env -- yourEditor`
114+
ensures that your editor will find the editor support in your environment
115+
variables.
54116

55117
> Note: If you use `atom`, and already have `opam` installed, then there's a
56118
known issue where `atom` has problems loading, but you can fix it easily
57119
by commenting out any part in your `bashrc` that sources opam environments.
58120
We will come up with a long term solution at some point.
59121

122+
##### Just Using Global Paths
123+
124+
Pure sandboxed based development doesn't always work for certain workflows.
125+
Prefixing *all* commands with `npm run env` may not work well. In that case,
126+
you can easily inject your successfully built project's environment into the
127+
global `PATH`, by putting the following in your `.bashrc`:
60128

61-
## Making It Your Project
62-
`ExampleProject` is meant to be the starting point of your own project. You'll want
129+
```sh
130+
# In your .bashrc
131+
pushd ~/pathTo/ReasonProject/ && \
132+
eval $(~/pathTo/ReasonProject/node_modules/.bin/dependencyEnv) && \
133+
popd
134+
```
135+
136+
137+
### Multiple Projects
138+
139+
You can have multiple clones/forks/builds of `ReasonProject` for each of your
140+
projects. When you make changes, you can share the project easily with anyone
141+
else. It's common to have multiple `ReasonProject`s simultaneously. If also
142+
using global environment variables, it's wise to also have one special
143+
`ReasonProject`, that is only used for augmenting the global path.
144+
145+
### Making It Your Project
146+
`ReasonProject` is meant to be the starting point of your own project. You'll want
63147
to make use of existing libraries in your app, so
64148
browse the growing set of `opam` packages ported to `npm` under
65149
[`opam-alpha`](https://www.npmjs.com/~opam-alpha#packages). If there's something
@@ -90,20 +174,6 @@ as they are, but a next generation `opam-beta` universe on `npm` would have
90174
everything `opam-alpha` has (and then some). The work to upgrade your projects
91175
will likely be minimal.
92176

93-
### What's happening
94-
- `npm install` will download and install all your dependencies, and run the
95-
`postinstall` steps for all of those dependencies, and then finally the
96-
`postinstall` script step of this project.
97-
- `npm start` will run the script located in the `start` field of the
98-
`scripts` section of the `package.json` file here. The `start` script simply
99-
runs the binary that was built in the `postinstall` step.
100-
- No, really - all you need is `npm` (> `3.0`). All of the compiler infrastructure
101-
has been organized into `npm` packages, and will be compiled on your host
102-
inside of the `./node_modules` directory. No `PATH`s are poluted. No global
103-
environment variables destroyed. No trace is left on your system. If you
104-
delete the `./node_modules` directory, you're back to exactly where you
105-
started.
106-
107177

108178
### Add Your Own Scripts
109179
- `npm` allows `scripts` to be specified in your project's `package.json`.
@@ -132,13 +202,13 @@ will likely be minimal.
132202
repo](https://github.com/npm-ml/dependency-env).
133203

134204

135-
### How to turn this project into a library
205+
### Creating Reusable Libraries
136206

137207
- To turn this example project into a library that other people can depend on
138208
via `npm`... (coming soon).
139209

140210

141-
### Debugging a Failed Dependency Install
211+
### Debugging Failed Dependencies
142212

143213
When `npm install` fails to install one of your dependencies successfully, it's
144214
typically because a `postinstall` step of a package has failed. Read
@@ -163,7 +233,7 @@ Output:
163233
```sh
164234
test@1.0.0 /Users/jwalke/Desktop/tmp
165235
└─┬ @opam-alpha/qcheck@0.4.0
166-
└── qcheck-actual@0.4.0 (git://github.com/npm-opam/qcheck.git#85bd0e35bec2987b301fa26235b97c1e344462df)
236+
└── qcheck-actual@0.4.0 (git://github.com/npm-opam/qcheck.git
167237
```
168238
(Note: Sometimes it won't traverse `git` dependencies to find all the potentially installed
169239
package. That's okay).
@@ -182,14 +252,14 @@ Ouput:
182252
```
183253
test@1.0.0 /Users/jwalke/Desktop/tmp
184254
└─┬ @opam-alpha/qcheck@0.4.0
185-
└── qcheck-actual@0.4.0 (git://github.com/npm-opam/qcheck.git#85bd0e35bec2987b301fa26235b97c1e344462df)
255+
└── qcheck-actual@0.4.0 (git://github.com/npm-opam/qcheck.git
186256
```
187257
188258
Now, make sure `npm` didn't do something weird with installing new versions of package
189259
that didn't show up in the dry run, and make sure it installed things
190260
as flat as possible in `node_modules`, as opposed to nesting `node_modules`
191261
for compiled ocaml packages inside of other `node_modules`. Ideally, everything
192-
is a flat list inside the `ExampleProject/node_modules` directory.
262+
is a flat list inside the `ReasonProject/node_modules` directory.
193263
194264
`cd` into the package that was failing to build correctly (it was actually the `qcheck-actual` package
195265
in our case). Run the build command in `package.json`'s `postinstall` field by doing `npm run postinstall`.

0 commit comments

Comments
 (0)