Skip to content

Commit

Permalink
Initial open source release
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart Schuurmans committed Jun 21, 2022
1 parent 21709d9 commit 9d74564
Show file tree
Hide file tree
Showing 6 changed files with 538 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/.merlin
/.bsb.lock
/lib/
/node_modules/
/public/bundle/
/public/sw.js*
/public/workbox-*.js*
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# lumi-rescript-dev

This is a utility to build and bundle rescript projects using esbuild.

- Very fast builds
- Watcher with live-reload
- Service workers
- Sass support

## How to use

Simply run `lumi-rescript-dev build` in your project root. Typically, you'll want to add the following to your `package.json`.

```json
{
"scripts": {
"prepare": "lumi-rescript-dev build",
"start": "lumi-rescript-dev watch",
"start-prod": "lumi-rescript-dev watch '{\"http\":{\"proxy\":{\"target\":\"https://your-prod.com/\"}}}'",
"clean": "rescript clean && rm -rf public/bundle"
},
}
```

## Project structure

The default config expects something like the following project structure:
```
project-name
├── bsconfig.json
├── package.json
├── public
│ ├── images
│ │ ├── favicon.ico
│ │ ├── icons-512.png
│ │ └── some-image.png
│ ├── index.html
│ └── site.webmanifest
└── src
├── css
│ ├── default.scss
│ └── main.sass
├── Index.res
└── Util.res
```

Generated files will end up in `lib` and `public/bundle`, by default.

## Configuration
The default configuration can be inspected using `lumi-rescript-dev dump-config`, and changes can be made by adding them to the `lumi-rescript-dev` key in your `package.json`.

## JS API
Alternatively, if you require more configuration flexibility, the code can be imported from your own code.
```js
const {main, defaultConfig} = require('lumi-rescript-dev')

main(defaultConfig, {
root: __dirname
// ...
})
```
37 changes: 37 additions & 0 deletions Watchman.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const watchman = require('fb-watchman')

class Watchman {
constructor() {
this.client = new watchman.Client()
}
command(...args) {
return new Promise((resolve, reject) => {
this.client.command(args, (err, resp) => {
if (err) reject(err)
else resolve(resp)
})
})
}
async setup_watches(dirname) {
const { warning, watch, relative_path } = await this.command("watch-project", dirname)
if (warning) {
console.warn('[watchman]', warning);
}
console.log('[watchman] watch established on:', watch, 'relative_path:', relative_path);
Object.assign(this, { watch, relative_path })
this.clock = await this.command("clock", watch)
}
async subscribe(name, expression) {
const sub = {
expression,
fields: ["name", "size", "mtime_ms", "exists", "type"],
since: this.clock
}
if (this.relative_path) sub.relative_root = this.relative_path
await this.command('subscribe', this.watch, name, sub)
}
on(x, y) {
return this.client.on(x, y)
}
}
module.exports.Watchman = Watchman
Loading

0 comments on commit 9d74564

Please sign in to comment.