Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
enieber authored Aug 27, 2023
0 parents commit b94eaeb
Show file tree
Hide file tree
Showing 74 changed files with 7,034 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/build-sample-project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
on:
pull_request:
push:
branches:
- main

jobs:
build-sample-project:
name: Build sample project
strategy:
matrix:
system: [windows-latest, ubuntu-latest, macos-latest]
fail-fast: false
runs-on: ${{ matrix.system }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: current
- name: Restore cache
uses: actions/cache@v3
id: restore-cache
with:
# The entire ~/.esy directory has to be cached because esy's
# import/export commands don't import/export the Melange JS runtime
# files
path: ~/.esy
key: ${{ matrix.system }}-esy-${{ hashFiles('esy.lock/index.json') }}
restore-keys: |
${{ matrix.system }}-esy-
- name: npm install
run: npm install
# Separating the esy steps provides more fine-grained insight when
# debugging failed jobs
- name: esy install
run: npx esy install
- name: Build esy dependencies
run: npx esy build-dependencies --release
- name: Build project
run: npx esy build --release
- name: Bundle JS app
run: npm run bundle
54 changes: 54 additions & 0 deletions .github/workflows/update-esy-dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
on:
schedule:
- cron: "0 0 * * 0"
workflow_dispatch:

jobs:
update-esy-dependencies:
strategy:
matrix:
system: [ubuntu-latest]
runs-on: ${{ matrix.system }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: current
- name: npm install
run: npm install
- name: Remove lockfile
run: rm -rf esy.lock
# Separating the esy steps provides more fine-grained insight when
# debugging failed jobs
- name: Update esy dependencies (esy install)
run: npx esy install
- name: Check if any dependencies were updated
id: check-for-updates
run: test -n "$(git status --porcelain)"
continue-on-error: true
- name: Build esy dependencies
if: steps.check-for-updates.outcome == 'success'
run: npx esy build-dependencies --release
- name: Build project
if: steps.check-for-updates.outcome == 'success'
run: npx esy build --release
- name: Bundle JS app
if: steps.check-for-updates.outcome == 'success'
run: npm run bundle
- name: Create pull request to update dependencies
if: steps.check-for-updates.outcome == 'success'
uses: peter-evans/create-pull-request@v4
with:
commit-message: Update esy dependencies
branch: update-esy-dependencies
delete-branch: true
title: Update esy dependencies
- name: Cache dependencies
if: steps.check-for-updates.outcome == 'success'
uses: actions/cache@v3
with:
# The entire ~/.esy directory has to be cached because esy's
# import/export commands don't import/export the Melange JS runtime
# files
path: ~/.esy
key: ${{ matrix.system }}-esy-${{ hashFiles('esy.lock/index.json') }}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store
node_modules
_build
_esy
.merlin
dist/
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ocaml.sandbox": {
"kind": "custom",
"template": "esy -P ${workspaceFolder:melange-esy-template} $prog $args --fallback-read-dot-merlin"
}
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Javier Chávarri

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# melange-esy-template

A simple project template using [Melange](https://github.com/melange-re/melange)
with [esy](https://esy.sh/).

If you are looking for a template with opam, check [melange-opam-template](https://github.com/melange-re/melange-opam-template).

## Quick Start

```shell
npm install

# In separate terminals:
npm run build:watch
npm run serve
```

### React

React support is provided by
[`reason/react`](https://github.com/reasonml/reason-react/). The entry
point of the sample React app is [`src/ReactApp.re`](src/ReactApp.re).

## Commands

- `npm install` - installs the npm/JavaScript dependencies, including the `esy`
package manager (see below)
- `npm run build:watch` - uses `esy` to:
- Install OCaml-based dependencies (e.g. OCaml and Melange)
- Symlink Melange's JavaScript runtime into `node_modules/melange`, so that
JavaScript bundlers like Webpack can find the files when they're imported
- Compile the project's ReasonML/OCaml/ReScript source files to JavaScript
- Rebuild files when changed (via Melange's built-in watch mode)
- `npm run serve` - starts a dev server to serve the frontend app

## JavaScript output

Since Melange just compiles source files into JavaScript files, it can be used
for projects on any JavaScript platform - not just the browser.

All ReasonML/OCaml/ReScript source files under `src/` will be compiled to
JavaScript and written to `_build/default/src/*` (along with some other build
artifacts).

For example, [`src/Hello.ml`](src/Hello.ml) (using OCaml syntax) and
[`src/Main.re`](src/Main.re) (using ReasonML syntax) can each be run with
`node`:

```bash
node _build/default/src/node/src/Hello.js
node _build/default/src/node/src/Main.js
```
6 changes: 6 additions & 0 deletions dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
;; we start by ignoring node_modules. if you need to consume an OCaml
;; project from `node_modules`, this should work:
;; - remove the `dirs` stanza below
;; - add a `(subdir node_modules (dirs only_your_package))`

(dirs :standard \ node_modules)
3 changes: 3 additions & 0 deletions dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(lang dune 3.8)
(using directory-targets 0.1)
(using melange 0.1)
28 changes: 28 additions & 0 deletions esy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "melange-project",
"dependencies": {
"ocaml": "4.14.0",
"@opam/dune": ">= 3.8.0",
"@opam/ocamlfind": "1.9.5",
"@opam/ocamlbuild": "0.14.2",
"@opam/reason": "*",
"@opam/melange": ">=1.0.0",
"@opam/reactjs-jsx-ppx": ">=1.0.0",
"@opam/reason-react": "0.11.0"
},
"devDependencies": {
"@opam/ocaml-lsp-server": ">= 1.12.0"
},
"esy": {
"buildsInSource": "_build",
"build": [
"dune build @react @node"
]
},
"scripts": {
"build:watch": "dune build @react @node -w"
},
"installConfig": {
"pnp": false
}
}
3 changes: 3 additions & 0 deletions esy.lock/.gitattributes

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions esy.lock/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b94eaeb

Please sign in to comment.