nce-amd

0.0.1 • Public • Published

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. name[String]: A name as identifier
  2. code[String]: JavaScript code, written in amd-style.
  3. cb[Function]: Callback-function form fs.writeFile with the arguments:
    1. error[Error]: Used for exceptions
  4. opts[Object]: Options:
    • minify[Boolean]: Minify code (default true)

ext.defineCDN(name, url, cb)

Define a module from cdn.

Arguments
  1. name[String]: A name as identifier
  2. url[String]: URL to JS-Resource.
  3. cb[Function]: Callback-function form fs.writeFile with the arguments:
    1. error[Error]: Used for exceptions
    2. success[Boolean]: True on success

ext.get = function(name, cb)

Get the content of a resource as buffer.

Arguments
  1. name[String]: A name as identifier
  2. cb[Function]: Callback-function form fs.readFile with the arguments:
    1. error[Error]: Used for exceptions
    2. code[Buffer]: Content of file as buffer

ext.getStream = function(name)

Get a stream of a resource.

Arguments
  1. name[String]: 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. name[String]: A name as identifier
  2. cb[Function]: Callback-function form fs.readFile with the arguments:
    1. error[Error]: Used for exceptions

ext.mkScriptTag = function(mainName)

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

Arguments
  1. mainName[String]: A name as identifier

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

Package Sidebar

Install

npm i nce-amd

Weekly Downloads

0

Version

0.0.1

License

ISC

Last publish

Collaborators

  • atd