Skip to content

Commit

Permalink
Add index.js file such that only require 'mixco' is needed
Browse files Browse the repository at this point in the history
This also makes the compilation process simpler, because the index.js
also selects whether to use the sources or the compiled library based on
the `MIXCO_USE_SOURCE` environment variable.
  • Loading branch information
arximboldi committed May 31, 2015
1 parent 85396c5 commit a643365
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 71 deletions.
23 changes: 23 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// mixco
// =====

if (process.env.MIXCO_USE_SOURCE) {
require('coffee-script/register')
module.exports = {
behaviour: require('./src/behaviour'),
control: require('./src/control'),
script: require('./src/script'),
transform: require('./src/transform'),
util: require('./src/util'),
value: require('./src/value')
}
} else {
module.exports = {
behaviour: require('./lib/behaviour'),
control: require('./lib/control'),
script: require('./lib/script'),
transform: require('./lib/transform'),
util: require('./lib/util'),
value: require('./lib/value')
}
}
44 changes: 24 additions & 20 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

NODE_BIN = node_modules/.bin

NODEJS = node
COFFEE = $(NODE_BIN)/coffee
BROWSERIFY = $(NODE_BIN)/browserify
DOCCO = $(NODE_BIN)/docco
MOCHA = $(NODE_BIN)/_mocha
ISTANBUL = $(NODE_BIN)/istanbul
WITH_PATH = NODE_PATH="$(NODE_PATH):.."
NODEJS = $(WITH_PATH) node
COFFEE = $(WITH_PATH) $(NODE_BIN)/coffee
BROWSERIFY = $(WITH_PATH) $(NODE_BIN)/browserify
DOCCO = $(WITH_PATH) $(NODE_BIN)/docco
MOCHA = $(WITH_PATH) $(NODE_BIN)/mocha
ISTANBUL = $(WITH_PATH) $(NODE_BIN)/istanbul
_MOCHA = $(NODE_BIN)/_mocha

SCRIPTS = \
out/korg_nanokontrol2.js out/korg_nanokontrol2.midi.xml \
Expand All @@ -25,7 +27,6 @@ FRAMEWORK = \
lib/cli.js \
lib/console.js \
lib/control.js \
lib/index.js \
lib/script.js \
lib/transform.js \
lib/util.js \
Expand All @@ -37,7 +38,6 @@ DOCS = \
doc/src/cli.html \
doc/src/control.html \
doc/src/console.html \
doc/src/index.html \
doc/src/script.html \
doc/src/transform.html \
doc/src/util.html \
Expand Down Expand Up @@ -82,38 +82,41 @@ tmp/%.js: script/%.js
@mkdir -p $(@D)
cp -f $< $@

out/%.js: script/%.js
out/%.js: script/%.js $(FRAMEWORK)
@mkdir -p $(@D)
@mkdir -p tmp
echo "require('../$<')" >> tmp/$*.entry.js
$(BROWSERIFY) \
$(BROWSERIFY) -u "src/*" -u "coffee-script/register" \
-t coffeeify --extension=".js" --extension=".coffee" --extension=".litcoffee" \
-r "./$<:$*" tmp/$*.entry.js -o $@
echo ";$*=require('$*').$*" >> $@
out/%.js: script/%.litcoffee
v8 $@
out/%.js: script/%.litcoffee $(FRAMEWORK)
@mkdir -p $(@D)
@mkdir -p tmp
echo "require('../$<')" >> tmp/$*.entry.js
$(BROWSERIFY) \
$(BROWSERIFY) -u "src/*" -u "coffee-script/register" \
-t coffeeify --extension=".js" --extension=".coffee" --extension=".litcoffee" \
-r "./$<:$*" tmp/$*.entry.js -o $@
echo ";$*=require('$*').$*" >> $@
out/%.js: script/%.coffee
v8 $@
out/%.js: script/%.coffee $(FRAMEWORK)
@mkdir -p $(@D)
@mkdir -p tmp
echo "require('../$<')" >> tmp/$*.entry.js
$(BROWSERIFY) \
$(BROWSERIFY) -u "src/*" -u "coffee-script/register" \
-t coffeeify --extension=".js" --extension=".coffee" --extension=".litcoffee" \
-r "./$<:$*" tmp/$*.entry.js -o $@
echo ";$*=require('$*').$*" >> $@
v8 $@

