From 2b9632fd3929ba550d0495faa78ef50c3f5d3c1a Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Sat, 13 Apr 2019 23:23:25 +0200 Subject: [PATCH] docs: custom module bundling --- resources/docs/docs/custom-module.md | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/resources/docs/docs/custom-module.md b/resources/docs/docs/custom-module.md index 46e50ca7..e1e4c378 100644 --- a/resources/docs/docs/custom-module.md +++ b/resources/docs/docs/custom-module.md @@ -1,5 +1,7 @@ # Custom module +## Writing a custom module + Using the `-c / --custom-module` command-line switch, users can load a javascript file to tune the way Open Stage Control behaves regarding osc. ```js @@ -44,6 +46,8 @@ module.exports = { ``` +## Available globals + The module is executed in a restricted context, only a few globals are available : - `console`: `object` @@ -86,3 +90,35 @@ sendOsc({ ] }) ``` + +## Managing big modules + +Custom modules don't let you use node's `require` function at runtime, but you can manage your sources in multiple files and bundle them into a single file before loading it in Open Stage Control. + +The common pattern for this is using the [browserify](http://browserify.org/) library: + +1. define some variable in `number.js` + +```javascript +module.exports = 42 +``` + +2. retreive it in your main module file (`main.js`): + +```javascript +var num = require('./number.js') + +module.exports = { + init: function(){ + console.log(num) // 42 + }, + oscInFilter: function(data){ + // etc + } +} +``` + + +3. bundle your sources into `custom-module.js`: + +`browserify main.js -o custom-module.js --standalone module.exports`