node-amdify
This is yet another library that converts nodejs code to browser supported code. Actually, node-amdify doesn't know how to extract pacakge 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:
build
amdify = ; var pipe = amdify
Here dir
is a directory from where all .js
and .coffee
file will be converted to AMD, result
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.
watch
amdify = ; var pipe = amdify
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
very fast.
Pipe
constructor(dir, pack, output)
Just constructor, but since you have no access to a class, it doesn't matter.
launchPipe(userPipe, cb)
node-amdify has 3 steps:
- Compile .coffee to .js if it's .coffee
- userPipe
- Extracting all CommonJS dependencies, normalizing paths and adding
define
statements - 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 if datacode code = 'var I18n = require("common/i18n");\n' + datacode @queue file: datafilecode: code else @queue data module.exports = : -> converter = amdifywatch './src''./pack.js''./lib' converterlaunchPipe mypipe-> consolelog 'compiled'