Skip to content

Commit b94eaeb

Browse files
authored
Initial commit
0 parents  commit b94eaeb

File tree

74 files changed

+7034
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+7034
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
on:
2+
pull_request:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
build-sample-project:
9+
name: Build sample project
10+
strategy:
11+
matrix:
12+
system: [windows-latest, ubuntu-latest, macos-latest]
13+
fail-fast: false
14+
runs-on: ${{ matrix.system }}
15+
steps:
16+
- uses: actions/checkout@v3
17+
- uses: actions/setup-node@v3
18+
with:
19+
node-version: current
20+
- name: Restore cache
21+
uses: actions/cache@v3
22+
id: restore-cache
23+
with:
24+
# The entire ~/.esy directory has to be cached because esy's
25+
# import/export commands don't import/export the Melange JS runtime
26+
# files
27+
path: ~/.esy
28+
key: ${{ matrix.system }}-esy-${{ hashFiles('esy.lock/index.json') }}
29+
restore-keys: |
30+
${{ matrix.system }}-esy-
31+
- name: npm install
32+
run: npm install
33+
# Separating the esy steps provides more fine-grained insight when
34+
# debugging failed jobs
35+
- name: esy install
36+
run: npx esy install
37+
- name: Build esy dependencies
38+
run: npx esy build-dependencies --release
39+
- name: Build project
40+
run: npx esy build --release
41+
- name: Bundle JS app
42+
run: npm run bundle
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
on:
2+
schedule:
3+
- cron: "0 0 * * 0"
4+
workflow_dispatch:
5+
6+
jobs:
7+
update-esy-dependencies:
8+
strategy:
9+
matrix:
10+
system: [ubuntu-latest]
11+
runs-on: ${{ matrix.system }}
12+
steps:
13+
- uses: actions/checkout@v3
14+
- uses: actions/setup-node@v3
15+
with:
16+
node-version: current
17+
- name: npm install
18+
run: npm install
19+
- name: Remove lockfile
20+
run: rm -rf esy.lock
21+
# Separating the esy steps provides more fine-grained insight when
22+
# debugging failed jobs
23+
- name: Update esy dependencies (esy install)
24+
run: npx esy install
25+
- name: Check if any dependencies were updated
26+
id: check-for-updates
27+
run: test -n "$(git status --porcelain)"
28+
continue-on-error: true
29+
- name: Build esy dependencies
30+
if: steps.check-for-updates.outcome == 'success'
31+
run: npx esy build-dependencies --release
32+
- name: Build project
33+
if: steps.check-for-updates.outcome == 'success'
34+
run: npx esy build --release
35+
- name: Bundle JS app
36+
if: steps.check-for-updates.outcome == 'success'
37+
run: npm run bundle
38+
- name: Create pull request to update dependencies
39+
if: steps.check-for-updates.outcome == 'success'
40+
uses: peter-evans/create-pull-request@v4
41+
with:
42+
commit-message: Update esy dependencies
43+
branch: update-esy-dependencies
44+
delete-branch: true
45+
title: Update esy dependencies
46+
- name: Cache dependencies
47+
if: steps.check-for-updates.outcome == 'success'
48+
uses: actions/cache@v3
49+
with:
50+
# The entire ~/.esy directory has to be cached because esy's
51+
# import/export commands don't import/export the Melange JS runtime
52+
# files
53+
path: ~/.esy
54+
key: ${{ matrix.system }}-esy-${{ hashFiles('esy.lock/index.json') }}

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.DS_Store
2+
node_modules
3+
_build
4+
_esy
5+
.merlin
6+
dist/

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"ocaml.sandbox": {
3+
"kind": "custom",
4+
"template": "esy -P ${workspaceFolder:melange-esy-template} $prog $args --fallback-read-dot-merlin"
5+
}
6+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Javier Chávarri
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# melange-esy-template
2+
3+
A simple project template using [Melange](https://github.com/melange-re/melange)
4+
with [esy](https://esy.sh/).
5+
6+
If you are looking for a template with opam, check [melange-opam-template](https://github.com/melange-re/melange-opam-template).
7+
8+
## Quick Start
9+
10+
```shell
11+
npm install
12+
13+
# In separate terminals:
14+
npm run build:watch
15+
npm run serve
16+
```
17+
18+
### React
19+
20+
React support is provided by
21+
[`reason/react`](https://github.com/reasonml/reason-react/). The entry
22+
point of the sample React app is [`src/ReactApp.re`](src/ReactApp.re).
23+
24+
## Commands
25+
26+
- `npm install` - installs the npm/JavaScript dependencies, including the `esy`
27+
package manager (see below)
28+
- `npm run build:watch` - uses `esy` to:
29+
- Install OCaml-based dependencies (e.g. OCaml and Melange)
30+
- Symlink Melange's JavaScript runtime into `node_modules/melange`, so that
31+
JavaScript bundlers like Webpack can find the files when they're imported
32+
- Compile the project's ReasonML/OCaml/ReScript source files to JavaScript
33+
- Rebuild files when changed (via Melange's built-in watch mode)
34+
- `npm run serve` - starts a dev server to serve the frontend app
35+
36+
## JavaScript output
37+
38+
Since Melange just compiles source files into JavaScript files, it can be used
39+
for projects on any JavaScript platform - not just the browser.
40+
41+
All ReasonML/OCaml/ReScript source files under `src/` will be compiled to
42+
JavaScript and written to `_build/default/src/*` (along with some other build
43+
artifacts).
44+
45+
For example, [`src/Hello.ml`](src/Hello.ml) (using OCaml syntax) and
46+
[`src/Main.re`](src/Main.re) (using ReasonML syntax) can each be run with
47+
`node`:
48+
49+
```bash
50+
node _build/default/src/node/src/Hello.js
51+
node _build/default/src/node/src/Main.js
52+
```

dune

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
;; we start by ignoring node_modules. if you need to consume an OCaml
2+
;; project from `node_modules`, this should work:
3+
;; - remove the `dirs` stanza below
4+
;; - add a `(subdir node_modules (dirs only_your_package))`
5+
6+
(dirs :standard \ node_modules)

dune-project

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(lang dune 3.8)
2+
(using directory-targets 0.1)
3+
(using melange 0.1)

esy.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "melange-project",
3+
"dependencies": {
4+
"ocaml": "4.14.0",
5+
"@opam/dune": ">= 3.8.0",
6+
"@opam/ocamlfind": "1.9.5",
7+
"@opam/ocamlbuild": "0.14.2",
8+
"@opam/reason": "*",
9+
"@opam/melange": ">=1.0.0",
10+
"@opam/reactjs-jsx-ppx": ">=1.0.0",
11+
"@opam/reason-react": "0.11.0"
12+
},
13+
"devDependencies": {
14+
"@opam/ocaml-lsp-server": ">= 1.12.0"
15+
},
16+
"esy": {
17+
"buildsInSource": "_build",
18+
"build": [
19+
"dune build @react @node"
20+
]
21+
},
22+
"scripts": {
23+
"build:watch": "dune build @react @node -w"
24+
},
25+
"installConfig": {
26+
"pnp": false
27+
}
28+
}

esy.lock/.gitattributes

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

esy.lock/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)