0.0.1 • Published 11 years ago

nce-amd v0.0.1

Weekly downloads
2
License
ISC
Repository
github
Last release
11 years ago

AMD extension for NCE

Description

This is an nce extension for Asynchronous Module Definition support designed with require.js.

How to install

Install with npm: npm install --save nce-amd

Integrate in NCE with the extension-manager:

var NCE = require("nce");
var nce = new NCE(/*{}*/);
var extMgr = require("nce-extension-manager")(nce);

var amd = extMgr.getActivatedExtension("amd");

How to use

Config settings

You are able to use the following config-settings with their defaults:

  • route: "/amd": Sub-URL to listen
  • dumpPath: process.cwd() + "/amd": Directory to dump files
  • logger: {}: Settings for logger-extension

Basic methods

ext.define(name, code, cb, opts)

Define a module for amd.

Normally the code get minified. If you don't want to, set: opts.minify = false.

Arguments
  1. nameString: A name as identifier
  2. codeString: JavaScript code, written in amd-style.
  3. cbFunction: Callback-function form fs.writeFile with the arguments:
    1. errorError: Used for exceptions
  4. optsObject: Options:
    • minifyBoolean: Minify code (default true)

ext.defineCDN(name, url, cb)

Define a module from cdn.

Arguments
  1. nameString: A name as identifier
  2. urlString: URL to JS-Resource.
  3. cbFunction: Callback-function form fs.writeFile with the arguments:
    1. errorError: Used for exceptions
    2. successBoolean: True on success

ext.get = function(name, cb)

Get the content of a resource as buffer.

Arguments
  1. nameString: A name as identifier
  2. cbFunction: Callback-function form fs.readFile with the arguments:
    1. errorError: Used for exceptions
    2. codeBuffer: Content of file as buffer

ext.getStream = function(name)

Get a stream of a resource.

Arguments
  1. nameString: A name as identifier

Returns a stream from fs.createReadStream.

ext.undefine = function(name, cb)

Remove a script from defined functions by its name.

Arguments
  1. nameString: A name as identifier
  2. cbFunction: Callback-function form fs.readFile with the arguments:
    1. errorError: Used for exceptions

ext.mkScriptTag = function(mainName)

Returns a html-script-tag with mainName as start script for amd.

Arguments
  1. mainNameString: A name as identifier

Returns a HTML-script tag with require.js and loads mainName with its dependencies.