out/%.midi.xml: script/%.litcoffee
out/%.midi.xml: script/%.litcoffee $(FRAMEWORK)
@mkdir -p $(@D)
$(COFFEE) $< -g > $@
out/%.midi.xml: script/%.coffee
out/%.midi.xml: script/%.coffee $(FRAMEWORK)
@mkdir -p $(@D)
$(COFFEE) $< -g > $@
out/%.midi.xml: script/%.js
out/%.midi.xml: script/%.js $(FRAMEWORK)
@mkdir -p $(@D)
$(NODEJS) $< -g > $@

Expand Down Expand Up @@ -147,11 +150,12 @@ install:
npm install

test:
$(MOCHA) \
--recursive --compilers coffee:coffee-script/register
MIXCO_USE_SOURCE=1 \
$(MOCHA) --recursive --compilers coffee:coffee-script/register

test-coverage:
$(ISTANBUL) cover $(MOCHA) -- \
MIXCO_USE_SOURCE=1 \
$(ISTANBUL) cover $(_MOCHA) -- \
--recursive --compilers coffee:coffee-script/register \
--require coffee-coverage/register-istanbul
$(ISTANBUL) report text lcov
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"makefile"
],
"preferGlobal": true,
"main": "lib/index.js",
"main": "index.js",
"bin": {
"mixco": "./bin/mixco.js"
},
Expand Down
20 changes: 7 additions & 13 deletions script/korg_nanokontrol2.litcoffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,13 @@ Dependencies
First, we have to import he *Mixco* modules that we are going to use,
using the [NodeJS,
**require**](http://nodejs.org/api/modules.html#modules_module_require_id)
function.
function. Also, lets define these couple of shortcuts to save typing.

{assert} = require '../src/util'
script = require '../src/script'
control = require '../src/control'
behaviour = require '../src/behaviour'
value = require '../src/value'
Also, lets define these couple of shortcuts to save typing.

c = control
b = behaviour
v = value
mixco = require 'mixco'
{assert} = mixco.util
c = mixco.control
b = mixco.behaviour
v = mixco.value
The script
----------
Expand All @@ -44,7 +38,7 @@ The `name` attribute is compulsory and must match file name *without
extension*. It should be a valid JavaScript identifier -- i.e. start
with a letter and contain only alfanumerical characters or underscore.

script.register module,
mixco.script.register module,
name: 'korg_nanokontrol2'
Expand Down
13 changes: 6 additions & 7 deletions script/maudio_xponent.litcoffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@ functionallity of the controls.

![Xponent Layout](../pic/maudio_xponent.png)

{assert} = require '../src/util'
script = require '../src/script'
c = require '../src/control'
b = require '../src/behaviour'
v = require '../src/value'
mixco = require 'mixco'
{assert} = mixco.util
c = mixco.control
b = mixco.behaviour
v = mixco.value
ledButtonFixed = ->
c.ledButton(arguments...).option
process: (ev) ->
if ev.message() == c.MIDI_NOTE_OFF
ev.value = 0
script.register module,
mixco.script.register module,
name: 'maudio_xponent'
info:
Expand Down
11 changes: 5 additions & 6 deletions script/novation_twitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@
// modules are usable too when writing your script with the *Mixco*
// framework.

require("coffee-script/register")
var _ = require('underscore')
var script = require('../src/script')
var c = require('../src/control')
var b = require('../src/behaviour')
var v = require('../src/value')
var mixco = require('mixco')
var c = mixco.control
var b = mixco.behaviour
var v = mixco.value

// The script
// ----------
Expand All @@ -45,7 +44,7 @@ var v = require('../src/value')
// *NodeJS*, the second parameter is the JavaScript object with all
// the functions and information about our script.

script.register(module, {
mixco.script.register(module, {

// ### Metadata
//
Expand Down
24 changes: 0 additions & 24 deletions src/index.litcoffee

This file was deleted.

0 comments on commit a643365

Please sign in to comment.