This is yet another library that converts nodejs code to browser supported code. Actually, node-amdify doesn't know how to extract package dependencies, which makes it less usefull than https://github.com/substack/node-browserify. However, it serves to one more general purpose. It can convert CommonJS module definition style to AMD https://github.com/amdjs/amdjs-api/wiki/AMD.
I wrote it despite the fact that there is already https://github.com/jrburke/r.js, because r.js is very slow, not flexible and doesn't allow you to inject any code, that somehow modifies converter behaviour.
This library has only two methods:
amdify = require('node-amdify'); var pipe = amdify.build('dir', 'result', 'output')
dir is a directory from where all
.coffee file will be converted to AMD,
is a file where convert result will be stored and
output is a directory where just compiled from coffee
but not converted files will be stored. Result value is
Pipe class wich will be define later.
amdify = require('node-amdify'); var pipe = amdify.watch('dir', 'result', 'output')
The same as
build but it also watches
dir for changes and recompiles changed files. Since all compiled files
are stored in memory and
watch compiles only changed files, after initial compilation, every change compiles
constructor(dir, pack, output)
Just constructor, but since you have no access to a class, it doesn't matter.
node-amdify has 3 steps:
- Compile .coffee to .js if it's .coffee
- Extracting all CommonJS dependencies, normalizing paths and adding
- Building single pack
userPipe allows you to interact with this scheme and somehow modify code after it's compiled, but before convert started,
cb is just a callback that fires every time when pack is built.
through = require('through') mypipe = through (data) -> if data.code code = 'var I18n = require("common/i18n");\n' + data.code @queue file: data.file, code: code else @queue data module.exports = watch: -> converter = amdify.watch './src', './pack.js', './lib' converter.launchPipe mypipe, -> console.log 'compiled'